(a) To make all 7 tricks you must play the Q from hand intending to finesse. Playing to the Jack is inferior because it fails to pick up K10x in the West hand. You’ll always lose to the K in the East hand but you must not lose to K10x in the West hand. Of course you’ll know that West started with K10x when East shows out on the first round of the suit. You can then finesse the 9 if necessary on the second round.
(b) You need a lot of luck to make all 4 tricks. You start by leading low to the Jack and hope that wins the trick. You now have an even money choice. You either play the Ace hoping that West started with exactly Kx, or you play the Q (which West will cover) hoping to pin the 10 in East’s hand.
The opposition suit layout has to be either Kx opposite 10xx, or Kxx opposite 10x for you to succeed if you guess correctly.
Play to pin the 10 if you want to impress the other players at the table!