From the Super Mario Wiki
Pair-a-Gone is a minigame featured in the games Super Mario 64 DS and New Super Mario Bros.. In the former it is one of Luigi's minigames, and in the latter, it is classified as a Table Minigame. In addition to stating the minigame's basic mechanics, the name "Pair-a-Gone" seems to be a pun on "paragon," which can mean "a sole example" or "to rival," both of which can be thought of as relating to this game and the skill required to succeed at it.
It consists of fifty cards with pictures on them, which the player must match either up, down, left, right, or diagonally. To win coins, the player must be able to match all of the cards. If the player is unable to match all of the cards, one coin is deducted for each card remaining. The separate minigame Pair-a-Gone and On is largely identical in gameplay to Pair-a-Gone, though it lasts forever.
This lists the different types of cards the player can get.
Touch 2 identical cards that are connected horizontally, vertically, or diagonally to make them disappear. Clear them all to win!