Unfolding the Solitaire#5864

Unfolding the Solitaire

2 seconds
64 megabytes
Easy

"N-T solitaire" is a card game for one player. There are cards (3 \leq N \leq 15) in the game, where each card has a unique combination of its value (an integer in the range ) and suit (black171, red168, black170, or red169).

At the start, all cards are dealt into piles (4 \leq T \leq 8). The first (4N) \bmod T piles each contain (4N \mathbin{/} T) + 1 cards; the remaining piles each contain 4N \mathbin{/} T cards (here, "/" and "bmod" denote integer division and remainder, respectively).

If the sum of the values of the top cards of any two piles equals N+1, both cards may be moved to the discard pile (regardless of their suits). This is the only allowed move.

Write a program to determine the maximum number of cards that can be moved to the discard pile, and give an example of how to do this.

Input

The first line contains two integers and . The next lines describe each pile. Each card is given by its value (an integer) and suit (a character with ASCII code 03 (black171), 04 (red168), 05 (black170), or 06 (red169)), with no space between value and suit. Cards in one pile are separated by a single space. The list for each pile is given from bottom to top (leftmost card is on the bottom, rightmost is on the top).

Sample Input:

Output

On the first line, print one integer — the maximum number of cards that can be discarded. Then print pairs of integers, one pair per line, representing the indices of the piles from which to remove the top cards at each move.

Examples

Example 1

Loading
Loading

Note

If there are multiple ways to achieve the maximum, output any one.