The black king stands on the edge and White's king on e6 covers d7, e7 and f7. Qe7# is the first finishing pattern: the queen checks from the square next to the king, and the king cannot take it because White's king protects it. Qa8# is the second: the queen checks along the edge and the king cannot step forward.
What to notice
Both mates need your king two squares in front of theirs. The tempting Qd6?? takes away d8 and f8 without giving check, which is stalemate, and Qf8+?? loses the queen to Kxf8.