We will now show a short example of modulation to a distantly related key in Bach's Prelude for the lute BWV 998. In only 6 measures - starting in measure 36 - Bach goes from Eb major to Ab minor before returning to Eb major:
The Ab minor is used as a pivot chord for modulating to Ab minor (measure 37). Ab minor chord is not found in Eb major, but the chord is the iv degree of Eb minor and it is a common practice to use chords from the parallel minor key. After the Ab minor chord, Bach uses the vii degree of Ab minor to establish the new key in measure 38.
Bach returns from Ab minor to Eb major by using the VI degree of Ab minor (Fb major) as a pivot chord. Again, this chord is not found in Eb major, but Fb major is the Neapolitan sixth of Eb major. Following Fb major by the dominant chord of Eb major would take us back to Eb major, but ...
Bach has another surprise for us. Instead of presenting the dominant chord after the Neapolitan sixth, he precedes the chord with a secondary dominant (V of V) in measure 40.