#D1712. Unknown Switches

    ID: 1428 Type: Default 8000ms 536MiB

Unknown Switches

Unknown Switches

Problem Statement

In the headquarter building of ICPC (International Company of Plugs & Connectors), there are MM light bulbs and they are controlled by NN switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light bulbs controlled by the switch change their states. You lost the table that recorded the correspondence between the switches and the light bulbs, and want to restore it.

You decided to restore the correspondence by the following procedure.

  • At first, every switch is off and every light bulb is off.
  • You operate some switches represented by S1S_1.
  • You check the states of the light bulbs represented by B1B_1.
  • You operate some switches represented by S2S_2.
  • You check the states of the light bulbs represented by B2B_2.
  • ...
  • You operate some switches represented by SQS_Q.
  • You check the states of the light bulbs represented by BQB_Q.

After you operate some switches and check the states of the light bulbs, the states of the switches and the light bulbs are kept for next operations.

Can you restore the correspondence between the switches and the light bulbs using the information about the switches you have operated and the states of the light bulbs you have checked?

Input

The input consists of multiple datasets. The number of dataset is no more than 5050 and the file size is no more than 10MB10\mathrm{MB}. Each dataset is formatted as follows.

NN MM QQ S1S_1 B1B_1 : : SQS_Q BQB_Q

The first line of each dataset contains three integers NN (1N361 \le N \le 36), MM (1M1,0001 \le M \le 1{,}000), QQ (0Q1,0000 \le Q \le 1{,}000), which denote the number of switches, the number of light bulbs and the number of operations respectively. The following QQ lines describe the information about the switches you have operated and the states of the light bulbs you have checked. The ii-th of them contains two strings SiS_i and BiB_i of lengths NN and MM respectively. Each SiS_i denotes the set of the switches you have operated: SijS_{ij} is either 00 or 11, which denotes the jj-th switch is not operated or operated respectively. Each BiB_i denotes the states of the light bulbs: BijB_{ij} is either 00 or 11, which denotes the jj-th light bulb is off or on respectively.

You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.

The end of input is indicated by a line containing three zeros.

Output

For each dataset, output the correspondence between the switches and the light bulbs consisting of MM numbers written in base-3636. In the base-3636 system for this problem, the values 00-99 and 1010-3535 are represented by the characters '0'-'9' and 'A'-'Z' respectively. The ii-th character of the correspondence means the number of the switch controlling the ii-th light bulb. If you cannot determine which switch controls the ii-th light bulb, output '?' as the ii-th character instead of the number of a switch.

Sample Input

3 10 3 000 0000000000 110 0000001111 101 1111111100 2 2 0 1 1 0 2 1 1 01 1 11 11 10 10000000000 10000000000 11000000000 01000000000 01100000000 00100000000 00110000000 00010000000 00011000000 00001000000 00001100000 00000100000 00000110000 00000010000 00000011000 00000001000 00000001100 00000000100 00000000110 00000000010 0 0 0

Output for the Sample Input

2222221100 ?? 0 1 0123456789A

Example

Input

3 10 3 000 0000000000 110 0000001111 101 1111111100 2 2 0 1 1 0 2 1 1 01 1 11 11 10 10000000000 10000000000 11000000000 01000000000 01100000000 00100000000 00110000000 00010000000 00011000000 00001000000 00001100000 00000100000 00000110000 00000010000 00000011000 00000001000 00000001100 00000000100 00000000110 00000000010 0 0 0

Output

2222221100 ?? 0 1 0123456789A

inputFormat

Input

The input consists of multiple datasets. The number of dataset is no more than 5050 and the file size is no more than 10MB10\mathrm{MB}. Each dataset is formatted as follows.

NN MM QQ S1S_1 B1B_1 : : SQS_Q BQB_Q

The first line of each dataset contains three integers NN (1N361 \le N \le 36), MM (1M1,0001 \le M \le 1{,}000), QQ (0Q1,0000 \le Q \le 1{,}000), which denote the number of switches, the number of light bulbs and the number of operations respectively. The following QQ lines describe the information about the switches you have operated and the states of the light bulbs you have checked. The ii-th of them contains two strings SiS_i and BiB_i of lengths NN and MM respectively. Each SiS_i denotes the set of the switches you have operated: SijS_{ij} is either 00 or 11, which denotes the jj-th switch is not operated or operated respectively. Each BiB_i denotes the states of the light bulbs: BijB_{ij} is either 00 or 11, which denotes the jj-th light bulb is off or on respectively.

You can assume that there exists a correspondence between the switches and the light bulbs which is consistent with the given information.

The end of input is indicated by a line containing three zeros.

outputFormat

Output

For each dataset, output the correspondence between the switches and the light bulbs consisting of MM numbers written in base-3636. In the base-3636 system for this problem, the values 00-99 and 1010-3535 are represented by the characters '0'-'9' and 'A'-'Z' respectively. The ii-th character of the correspondence means the number of the switch controlling the ii-th light bulb. If you cannot determine which switch controls the ii-th light bulb, output '?' as the ii-th character instead of the number of a switch.

Sample Input

3 10 3 000 0000000000 110 0000001111 101 1111111100 2 2 0 1 1 0 2 1 1 01 1 11 11 10 10000000000 10000000000 11000000000 01000000000 01100000000 00100000000 00110000000 00010000000 00011000000 00001000000 00001100000 00000100000 00000110000 00000010000 00000011000 00000001000 00000001100 00000000100 00000000110 00000000010 0 0 0

Output for the Sample Input

2222221100 ?? 0 1 0123456789A

Example

Input

3 10 3 000 0000000000 110 0000001111 101 1111111100 2 2 0 1 1 0 2 1 1 01 1 11 11 10 10000000000 10000000000 11000000000 01000000000 01100000000 00100000000 00110000000 00010000000 00011000000 00001000000 00001100000 00000100000 00000110000 00000010000 00000011000 00000001000 00000001100 00000000100 00000000110 00000000010 0 0 0

Output

2222221100 ?? 0 1 0123456789A

样例

3 10 3
000 0000000000
110 0000001111
101 1111111100
2 2 0
1 1 0
2 1 1
01 1
11 11 10
10000000000 10000000000
11000000000 01000000000
01100000000 00100000000
00110000000 00010000000
00011000000 00001000000
00001100000 00000100000
00000110000 00000010000
00000011000 00000001000
00000001100 00000000100
00000000110 00000000010
0 0 0
2222221100

?? 0 1 0123456789A

</p>