#Norek weź mu dostaw średniki na końcu linii. Brzydkie to tak, że się na to patrzeć nie da.
#Karol, tak nie wolno, to przecież pajton!
#Co nie wolno, co nie wolno?! Będzie działać ze średnikami szybciej, bo bardziej przypomina C++!

from collections import Counter;

indeterminate = "WIELE POPRAWNYCH ODPOWIEDZI";
incorrect = "BRAK POPRAWNYCH ODPOWIEDZI";

def matching(guess, verifier):
    score =0;
    for x in verifier.keys():
        if x in guess:
            score+= min(verifier[x],guess[x]);
    return score;

def get_next_item(L, item, index, available):
        if(index<0):
            return "";
        if(item[index]==available[len(available)-1]):
            item = item[:index]+available[0]+item[index+1:];
            return get_next_item(L,item, index-1,available);
        else:
            item = item[:index]+available[available.index(item[index])+1]+item[index+1:]; 
            return item;


def solve():
    length, guessnumber = list(map(int, input().split()))
    password = [];
    correct = [];
    misplaced = [];
    mappedpasswords = [];
    available = ['a','b','c','d','e','f','g','h','i','j','k','l',
                 'm','n','o','p','q','r','s','t','u','v','w','x','y','z']
    G = guessnumber;
    for _ in range(G):
        x,y,z = input().split(' ')
        y = int(y)
        z = int(z)
        if(y+z>0):
            password.append(x);
            correct.append(y);
            misplaced.append(z);
            mappedpasswords.append(Counter(x));
        else:
            guessnumber-=1;
            for j in range(len(x)):
                if x[j] in available:
                    available.remove(x[j]);
    found = 0;
    ans = "";
    SS="";
    if(len(available)>0):
        for i in range(length):
            SS+=available[0];
    while(SS!=""):
        s2map = Counter(SS);
        gud = True;
        for i in range(guessnumber):
            corr = 0;
            miss = 0;
            for q in range(length):
                if(password[i][q]==SS[q]):
                    corr+=1;
            miss = matching(mappedpasswords[i],s2map)-corr;
            if (corr!=correct[i] or miss!=misplaced[i]):
                gud = False;
                break;
            
        if(gud):
            if(ans==""):
                ans = SS;
            else:
#                print(ans,'\t',SS);
                print(indeterminate);
                return;
        SS = get_next_item(length,SS,length-1,available);
    #    print(SS);

    if(ans==""):
        print(incorrect);
        return;

    print(ans)


T = int(input())
for _ in range(T):
    solve()
