Conventions used after intervention following a Blackwood 4NT. Following an intervening bid, Double shows zero (O) aces, Pass one (I) and other responses on a step principle, the first bid (e.g. 5♥ after a 5♦ overcall) showing two aces etc. After an intervening double, Redouble shows zero (O) aces, Pass one (I) ace etc.
If you are playing Keycard Blackwood or Roman Keycard Blackwood, it is usual to play that you double (or redouble) to show the first step response or pass to make the second step response. The cheapest actual bid shows the third step response and so on.
On the first hand, playing Keycard Blackwood, you want to show three key cards. That is a fourth step response. Thus, as double and pass deal with the first and second steps, you bid 5♠. On the second hand, you have two key cards and so bid 5♥.
With Roman Keycard Blackwood you have (zero or) three key cards on the first hand (first step response) and so double. With the second hand, you have two key cards and the trump queen, which is a fourth step response, and so bid 5♠.