Under construction

Still being built. Things may change

Guess Who

Time limit1sMemory limit1024 MB

Summary
Count the characters whose attributes match every given answer, then print the index if exactly one matches or the number of matches otherwise.
Level

Easy2 of 10

Topics
Implementation
Solved
No attempts yet

Statement

Guess Who is a two-player board game. Each character is uniquely identified by a set of attributes, such as wearing glasses. Each player tries to guess the other player's hidden character by asking yes/no questions, such as whether the character wears glasses.

In this variation, there are NN characters, and each one is uniquely identified by a set of MM attributes. Each attribute value is either YES or NO. You are given the list of characters and their attributes, along with QQ questions and their answers. Determine the hidden character if possible.

Input

The first line contains three space-separated integers NN, MM, and QQ, where 1≤N≤1 0001 \leq N \leq 1\,000, 1≤M≤151 \leq M \leq 15, and 1≤Q≤M1 \leq Q \leq M. The next NN lines each contain a string of MM characters, each either Y or N. The iith line gives the MM attribute values of the iith character.

Each of the next QQ lines contains an integer AA (1≤A≤M1 \leq A \leq M), a space, and a character Y or N. This means the question is about attribute AA, and the hidden character's value for that attribute is YES or NO. There is at most one question per attribute. At least one listed character matches the answers to all queries.

Output

On the first line, print unique if exactly one character matches the answers, or ambiguous if more than one does.

If the hidden character is unique, print its index (between 1 and NN) on the second line. If there are multiple possible characters, print how many of them match on the second line.

Examples2

  1. Example 1

    Input
    5 5 3
    YYYYY
    NNNNN
    YNYNY
    YYYNN
    NNYYY
    1 N
    2 N
    3 Y
    
    Expected output
    unique
    5
    
  2. Example 2

    Input
    5 5 3
    YYYYY
    NNNNN
    YNYNY
    YYNNN
    NNNYY
    1 Y
    5 Y
    3 Y
    
    Expected output
    ambiguous
    2