// Justin Almazan
// 6/25/2025
// Solution to 2025 CS SI UCF Contest 3 Problem: Guess Who
// https://open.kattis.com/problems/guesswho

#include <bits/stdc++.h>
using namespace std;

int n, m, qq;

vector<string> v;

int main() {

    // Get input
    cin >> n >> m >> qq;

    // Create vector for each character's attributes
    v = vector<string>(n);
    
    // Get each character's attributes
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    // Keeps track of the attributes we know the character must have
    string key = "";
    for (int i = 0; i < m; i++) key += "X";

    // Process each question
    while (qq--) {

        // Read in the information for each guess
        int x;
        char c;
        cin >> x >> c;

        // Edit the key to match the guess
        key[x-1] = c;
    }

    // Check for a match and keep track of the position/frequency
    int freq = 0, index = -1;

    for (int i = 0; i < n; i++) {
        
        // True if this character is a match
        bool b = true;

        // Compare each attribute of this character with the key
        for (int j = 0; j < m; j++) {
            
            // If they don't match
            if (key[j] != 'X' && key[j] != v[i][j]) {

                // This character cannot be the hidden character
                b = false;
            }
        }

        // Change accordingly
        if (b) {
            freq++;
            index = i;
        }
    }

    // Unique case
    if (freq == 1) {
        cout << "unique" << endl;
        cout << index + 1 << endl;
    }

    // Ambiguous case
    else {
        cout << "ambiguous" << endl;
        cout << freq << endl;
    }

    return 0;
}