Licky Jaiden


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

After arriving at work, Jaiden realises he hasn't packed his lunch. Fortunately, he has decided that he really, really likes the look of his coworker's lunch, and that he'd like to steal it - or to "hit a lick".

Unfortunately for him the lunch is secured in their locker with a combination lock which he really would rather not bruteforce. A combination lock is a lock with many rotating dials, with some characters on each wheel.

Image 1

Luckily for him, since the lunch is so delicious his coworker often checks the locker multiple times to verify that it is still infact there. Although he can't observe their locker code directly when they do this, he can gain valuable information that will help you crack the code.

Every time his coworker goes to open the locker, he stands nearby inconspicuously, noting down the locker code's starting code. To open the locker, his coworker must spin some of the dials on the combination lock. Each time they turn any dial by one position, Jaiden hears a distinct "click" - he note down the amount of clicks as the amount of dial turns it took to get from the starting code to the correct code. Jaiden's coworker's dial turns are always efficient. That is, when turning the dials to get from one code to another, they will always take the least number of dial turns required to get to the final code.

After observing this multiple times, can you deduce what their code is?

Input

The first line consists of 3 integers in the format n m k, the number of rotating dials on the lock, the number of characters on each dial, and how many times your coworkers checks the locker. (1 \leq n \leq 10), (2 \leq m \leq 6), (1 \leq k \leq 100).

The next n lines consist of m lowercase alphabetical characters - the characters on the nth dial. On a given dial, each character will be unique. The m characters wrap around the dial, so it is possible to move from the last character to the first or vice versa in 1 click.

The next k lines consist of string a of length n and an integer x (0 \leq x \leq 5), representing the the locker's starting code and the number of clicks Jaiden heard for that code.

Output

Output a single string value: the only possible correct locker code combination, or IMPOSSIBLE if there is not enough information to tell.

Examples

Input 1
4 4 3
comp
fold
plot
helm
mdol 4
olol 2
pool 1
Output 1
cool

The only possible locker combination is cool.

Input 2
3 5 1
sugar
alien
bread
sad 1
Output 2
IMPOSSIBLE

Based on the given information, the correct dial could be sab, saa, sld, snd, uad, or rad. There is not enough information to narrow it down to one possible combination.


Comments

There are no comments at the moment.