user25593: So... initial position is
[FEN "7k/8/6KB/8/p7/8/Q7/8 w - - 0 1"]

Now... Neither white's king nor queen has moved in the previous five moves. In addition, no pieces have been captured by either side.
What was the last move? Also, where the piece came from here?
Since the black's king can't move it's very tempting to say that black's last move was a pawn move or white's last move was a bishop move. The tricky part is the mention of 5 moves. Black's pawn can only do 3 moves from starting position, and since white's queen and the king didn't move, black's king is stuck.

user21604: As the Black pawn can only have made three moves, the Black king must have made two moves. As the entrance to h8 is blocked, the White queen's line of attack must have been blocked at some point. The White king has not moved, and the Black pawn cannot block that line, so it must have been the White bishop. But the White bishop is a dark-square bishop, and cannot block the White queen along a light-colored diagonal, so it must come from a pawn promotion. The question "Where does the piece come from?" in the OP is a hint.
Here is a solution where the last move was a Black move. I think the problem cannot be solved if the last move was a White move:
[FEN "5k2/p7/6K1/3P4/8/8/Q7/8 b - - 0 1"]
[StartFlipped "0"]

1... Kg8 2. d6+ Kh8 3. d7 a6 4. d8=B a5 5. Bg5 a4 6. Bh6


25593: <p>So... initial position is</p>
<pre><code>[FEN &quot;7k/8/6KB/8/p7/8/Q7/8 w - - 0 1&quot;]
</code></pre>
<p>Now... Neither white's king nor queen has moved in the previous five moves. In addition, no pieces have been captured by either side.
What was the last move? Also, where the piece came from here?</p>
<p>Since the black's king can't move it's very tempting to say that black's last move was a pawn move or white's last move was a bishop move. The tricky part is the mention of 5 moves. Black's pawn can only do 3 moves from starting position, and since white's queen and the king didn't move, black's king is stuck.</p>
 21604: <p>As the Black pawn can only have made three moves, the Black king must have made two moves. As the entrance to h8 is blocked, the White queen's line of attack must have been blocked at some point. The White king has not moved, and the Black pawn cannot block that line, so it must have been the White bishop. But <strong>the White bishop</strong> is a dark-square bishop, and cannot block the White queen along a light-colored diagonal, so it <strong>must come from a pawn promotion</strong>. The question &quot;Where does the piece come from?&quot; in the OP is a hint.</p>
<p>Here is a solution where the last move was a Black move. I think the problem cannot be solved if the last move was a White move:</p>
<pre><code>[FEN &quot;5k2/p7/6K1/3P4/8/8/Q7/8 b - - 0 1&quot;]
[StartFlipped &quot;0&quot;]

1... Kg8 2. d6+ Kh8 3. d7 a6 4. d8=B a5 5. Bg5 a4 6. Bh6
</code></pre>
