Unknown Switches

Given switch-operation patterns and resulting bulb states over Q steps, determine which of N switches controls each bulb, or mark it unknown. Standard whiteboard task? No.

Hard8Bit manipulationMathBrute forceImplementationNo attempts yetTime limit8sMemory limit512 MB

Problem

A building has MM light bulbs, and NN switches control them. Every bulb is wired to exactly one switch, and one switch may control several bulbs. Operating a switch flips the state of every bulb that switch controls.

The table that recorded which switch controls which bulb is lost. You want to rebuild it with the following procedure.

  • At the start every switch is off and every bulb is off.
  • You operate the switches given by S1S_1.
  • You check the bulbs and read the states B1B_1.
  • You operate the switches given by S2S_2.
  • You check the bulbs and read the states B2B_2.
  • You repeat this up to SQS_Q and BQB_Q.

Operating switches and reading bulbs leaves both the switches and the bulbs in their new states, and the next operation continues from there.

Rebuild the correspondence between the switches and the bulbs from the switches you operated and the bulb states you read.

Input

The input holds several datasets. There are at most 50 datasets and the whole input is at most 10MB. Each dataset has this format.

N M Q
S1 B1
:
:
SQ BQ

The first line holds three integers NN, MM and QQ: the number of switches, the number of bulbs and the number of operations. (1N361 \le N \le 36, 1M10001 \le M \le 1\,000, 0Q10000 \le Q \le 1\,000)

Each of the next QQ lines holds two strings SiS_i and BiB_i of lengths NN and MM, separated by a space. The jj-th character of SiS_i is 0 or 1: 0 means the jj-th switch was not operated, 1 means it was. The jj-th character of BiB_i is 0 or 1: 0 means the jj-th bulb is off, 1 means it is on.

At least one correspondence between the switches and the bulbs is consistent with the given information.

A line holding three zeros marks the end of the input.

Output

For each dataset, print the correspondence on one line as MM base-36 digits. In the base-36 system of this problem, the values 0 to 9 are written as the characters '0' to '9' and the values 10 to 35 as the characters 'A' to 'Z'. Switches are numbered starting from 0.

The ii-th character is the number of the switch that controls the ii-th bulb. If the switch controlling the ii-th bulb cannot be pinned down to one switch, print '?' instead of a number.