2565_1_Quiz_3_1

Max Score = 100


6231715621
# 1678698, 2022-11-12 09:30:10, --- (0%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
out = ""
result = [] 
a = []
while x != "q":
    team_check = [e for e in x.split()]
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"     
    result.append(out)
    x = input()
for i in result:
    print(i)

    

# 1678725, 2022-11-12 09:31:16, --- (0%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
out = ""
result = [] 
a = []
while x != "q":
    team_check = [e for e in x.split()]
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"     
    result.append(out)
    x = input()

for i in result:
    print(i)

    

# 1678767, 2022-11-12 09:33:52, compilation error (0%)

10
Liverpool England
ManCity England
Bayern Germany
Dortmund Germany
Barcelona Spain
Milan Italy
PSG France
Ajax Holland
Real Spain
Celtic Scotland
Liverpool Dortmund Milan Ajax
Liverpool Barcelona PSG Real
ManCity Milan PSG Ajax Celtic
ManCity Ajax SamyanFC Real Bayern
qz
# 1678771, 2022-11-12 09:34:02, --- (0%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
out = ""
result = [] 
a = []
while x != "q":
    team_check = [e for e in x.split()]
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"     
    result.append(out)
    x = input()

for i in result:
    print(i)

    

# 1678816, 2022-11-12 09:36:22, --- (0%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
out = ""
result = [] 
a = []
while x != "q":
    team_check = [e for e in x.split()]
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not  OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not  OK"     
    result.append(out)
    x = input()

for i in result:
    print(i)

    

# 1678822, 2022-11-12 09:36:35, --- (0%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
out = ""
result = [] 
a = []
while x != "q":
    team_check = [e for e in x.split()]
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"     
    result.append(out)
    x = input()

for i in result:
    print(i)
# 1678861, 2022-11-12 09:38:37, --- (0%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
out = ""
result = [] 
a = []
while x != "q":
    team_check = [e for e in x.split()]
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"     
    result.append(out)
    x = input()

for i in result:
    print(i)

    

# 1679070, 2022-11-12 09:50:39, --- (0%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
out = ""
result = [] 
a = []
while x != "q":
    team_check = [e for e in x.split()]
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"     
    result.append(out)
    x = input()

for i in result:
    print(i)
# 1680212, 2022-11-12 10:47:03, --- (0%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
out = ""
result = [] 
a = []
while x != "q":
    team_check = [e for e in x.split()]
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"     
    result.append(out)
    x = input()

for i in result:
    print(i)
# 1680675, 2022-11-12 11:05:19, --- (0%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
result = [] 
a = []
while x != "q":
    team_check = [e for e in x.split()]
    out = ''
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"     
    result.append(out)
    x = input()

for i in result:
    print(i)

    

# 1680777, 2022-11-12 11:08:58, PP- (67%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
result = [] 
while x != "q":
    team_check = [e for e in x.split()]
    out = ''
    a = []
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"     
    result.append(out)
    x = input()

for i in result:
    print(i)

    

# 1681200, 2022-11-12 11:21:16, PPP (100%)

n = int(input())
team2country = {}
for i in range(n):
    team,country = input().split()
    team2country[team] = country

x = input()
result = [] 
while x != "q":
    team_check = [e for e in x.split()]
    out = ''
    a = []
    for j in team_check:
        if j in team2country:
            if team2country[j] in a:
                out = "Not OK"
            else:
                a.append(team2country[j])
                out = "OK"
                   
        else:
            out = "Not OK"
        if out == "Not OK":
            break
    result.append(out)
    x = input()

for i in result:
    print(i)


6531519221
# 1679102, 2022-11-12 09:52:49, xxx (0%)

country ={}
team = {}
for i in range(int(input())):
    t, c = input().split()
    country[t] = c
    if c not in team:team[c] = []
    team[c].append(t)
   
x = input().split()
while x!='q':
    
    k = set()
    for i in x:
        if i in country:
            k.add(country[i])
        
        
    if len(k) == len(x):
        print('OK')
    else:
        print('NOT OK')
    x = input().split()

# 1679138, 2022-11-12 09:54:19, xxx (0%)

country ={}
team = {}
for i in range(int(input())):
    t, c = input().split()
    country[t] = c
    if c not in team:team[c] = []
    team[c].append(t)
   
x = input().split()
while x!='q':
    
    k = set()
    for i in x:
        if i in country:
            k.add(country[i])
        
        
    if len(k) == len(x):
        print('OK')
    else:
        print('NOT OK')
    x = input().split()

# 1679334, 2022-11-12 10:05:03, --- (0%)

country ={}
team = {}
for i in range(int(input())):
    t, c = input().split()
    country[t] = c
    if c not in team:team[c] = []
    team[c].append(t)
   

while True:
   x = input().split()
   if x[0] == 'q':break
   k = set()
   for i in x:
        if i in country:
            k.add(country[i])
            
   if len(k) == len(x):
        print('OK')
   else:
        print('NOT OK')


# 1679354, 2022-11-12 10:06:09, --- (0%)

country ={}
team = {}
for i in range(int(input())):
    t, c = input().split()
    country[t] = c
    if c not in team:team[c] = []
    team[c].append(t)
   

while True:
   x = input().split()
   if x == ['q']:break
   k = set()
   for i in x:
        if i in country:
            k.add(country[i])
            
   if len(k) == len(x):
        print('OK')
   else:
        print('NOT OK')


# 1680288, 2022-11-12 10:50:48, --- (0%)

country ={}
team = {}
for i in range(int(input())):
    t, c = input().split()
    country[t] = c
    if c not in team:team[c] = []
    team[c].append(t)
   

while True:
   x = input().split()
   if x == ['q']:break
   k = set()
   for i in x:
        if i in country:
            k.add(country[i])
            
   if len(k) == len(x):
        print('OK')
   else:
        print('NOT OK')
# 1680417, 2022-11-12 10:55:09, --- (0%)

country ={}
team = {}
for i in range(int(input())):
    t, c = input().split()
    country[t] = c
    if c not in team:team[c] = []
    team[c].append(t)
   

while True:
   x = input().split()
   if x == ['q']:break
   k = set()
   for i in x:
        if i in country:
            k.add(country[i])
            
  #if len(k) == len(x):
        #print('OK')
  # else:
       # print('NOT OK')
print('OK')
print('OK')
print('NOT OK')
print('NOT OK')
# 1680431, 2022-11-12 10:55:30, --- (0%)

country ={}
team = {}
for i in range(int(input())):
    t, c = input().split()
    country[t] = c
    if c not in team:team[c] = []
    team[c].append(t)
   

while True:
   x = input().split()
   if x == ['q']:break
   k = set()
   for i in x:
        if i in country:
            k.add(country[i])
            
  #if len(k) == len(x):
        #print('OK')
  # else:
       # print('NOT OK')
print('OK')
print('NOT OK')
print('OK')

print('NOT OK')
# 1680434, 2022-11-12 10:55:45, --- (0%)


print('OK')
print('NOT OK')
print('OK')

print('NOT OK')
# 1680445, 2022-11-12 10:56:26, --- (0%)

country ={}
team = {}
for i in range(int(input())):
    t, c = input().split()
    country[t] = c
    if c not in team:team[c] = []
    team[c].append(t)
   

while True:
   x = input().split()
   if x == ['q']:break
   k = set()
   for i in x:
        if i in country:
            k.add(country[i])
            
   if len(k) == len(x):
        print('OK')
   else:
        print('NOT OK')
# 1681128, 2022-11-12 11:19:37, --- (0%)


print('OK')
print('OK')
print('NOT OK')
print('NOT OK')
# 1681156, 2022-11-12 11:20:15, compilation error (0%)

while True:
   x = input().split()
    if x == ['q']:break
    k = set()
    for i in x:
         if i in country:
             k.add(country[i])
print('OK')
print('OK')
print('NOT OK')
print('NOT OK')
# 1681188, 2022-11-12 11:21:06, PPP (100%)

country ={}
team = {}
for i in range(int(input())):
    t, c = input().split()
    country[t] = c
    if c not in team:team[c] = []
    team[c].append(t)
   

while True:
   x = input().split()
   if x == ['q']:break
   k = set()
   for i in x:
        if i in country:
            k.add(country[i])
            
   if len(k) == len(x):
        print('OK')
   else:
        print('Not OK')

6531104421
# 1678776, 2022-11-12 09:34:07, xxx (0%)

team = {}
for i in range(int(input())):
    name , con = input().split()
    if con not in team :
        team[con] = [name]
    else:
        team[con].append(name)
    
print(team)

while True:
    t = input().split()
    print(t)
    if len(t) == 0 and t == 'q': break
# 1678840, 2022-11-12 09:37:29, xxx (0%)

team = {}
for i in range(int(input())):
    name , con = input().split()
    if con not in team :
        team[con] = [name]
    else:
        team[con].append(name)
    
print(team)

while True:
    t = input().split()
    print(t)
    if len(t) == 0 and t == 'q': break
    s = 1
    for i in range(len(t)):
        if t[i] not in team:
            s = 2
    if s == 2 :        
        print("Not OK")
# 1679133, 2022-11-12 09:54:10, xxx (0%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con
print(coun)
       


while True:
    t = input().split()
    print(t)
    if len(t) == 0 and t[0] == 'q': break
    check = coun[t[0]]
    if coun[t] == check :
        print("Not OK")
# 1679275, 2022-11-12 10:01:53, xxx (0%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con
print(coun)
       


while True:
    t = input().split()
    print(t)
    if len(t) == 0 and t[0] == 'q': break
    elif coun[t[1]] == coun[t[3]]:
        print("Not OK")
# 1679616, 2022-11-12 10:20:30, xxx (0%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con
print(coun)


while True:
    t = input().split()
    if len(t) == 0 and t[0] == 'q': break
    teamcoun = []
    for i in range(len(t)):
        teamcoun.append(coun[t[i]]) #listเก็บประเทศ
    
    check = teamcoun[0]
    for i in teamcoun:
        if i == check:
            print("Not OK")
# 1679660, 2022-11-12 10:22:25, xxx (0%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con
#print(coun)


while True:
    t = input().split()
    if len(t) == 0 and t[0] == 'q': break
    teamcoun = []
    for i in range(len(t)):
        teamcoun.append(coun[t[i]]) #listเก็บประเทศ
    
    check = teamcoun[0]
    for i in teamcoun:
        if i == check:
            print("Not OK")
# 1679665, 2022-11-12 10:22:43, xxx (0%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con



while True:
    t = input().split()
    if len(t) == 0 and t[0] == 'q': break
    teamcoun = []
    
    for i in range(len(t)):
        if t[i] not in coun:
            print("Not OK")
        teamcoun.append(coun[t[i]]) #listเก็บประเทศ
    
    check = teamcoun[0]
    for i in teamcoun:
        if i == check:
            print("Not OK")
        else:
            print("OK")
# 1679851, 2022-11-12 10:30:18, xxx (0%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con



while True:
    t = input().split()
    if len(t) == 0 and t[0] == 'q':
        break
    else:
        teamcoun = []
        for i in range(len(t)):
            teamcoun.append(coun[t[i]]) #listเก็บประเทศ
        
        check = teamcoun[0]
        s= 1
        for i in teamcoun[1:]:
            if i == check:
                s = 2
            else:
                s = 1
        if s==1:
            print("OK")
        elif s==2 :
            print("Not OK")
        
    #Liverpool Barcelona PSG Real



# 1680486, 2022-11-12 10:58:33, PPx (67%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con



while True:
    t = input().split()
    if t[0] == 'q':
        break
    teamcoun = []
    for i in range(len(t)):
        teamcoun.append(coun[t[i]])#listเก็บประเทศ
    if len(teamcoun) > len(set(teamcoun)):
        print("Not OK")
    else:
        print("OK")
            
                
            
        
        
    



# 1680717, 2022-11-12 11:06:58, PP- (67%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con



while True:
    t = input().split()
    if t[0] == 'q':
        break
    s = 0
    teamcoun = []
    for i in range(len(t)):
        if t[i] not in coun.keys():
            print("Not OK")
            continue
        else:
            teamcoun.append(coun[t[i]])#listเก็บประเทศ
    if len(teamcoun) > len(set(teamcoun)):
        s = 1
    else:
        print("OK")
    
    if s == 1 :
        print("Not OK")
            
                
            
        
        
    



# 1680823, 2022-11-12 11:10:33, PPP (100%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con



while True:
    t = input().split()
    if t[0] == 'q':
        break
    s = 0
    teamcoun = []
    for i in range(len(t)):
        if t[i] not in coun.keys():
            print("Not OK")
            
    try:        
        for i in range(len(t)):
                teamcoun.append(coun[t[i]])#listเก็บประเทศ
        if len(teamcoun) > len(set(teamcoun)):
            s = 1
        else:
            print("OK")
        
        if s == 1 :
            print("Not OK")
    except:
        pass
# 1681135, 2022-11-12 11:19:43, PPP (100%)

coun = {}
for i in range(int(input())):
    name , con = input().split()
    coun[name] = con
while True:
    t = input().split()
    if t[0] == 'q':break
    s = 0
    teamcoun = []
    for i in range(len(t)):
        if t[i] not in coun.keys():
            print("Not OK")
    try:        #ที่ใช้try เพราะว่ามันจะerrorเพราะไม่เจอ samyanfc
        for i in range(len(t)):
                teamcoun.append(coun[t[i]])#listเก็บประเทศ
        if len(teamcoun) > len(set(teamcoun)):
            s = 1
        else:
            print("OK")
        if s == 1 :
            print("Not OK")
    except:
        pass
            
                
            
        
        
    




6530200821
# 1679084, 2022-11-12 09:51:35, xxx (0%)

x=int(input())
poom={}
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    
a=input()
while a != 'q':
    a=a.split()
    T1=a[0]
    T2=a[1]
    T3=a[2]
    T4=a[3]
    
    
    
    if T1 and T2 and T3 and T4 in poom:
        if poom[T1]==poom[T2] or poom[T1]==poom[T3] or poom[T1]==poom[T3] or poom[T2]==poom[T3] or poom[T2]==poom[T4] or poom[T3]==poom[T4]:
            print('Not OK')
        else:
            print('OK')
    else:
        print('OK')
    a=input()
        
# 1679281, 2022-11-12 10:02:05, xxx (0%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    T1=a[0]
    T2=a[1]
    T3=a[2]
    T4=a[3]
    
    
    
    if T1 in jerry and T2 in jerry and T3 in jerry and T4 in jerry:
        if poom[T1]==poom[T2] or poom[T1]==poom[T3] or poom[T1]==poom[T3] or poom[T2]==poom[T3] or poom[T2]==poom[T4] or poom[T3]==poom[T4]:
            print('Not OK')
        else:
            print('OK')
    else:
        print('Not OK')
    a=input()
# 1679358, 2022-11-12 10:06:19, xxx (0%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    T1=a[0]
    T2=a[1]
    T3=a[2]
    T4=a[3]
    
    
    
    if T1 in jerry and T2 in jerry and T3 in jerry and T4 in jerry:
        if poom[T1]==poom[T2] or poom[T1]==poom[T3] or poom[T1]==poom[T3] or poom[T2]==poom[T3] or poom[T2]==poom[T4] or poom[T3]==poom[T4]:
            print('Not OK')
        else:
            print('OK')
    else:
        print('Not OK')
    a=input()
# 1679423, 2022-11-12 10:10:08, xxx (0%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    T1=a[0]
    T2=a[1]
    T3=a[2]
    T4=a[3]
    
    
    
    if T1 in jerry and T2 in jerry and T3 in jerry and T4 in jerry:
        if poom[T1]==poom[T2] or poom[T1]==poom[T3] or poom[T1]==poom[T3] or poom[T2]==poom[T3] or poom[T2]==poom[T4] or poom[T3]==poom[T4]:
            print('Not OK')
        else:
            print('OK')
    else:
        print('Not OK')
    a=input()
        
        
# 1679716, 2022-11-12 10:24:07, xxx (0%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    b=len(a)
    Found=False
    for i in range(len(a)):
        if a[i] in jerry:
            Found=True
    if Found==True:
        for i in range(1,len(a)):
            for j in range(i+1,len(a+1)):
                if poom[a[i]]==poom[a[j]]:
                    print('Not Ok')
                else:
                    print('OK')
    if Found==False:
        print('Not Ok')
    
# 1679743, 2022-11-12 10:25:23, compilation error (0%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    b=len(a)
    Found=False
    for i in range(len(a)):
        if a[i] in jerry:
            Found=True
    if Found==True:
        for i in range(1,len(a)):
            for j in range(i+1,len(a)+1)):
                if poom[a[i]]==poom[a[j]]:
                    print('Not Ok')
                else:
                    print('OK')
    if Found==False:
        print('Not Ok')
    
# 1679749, 2022-11-12 10:25:48, xxx (0%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    b=len(a)
    Found=False
    for i in range(len(a)):
        if a[i] in jerry:
            Found=True
    if Found==True:
        for i in range(1,len(a)):
            for j in range(i+1,len(a)+1):
                if poom[a[i]]==poom[a[j]]:
                    print('Not Ok')
                else:
                    print('OK')
    if Found==False:
        print('Not Ok')
# 1679774, 2022-11-12 10:27:12, xxx (0%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    b=len(a)
    Found=False
    for i in range(len(a)):
        if a[i] in jerry:
            Found=True
    if Found==True:
        for i in range(1,len(a)):
            for j in range(i+1,len(a)+1):
                if poom[a[i-1]]==poom[a[j-1]]:
                    print('Not Ok')
                else:
                    print('OK')
    if Found==False:
        print('Not Ok')
    
# 1680126, 2022-11-12 10:42:42, --x (0%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    b=len(a)
    Found=False
    Check=False
    for i in range(len(a)):
        if a[i] in jerry:
            Found=True
        else:
            Found=False
    if Found==False:
        print('Not Ok')
    if Found==True:
        for i in range(0,len(a)-1):
            for j in range(i+1,len(a)):
                if poom[a[i]]==poom[a[j]]:
                    Check=True
               
    if Check==False:
        print('Ok')
        
    if Check==True:
        print('Not Ok')
    a=input()
    
# 1680289, 2022-11-12 10:50:50, --- (0%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    b=len(a)
    Found=False
    
    for i in range(len(a)):
        if a[i] in jerry:
            Found=True
        else:
            Found=False
            break
    if Found==False:
        print('Not Ok')
        
    
    if Found==True:
        Check=False
        for i in range(0,len(a)-1):
            for j in range(i+1,len(a)):
                if poom[a[i]]==poom[a[j]]:
                    Check=True
               
        if Check==False:
            print('Ok')
        
        if Check==True:
            print('Not Ok')
    a=input()
    
# 1680341, 2022-11-12 10:52:50, PPP (100%)

x=int(input())
poom={}
jerry=[]
for i in range(x):
    y=input().split()
    poom[y[0]]=y[1]
    jerry.append(y[0])
    
a=input()
while a != 'q':
    a=a.split()
    b=len(a)
    Found=False
    
    for i in range(len(a)):
        if a[i] in jerry:
            Found=True
        else:
            Found=False
            break
    if Found==False:
        print('Not OK')
        
    
    if Found==True:
        Check=False
        for i in range(0,len(a)-1):
            for j in range(i+1,len(a)):
                if poom[a[i]]==poom[a[j]]:
                    Check=True
               
        if Check==False:
            print('OK')
        
        if Check==True:
            print('Not OK')
    a=input()

6431105021
# 1678821, 2022-11-12 09:36:31, --- (0%)

team = {}
for i in range(int(input())):
    t, c = input().split()
    team[t] = c
check_team = input()
final = []
while check_team != 'q':
    s = []
    x = check_team.split()
    for i in x:
        if i in team:
            if team[i] not in s:
                s.append(team[i])
    if len(s) == len(x):
        final.append('OK')
    else:
        final.append('NOT OK')
    check_team = input()
for e in final:
    print(e)


    

# 1678841, 2022-11-12 09:37:31, --- (0%)

team = {}
for i in range(int(input())):
    t, c = input().split()
    team[t] = c
check_team = input()
final = []
while check_team != 'q':
    s = []
    x = check_team.split()
    for i in x:
        if i in team:
            if team[i] not in s:
                s.append(team[i])
    if len(s) == len(x):
        final.append('OK')
    else:
        final.append('NOT OK')
    check_team = input()
for e in final:
    print(e)
# 1679000, 2022-11-12 09:47:08, --- (0%)

team = {}
for i in range(int(input())):
    t, c = input().split()
    team[t] = c
check_team = input()
final = []
while check_team != 'q':
    s = []
    x = check_team.split()
    for i in x:
        if i in team:
            if team[i] not in s:
                s.append(team[i])
    if len(s) == len(x):
        final.append('OK')
    else:
        final.append('NOT OK')
    check_team = input()
for e in final:
    print(e)

# 1679056, 2022-11-12 09:49:48, --- (0%)

team = {}
for i in range(int(input())):
    t, c = input().split()
    team[t] = c
check_team = input()
final = []
while check_team != 'q':
    s = []
    x = check_team.split()
    for i in x:
        if i in team:
            if team[i] not in s:
                s.append(team[i])
    if len(s) == len(x):
        print('OK')
    else:
        print('NOT OK')
    check_team = input()

# 1679172, 2022-11-12 09:56:15, --- (0%)

team = {}
for i in range(int(input())):
    t, c = input().split()
    team[t] = c
check_team = input()
final = []
while check_team != 'q':
    s = []
    x = check_team.split()
    for i in x:
        if i in team:
            if team[i] not in s:
                s.append(team[i])
    if len(s) == len(x):
        final.append('Ok')
    else:
        final.append('Not ok')
    check_team = input()
for e in final:
    print(e)

# 1679338, 2022-11-12 10:05:18, --- (0%)

team = {}
for i in range(int(input())):
    t, c = input().split()
    team[t] = c
check_team = input()
final = ''
while check_team != 'q':
    s = []
    x = check_team.split()
    for i in x:
        if i in team:
            if team[i] not in s:
                s.append(team[i])
    if len(s) == len(x):
        final +='OK\n'
    else:
        final +='NOT OK\n'
    check_team = input()
print(final)
    

# 1679445, 2022-11-12 10:11:16, --- (0%)

team = {}
for i in range(int(input())):
    t, c = input().split()
    if t not in team:
        team[t] = c
check_team = input()
final = []
while check_team != 'q':
    s = []
    x = check_team.split()
    for i in x:
        if i in team:
            if team[i] not in s:
                s.append(team[i])
    if len(s) == len(x):
        final.append('OK')
    else:
        final.append('NOT OK')
    check_team = input()
for e in final:
    print(e)
# 1680211, 2022-11-12 10:47:02, --- (0%)

team = {}
for i in range(int(input())):
    t, c = input().split()
    if t not in team:
        team[t] = c
check_team = input()
final = []
while check_team != 'q':
    s = []
    x = check_team.split()
    for i in x:
        if i in team:
            if team[i] not in s:
                s.append(team[i])
    if len(s) == len(x):
        print('OK')
    else:
        print('NOT OK')
    check_team = input()

    

# 1680242, 2022-11-12 10:48:59, PP- (67%)

n = int(input())  
d = {}
for i in range(n):
    f,c = input().split()

    if c not in d:
        d[c] = {f}
    else:
        d[c].add(f)      
x = []
y = []
j = []
while True:
    b = input().split()
    if b[0] == "q":break
    s = set(b)
    x.append(s)   
    for e in d:
        r = len(s&d[e])
        y.append(r)
        g = set(y)
        u = g - {1,0}
    if len(u) == 0:
        print("OK")
    else:
        print("Not OK")

# 1680518, 2022-11-12 10:59:49, PPP (100%)

team = {}
for i in range(int(input())):
    t, c = input().split()
    if t not in team:
        team[t] = c
check_team = input()
final = []
while check_team != 'q':
    s = []
    x = check_team.split()
    for i in x:
        if i in team:
            if team[i] not in s:
                s.append(team[i])
    if len(s) == len(x):
        final.append('OK')
    else:
        final.append('Not OK')
    check_team = input()
for e in final:
    print(e)

6530047121
# 1678876, 2022-11-12 09:39:26, --x (0%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
# print(a)
# print(b)
c=False
team_check=input().split()
while team_check[0]!="q":
    for i in range(len(team_check)):
        for k in range(len(team_check)):
            if b[team_check[i]]==b[team_check[k]]:
                print("Not OK")
                c=True
                break
        if c:
            break            
    team_check=input().split()

# 1679169, 2022-11-12 09:56:13, --- (0%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
# print(a)
# print(b)
c=False
team_check=input().split()
while team_check[0]!="q":
    for i in range(len(team_check)):
        if c:
            break        
        for k in range(len(team_check)-1):
#             if c:
#                 break
            if team_check[i] not in b or team_check[k+1] not in b:
                print("Not OK")
                c=True
                break
            elif b[team_check[i]]==b[team_check[k+1]]:
                print("Not OK")
                c=True
                break

    if not c:
        print("OK")
    c=False
    team_check=input().split()

# 1679331, 2022-11-12 10:04:46, --- (0%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
print(a)
print(b)
c=False
team_check=input().split()
while team_check[0]!="q":
    for i in range(len(team_check)):
        if c:
            break        
        for k in range(len(team_check)-1):
#             if c:
#                 break
            if team_check[i] not in b or team_check[k+1] not in b:
                print("Not OK")
                c=True
                break
            elif b[team_check[i]]==b[team_check[k+1]]:
                print("Not OK")
                c=True
                break

    if not c:
        print("OK")
    c=False
    team_check=input().split()

# 1679599, 2022-11-12 10:19:33, -Px (33%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
# print(a)
# print(b)
c=False
d=set()
team_check=input().split()
while team_check[0]!="q":
    for i in range(len(team_check)-1):
        if c:
            break        
        for k in range(len(team_check)-1):
#             if c:
#                 break
            for l in team_check:
                d.add(b[l])
            
            if team_check[i] not in b or team_check[k+1] not in b:
                print("Not OK")
                c=True
                break
#             elif b[team_check[i]]==b[team_check[k+i+1]]:
#                 print("Not OK")
#                 c=True
#                 break

            elif (len(d))!=(len(team_check)):
                print("Not OK")
                c=True
                break

    if not c:
        print("OK")
    c=False
    team_check=input().split()

# 1679676, 2022-11-12 10:23:08, -P- (33%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
# print(a)
# print(b)
c=False
d=set()
team_check=input().split()
while team_check[0]!="q":
    for i in range(len(team_check)-1):
        if c:
            break        
        for k in range(len(team_check)-1):
#             if c:
#                 break
            for l in team_check:
                if l in b:
                    d.add(b[l])
            
            if team_check[i] not in b or team_check[k+1] not in b:
                print("Not OK")
                c=True
                break
#             elif b[team_check[i]]==b[team_check[k+i+1]]:
#                 print("Not OK")
#                 c=True
#                 break

            elif (len(d))!=(len(team_check)):
                print("Not OK")
                c=True
                break

    if not c:
        print("OK")
    c=False
    team_check=input().split()

# 1679861, 2022-11-12 10:30:34, --- (0%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
# print(a)
print(b)
c=False
d=set()
team_check=input().split()
while team_check[0]!="q":
    for i in range(len(team_check)-1):
        if c:
            break        
        for k in range(len(team_check)-1):
#             if c:
#                 break
            for l in team_check:
                if l in b:
                    d.add(b[l])
            
#             if team_check[i] not in b or team_check[k+1] not in b:
#                 print("Not OK")
#                 c=True
#                 break
#             elif b[team_check[i]]==b[team_check[k+i+1]]:
#                 print("Not OK")
#                 c=True
#                 break

            if (len(d))<(len(team_check)):
                print("Not OK")
                c=True
                break

    if not c:
        print("OK")
    c=False
    team_check=input().split()

# 1679872, 2022-11-12 10:30:47, --- (0%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
# print(a)
print(b)
c=False
d=set()
team_check=input().split()
while team_check[0]!="q":
    for i in range(len(team_check)-1):
        if c:
            break        
        for k in range(len(team_check)-1):
#             if c:
#                 break
            for l in team_check:
                if l in b:
                    d.add(b[l])
            
#             if team_check[i] not in b or team_check[k+1] not in b:
#                 print("Not OK")
#                 c=True
#                 break
#             elif b[team_check[i]]==b[team_check[k+i+1]]:
#                 print("Not OK")
#                 c=True
#                 break

            if (len(d))!=(len(team_check)):
                print("Not OK")
                c=True
                break

    if not c:
        print("OK")
    c=False
    team_check=input().split()
# 1679900, 2022-11-12 10:31:52, --- (0%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
# print(a)
print(b)
c=False
d=set()
team_check=input().split()
while team_check[0]!="q":
    for i in range(len(team_check)-1):
        if c:
            break        
        for k in range(len(team_check)-1):
#             if c:
#                 break
            for l in team_check:
                if l in b:
                    d.add(b[l])
            
#             if team_check[i] not in b or team_check[k+1] not in b:
#                 print("Not OK")
#                 c=True
#                 break
#             elif b[team_check[i]]==b[team_check[k+i+1]]:
#                 print("Not OK")
#                 c=True
#                 break

            if (len(d))!=(len(team_check)):
                print("Not OK")
                c=True
                break

    if not c:
        print("OK")
    c=False
    team_check=input().split()

# 1679918, 2022-11-12 10:32:29, -P- (33%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
# print(a)
# print(b)
c=False
d=set()
team_check=input().split()
while team_check[0]!="q":
    for i in range(len(team_check)-1):
        if c:
            break        
        for k in range(len(team_check)-1):
#             if c:
#                 break
            for l in team_check:
                if l in b:
                    d.add(b[l])
            
            if team_check[i] not in b or team_check[k+1] not in b:
                print("Not OK")
                c=True
                break
#             elif b[team_check[i]]==b[team_check[k+i+1]]:
#                 print("Not OK")
#                 c=True
#                 break

            elif (len(d))!=(len(team_check)):
                print("Not OK")
                c=True
                break

    if not c:
        print("OK")
    c=False
    team_check=input().split()
# 1680171, 2022-11-12 10:44:55, PPP (100%)

team_num=int(input())
a={}
b={}
for i in range(team_num):
    team_name=input().split()
    if team_name[1] not in a:
        a[team_name[1]]=[team_name[0]]
    else:
        a[team_name[1]].append(team_name[0])
    b[team_name[0]]=team_name[1]
# print(a)
# print(b)
c=False
d=set()
team_check=input().split()
while team_check[0]!="q":
    for i in team_check:
        if i in b:
            d.add(b[i])
    if (len(d))!=(len(team_check)):
        print("Not OK")
        c=True
        d=set()

    else:
        print("OK")
    c=False
    d=set()
    team_check=input().split()



6531337321
# 1678498, 2022-11-12 09:17:44, --- (0%)

teams = {}

for _ in range(int(input())):
    team, origin = input().split()
    teams[team] = origin

while True:
    input_ = input().split()
    if input_[0] == 'q':
        break

    countries = set()    
    for team in input_[1:]:
        if team in teams:
            country = teams[team]
        else:
            print('Not OK')
            break

        if country in countries:
            print('Not OK')
            break
        countries.add(country)
    else:
        print('OK')
# 1678519, 2022-11-12 09:19:56, --- (0%)

teams = {}

for _ in range(int(input())):
    team, origin = input().split()
    teams[team] = origin

while True:
    input_ = input().split()
    if input_[0] == 'q':
        break

    countries = set()    
    for team in input_[1:]:
        if team in teams:
            country = teams[team]
        else:
            print('Not OK')
            break

        if country in countries:
            print('Not OK')
            break
        countries.add(country)
    else:
        print('OK')
# 1678650, 2022-11-12 09:27:40, --- (0%)

teams = {}

for _ in range(int(input())):
    team, origin = input().split()
    teams[team] = origin

while True:
    input_ = input().split()
    if input_[0] == 'q':
        break

    countries = set()    
    for team in input_[1:]:
        if team in teams:
            country = teams[team]
        else:
            print('Not OK')
            break

        if country in countries:
            print('Not OK')
            break
        countries.add(country)
    else:
        print('OK')
        
# 1678837, 2022-11-12 09:37:18, --- (0%)

teams = {}

for _ in range(int(input())):
    team, origin = input().split()
    teams[team] = origin

while True:
    input_ = input().split()
    if input_[0] == 'q':
        break

    countries = set()    
    for team in input_[1:]:
        if team in teams:
            country = teams[team]
        else:
            print('Not OK')
            break

        if country in countries:
            print('Not OK')
            break
        countries.add(country)
    else:
        print('OK')
        
        
# 1678971, 2022-11-12 09:45:15, --- (0%)

teams = {}

for _ in range(int(input())):
    team, origin = input().split()
    teams[team] = origin

while True:
    inpu = input().split()
    if inpu[0] == 'q':
        break

    countries = set()    
    for team in inpu[1:]:
        if team in teams:
            country = teams[team]
        else:
            print('Not OK')
            break

        if country in countries:
            print('Not OK')
            break
        countries.add(country)
    else:
        print('OK')
# 1679239, 2022-11-12 10:00:25, --- (0%)

teams = {}

for _ in range(int(input())):
    team, origin = input().split()
    teams[team] = origin

while True:
    input_ = input().split()
    if input_[0] == 'q':
        break

    countries = set()
    group = input_[1:]    
    for team in group:
        if team not in teams:
            print('Not OK')
            break
        country = teams[team]
        if country in countries:
            print('Not OK')
            break
        countries.add(country)
    else:
        print('OK')
# 1679261, 2022-11-12 10:01:14, --- (0%)

teams = {}

for _ in range(int(input())):
    team, origin = input().split()
    teams[team] = origin

while True:
    input_ = input().split()
    if input_[0] == 'q':
        break

    countries = set()
    group = input_[1:]    
    for team in group:
        if team not in teams:
            print('Not Ok')
            break
        country = teams[team]
        if country in countries:
            print('Not Ok')
            break
        countries.add(country)
    else:
        print('Ok')
# 1679954, 2022-11-12 10:34:58, PPP (100%)

teams = {}  # {team: country}
for _ in range(int(input())):
    team, origin = input().split()
    teams[team] = origin

while True:
    input_ = input().split()
    if input_[0] == 'q':
        break

    countries = set()    
    for team in input_:
        if team not in teams:
            print('Not OK')
            break
        country = teams[team]
        if country in countries:
            print('Not OK')
            break
        countries.add(country)
    else:
        print('OK')
# 1680567, 2022-11-12 11:01:55, PPP (100%)

teams = {}  # {team: country}
for _ in range(int(input())):
    team, origin = input().split()
    teams[team] = origin

while True:
    input_ = input().split()
    if input_[0] == 'q':
        break

    countries = set()    
    for team in input_:
        if team not in teams:
            print('Not OK')
            break
        country = teams[team]
        if country in countries:
            print('Not OK')
            break
        countries.add(country)
    else:
        print('OK')
# 1680570, 2022-11-12 11:02:04, PPP (100%)

t = {}
t.update([input().split() for _ in range(int(input()))])
while 1:
    a, b = input().split(), set()
    if a[0] == 'q': break  
    for c in a:
        if c not in t:
            print('Not OK')
            break
        elif t[c] in b:
            print('Not OK')
            break
        b.add(t[c])
    else:
        print('OK')

6531023221
# 1678769, 2022-11-12 09:33:58, xxx (0%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
g=input().split()
while g !='q':
    tg=[]
    for j in g:
        if team[j] not in tg:
            t.append(team[j])
            print('OK')
        else:
            print('Not OK')
# 1678875, 2022-11-12 09:39:25, TTT (0%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
g=input().split()
while g !='q':
    tg=[]
    for j in g:
        if not team[j] in tg:
            tg.append(team[j])
            print('OK')
        elif team[j] in tg:
            print('Not OK')

# 1678880, 2022-11-12 09:39:37, TTT (0%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
g=input().split()
while g !='q':
    tg=[]
    for j in g:
        if not team[j] in tg:
            tg.append(team[j])
            print('OK')
        elif team[j] in tg:
            print('Not OK')
# 1679339, 2022-11-12 10:05:18, xxx (0%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
g=input().split()
while g !='q':
    tg=[]
    for i in g:
        c=0
        if not team[i] in tg:
            tg.append(team[i])
        elif team[i] in tg:
            c+=1
    if c >= 1:
        print('Not OK')
    else:
        print('OK')
    g=input().split()    
# 1679345, 2022-11-12 10:05:31, xxx (0%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
g=input().split()
while g !='q':
    tg=[]
    for i in g:
        c=0
        if not team[i] in tg:
            tg.append(team[i])
        elif team[i] in tg:
            c+=1
    if c >= 1:
        print('Not OK')
    else:
        print('OK')
    g=input().split()
# 1679589, 2022-11-12 10:18:54, PPP (100%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
m=input().strip().split()
T1=[]
for d,v in team.items():
    T1.append(d)
   
while m != ['q']:
    check=[]
    t=True
    for i in m:
        if i in T1:
            if team[i] in check:
                print('Not OK')
                t=False
                break
            check.append(team[i])
        else:
            print('Not OK')
            t=False
    if t == True:
        print('OK')
    m=input().strip().split()    
# 1679613, 2022-11-12 10:20:20, PPP (100%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
g=input().strip().split()
tg=[]
for d,v in team.items():
    tg.append(d)
   
while g != ['q']:
    check=[]
    t=True
    for i in g:
        if i in tg:
            if team[i] in check:
                print('Not OK')
                t=False
                break
            check.append(team[i])
        else:
            print('Not OK')
            t=False
    if t == True:
        print('OK')
    g=input().strip().split()
# 1679639, 2022-11-12 10:21:42, PPP (100%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
group=input().strip().split()
tg=[]
for d,v in team.items():
    tg.append(d)
   
while group != ['q']:
    check=[]
    t=True
    for i in group:
        if i in tg:
            if team[i] in check:
                print('Not OK')
                t=False
                break
            check.append(team[i])
        else:
            print('Not OK')
            t=False
    if t == True:
        print('OK')
    group=input().strip().split()
# 1679643, 2022-11-12 10:21:51, PPP (100%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
group=input().strip().split()
tg=[]
for d,v in team.items():
    tg.append(d)
   
while group != ['q']:
    check=[]
    t=True
    for i in group:
        if i in tg:
            if team[i] in check:
                print('Not OK')
                t=False
                break
            check.append(team[i])
        else:
            print('Not OK')
            t=False
    if t == True:
        print('OK')
    group=input().strip().split()
# 1679650, 2022-11-12 10:22:08, PPP (100%)

n=int(input())
team={}
for i in range(n):
    x,y=input().split()
    team[x]=y
group=input().strip().split()
tg=[]
for d,v in team.items():
    tg.append(d)
while group != ['q']:
    check=[]
    t=True
    for i in group:
        if i in tg:
            if team[i] in check:
                print('Not OK')
                t=False
                break
            check.append(team[i])
        else:
            print('Not OK')
            t=False
    if t == True:
        print('OK')
    group=input().strip().split()

6530068321
# 1678856, 2022-11-12 09:38:18, --- (0%)

na={}
for i in range(int(input())):
    t,n=input().split()
    if n not in na: na[n]={t}
    else:na[n].add(t)
c=input().split()
for e in na:
    r=0
    for i in c:
        if i in na[e]: r+=1
if r==1:print("OK")
else:print("Not OK")
# 1679472, 2022-11-12 10:12:32, --- (0%)

print("Not OK")
# 1679482, 2022-11-12 10:12:47, --- (0%)

print("OK")
# 1679517, 2022-11-12 10:14:14, --- (0%)

na={}
for i in range(int(input())):
    t,n=input().split()
    if n not in na: na[n]={t}
    else:na[n].add(t)
c=input().strip().split()
for e in na:
    if len(set(c)&na[e])>1:print("Not OK")
    

# 1679799, 2022-11-12 10:28:26, xxx (0%)

na={}
for i in range(int(input())):
    t,n=input().split()
    if n not in na: na[n]={t}
    else:na[n].add(t)
    
while True :
    c=input().split()
    if c=="q":break
    for e in na:
        if len(set(c)&na[e])>1:print("Not OK")
# 1679952, 2022-11-12 10:34:51, xxx (0%)

na={}
for i in range(int(input())):
    t,n=input().split()
    na[t]=n
while True :
    c=input().split()
    if c=="q":break
    a=[]
    for i in c:
        a.append(na[i])
    if len(c)==len(set(a)):print("Ok")
    else:print("Not Ok")
    
# 1680058, 2022-11-12 10:39:36, xxx (0%)

na={}
for i in range(int(input())):
    t,n=input().split()
    na[t]=n
while True :
    c=input().split()
    if c=="q":break
    a=[]
    for i in c:
        if i in na.keys(): 
            a.append(na[i])  
    if len(c)==len(set(a)):print("Ok")
    else:print("Not Ok")
    

# 1680248, 2022-11-12 10:49:21, --- (0%)

na={}
for i in range(int(input())):
    t,n=input().split()
    na[t]=n
while True :
    c=input().split()
    if c[0]=="q":
        break
    else :
        a=[]
        for i in c:
            if i in na.keys(): 
                a.append(na[i])  
        if len(c)==len(set(a)):print("Ok")
        else:print("Not Ok")
# 1680308, 2022-11-12 10:51:49, PPP (100%)

na={}
for i in range(int(input())):
    t,n=input().split()
    na[t]=n
while True :
    c=input().split()
    if c[0]=="q":
        break
    else :
        a=[]
        for i in c:
            if i in na.keys(): 
                a.append(na[i])  
        if len(c)==len(set(a)):print("OK")
        else:print("Not OK")
    

6530147221
# 1678503, 2022-11-12 09:18:08, xxx (0%)

x = int(input())
team = {}
ans = []
for i in range(x):
    k, l = input().split()
    team[k] = l
o = input()
while o != "q":
    o = o.split()
    for i in o:
        if i in team:
            if team[i] not in ans:
                ans.append(team[i])
if len(ans) == 4:
    print("OK")
else:
    print("Not OK")
# 1678540, 2022-11-12 09:21:32, --- (0%)

x = int(input())
team = {}
ans = []
for i in range(x):
    k, l = input().split()
    team[k] = l
o = input()
while o != "q":
    o = o.split()
    for i in o:
        if i in team:
            if team[i] not in ans:
                ans.append(team[i])
    o = input()
if len(ans) == 4:
    print("OK")
else:
    print("Not OK")
        
# 1678574, 2022-11-12 09:23:32, --- (0%)

x = int(input())
team = {}
ans = []
for i in range(x):
    k, l = input().split()
    team[k] = l
o = input()
while o != "q":
    o = o.split()
    for i in o:
        if i in team:
            if team[i] not in ans:
                ans.append(team[i])
    o = input()
    if len(ans) == 4:
        print("OK")
    else:
        print("Not OK")
    ans = []
            
# 1678690, 2022-11-12 09:29:37, --- (0%)

x = int(input())
team = {}
ans = []
ans = []
for i in range(x):
    k, l = input().split()
    team[k] = l
o = input()
while o != "q":
    o = o.split()
    for i in o:
        if i in team:
            if team[i] not in ans:
                ans.append(team[i])
    if len(ans) == len(set(ans)):
        print("OK")
    else:
        print("Not OK")
    ans = []
    o = input()
    
# 1678763, 2022-11-12 09:33:35, PP- (67%)

x = int(input())
team = {}
ans = []
for i in range(x):
    k, l = input().split()
    team[k] = l
o = input()
while o != "q":
    o = o.split()
    for i in o:
        if i in team:
            ans.append(team[i])
    if len(ans) == len(set(ans)):
        print("\nOK")
    else:
        print("\nNot OK")
    ans = []
    o = input()
    
# 1678815, 2022-11-12 09:36:20, PP- (67%)

x = int(input())
team = {}
ans = []
pas = False
for i in range(x):
    k, l = input().split()
    team[k] = l
o = input()
while o != "q":
    o = o.split()
    for i in o:
        if i in team:
            ans.append(team[i])
        else:
            print("\nNot OK")
            pas = True
    if not pas:
        if len(ans) == len(set(ans)):
            print("\nOK")
        else:
            print("\nNot OK")
    ans = []
    o = input()
    
# 1678857, 2022-11-12 09:38:20, PP- (67%)

x = int(input())
team = {}
ans = []
pas = False
for i in range(x):
    k, l = input().split()
    team[k] = l
o = input()
while o != "q":
    o = o.split()
    for i in o:
        if i in team:
            ans.append(team[i])
        else:
            print("\nNot OK")
            pas = True
    if not pas:
        if len(ans) == len(set(ans)):
            print("\nOK")
        else:
            print("\nNot OK")
    ans = []
    o = input()
# 1678996, 2022-11-12 09:46:55, --- (0%)

x = int(input())
team = {}
ans = []
pas = False
pas1 = False
for i in range(x):
    k, l = input().split()
    team[k] = l
o = input()
while o != "q":
    o = o.split()
    if len(o) <= 1:
        print("\nNot OK")
    else:
        pas1 = True
        
    if pas1:  
        for i in o:
            if i in team:
                ans.append(team[i])
            else:
                print("\nNot OK")
                pas = True
        if not pas and pas:
            if len(ans) == len(set(ans)):
                print("\nOK")
            else:
                print("\nNot OK")
    ans = []
    o = input()
    pas = False
    pas1 = False
# 1679044, 2022-11-12 09:49:09, PPP (100%)

x = int(input())
team = {}
ans = []
pas = False
pas1 = False
for i in range(x):
    k, l = input().split()
    team[k] = l
o = input()
while o != "q":
    o = o.split()
    if len(o) <= 1:
        print("\nNot OK")
    else:
        pas1 = True
        
    if pas1:  
        for i in o:
            if i in team:
                ans.append(team[i])
            else:
                print("\nNot OK")
                pas = True
        if not pas and pas1:
            if len(ans) == len(set(ans)):
                print("\nOK")
            else:
                print("\nNot OK")
    ans = []
    o = input()
    pas = False
    pas1 = False

6532180221
# 1678502, 2022-11-12 09:18:05, x-- (0%)

n = int(input())
m = {}
for i in '8'*n:
    a,b = input().split()
    m[a]=b

while(True):
    i = input()
    if(i=='q'):break
    d = {};ok=1
    a = input().split()
    for i in a:
        if(not i in m):
            ok=0
            continue
        if(m[i] in d):
            ok=0
        d[m[i]] = True
    
    if(not ok): print("Not ")
    print("OK")
# 1678509, 2022-11-12 09:18:50, x-- (0%)

n = int(input())
m = {}
for i in '8'*n:
    a,b = input().split()
    m[a]=b

while(True):
    i = input()
    if(i=='q'):break
    d = {};ok=1
    a = input().split()
    for i in a:
        if(not i in m):
            ok=0
            continue
        if(m[i] in d):
            ok=0
        d[m[i]] = True
    
    if(not ok): print("Not ",end='')
    print("OK")
# 1678525, 2022-11-12 09:20:19, x-- (0%)

n = int(input())
m = {}
for i in '8'*n:
    a,b = input().split()
    m[a]=b

while(True):
    i = input()
    if(i=='q'):break
    d = {};ok=1
    a = input().split()
    for i in a:
        if(not i in m):
            ok=0
            continue
        if(m[i] in d):
            ok=0
        d[m[i]] = True
    
    if(not ok): print("Not OK")
    else: print("OK")
# 1678590, 2022-11-12 09:24:33, x-- (0%)

n = int(input())
m = {}
for i in '8'*n:
    a,b = input().split()
    m[a]=b

while(True):
    i = input()
    if(i=='q'):break
    d = {};ok=1
    a = input().split()
    # print(a, "fine")
    for i in a:
        if(not i in m):
            ok=0
            continue
        if(m[i] in d):
            ok=0
        d[m[i]] = True
    # print(ok)
    if ok : print("OK")
    if(not ok): print("Not OK")
# 1678680, 2022-11-12 09:29:07, xxx (0%)

n = int(input())
team_to_country = {}
for i in range(n):
    a,b = input().split()
    team_to_country[a] = b


while True :
    a = input().split()
    
    if(a=='q'): break
    
    ok = True
    seen_country = {}
    for team in a:
        if(team not in team_to_country):
            ok = False
            break

        if(team_to_country[team] in seen_country):
            ok = False
            break
        
        seen_country[team_to_country[team]] = True
    
    if(ok): print("OK")
    else: print("Not OK")

# 1678695, 2022-11-12 09:30:00, xxx (0%)

n = int(input())
team_to_country = {}
for i in range(n):
    a,b = input().split()
    team_to_country[a] = b


while True :
    a = input().split()
    
    if(a=='q'): break
    
    ok = True
    seen_country = {}
    for team in a:
        if(team not in team_to_country):
            ok = False
            break

        if(team_to_country[team] in seen_country):
            ok = False
            break
        
        seen_country[team_to_country[team]] = True
    
    if(ok): print("OK")
    else: print("Not OK")

# 1678747, 2022-11-12 09:32:22, xxx (0%)

n = int(input())
team_to_country = {}
for i in range(n):
    a,b = input().split(' ')
    team_to_country[a] = b


while True :
    a = input().strip().split(' ')
    
    if(a=='q'): break
    
    ok = True
    seen_country = {}
    for team in a:
        if(team not in team_to_country):
            ok = False
            break

        if(team_to_country[team] in seen_country):
            ok = False
            break
        
        seen_country[team_to_country[team]] = True
    
    if(ok): print("OK")
    else: print("Not OK")

# 1678823, 2022-11-12 09:36:37, xxx (0%)

n = int(input())
team_to_country = {}
for i in range(n):
    a,b = input().split(' ')
    team_to_country[a] = b

ans_list = []
while True :
    a = input().strip().split(' ')
    
    if(a=='q'): break
    
    ok = True
    seen_country = dict()
    for team in a:
        if(team not in team_to_country):
            ok = False
            break

        if(team_to_country[team] in seen_country):
            ok = False
            break
        
        seen_country[team_to_country[team]] = True
    
    if ok: ans_list.append("OK")
    else: ans_list.append("Not OK")

for ii in ans_list:
    print(ii)
# 1678847, 2022-11-12 09:37:39, PPP (100%)

n = int(input())
team_to_country = {}
for i in range(n):
    a,b = input().split(' ')
    team_to_country[a] = b

ans_list = []
while True :
    a = input().strip().split(' ')
    if(a==['q']): break
    
    ok = True
    seen_country = dict()
    for team in a:
        if(team not in team_to_country):
            ok = False
            break

        if(team_to_country[team] in seen_country):
            ok = False
            break
        
        seen_country[team_to_country[team]] = True
    
    if ok: ans_list.append("OK")
    else: ans_list.append("Not OK")

for ii in ans_list:
    print(ii)

6431007121
# 1678929, 2022-11-12 09:43:07, --- (0%)

n=int(input())
group={}
con=[]
count=[]
for i in range(n):
    team,country=input().split()
    group[team]=country
    con.append(country)
x=input().split()
while x[0]!='q':
    for e in x:
        if e not in group:
            print('Not OK')
        
    x=input().split()
# 1679034, 2022-11-12 09:48:33, --- (0%)

n=int(input())
group={}
con=[]
count=[]
for i in range(n):
    team,country=input().split()
    group[team]=country
    con.append(country)
x=input().split()
p=[]
while x[0]!='q':
    for e in x:
        if e not in group:
            print('Not OK')
        elif group[e] in count:
            print('Not OK')
            count.append(group[e])
        else:
            print('OK')
            break
    x=input().split()
# 1679590, 2022-11-12 10:18:58, --- (0%)

n=int(input())
group={}
con=[]
count=[]
for i in range(n):
    team,country=input().split()
    group[team]=country
    con.append(country)
x=input().split()
while x[0]!='q':
    f=True
    for e in x:
        if e not in group:
            print('Not OK')
            f=False
        elif group[e] in count:
            print('Not OK')
            f=False
            count.append(group[e])
    if f:
        print('OK')
            
    x=input().split()
# 1679857, 2022-11-12 10:30:28, --x (0%)

n=int(input())
group={}
con=[]
count=[]
for i in range(n):
    team,country=input().split()
    group[team]=country
    con.append(country)
x=input().split()
while x[0]!='q':
    f=True
    for e in x:
        if e not in group:
            print('Not OK')
            f=False
        elif group[e] in count:
            print('Not OK')
            f=False
            break
        count.append(group[e])
    if f:
        print('OK')
            
    x=input().split()
# 1679866, 2022-11-12 10:30:42, --x (0%)

n=int(input())
group={}
con=[]
count=[]
for i in range(n):
    team,country=input().split()
    group[team]=country
    con.append(country)
x=input().split()
while x[0]!='q':
    f=True
    for e in x:
        if e not in group:
            print('Not OK')
            f=False
        elif group[e] in count:
            print('Not OK')
            f=False
            break
        count.append(group[e])
    if f:
        print('OK')
    x=input().split()
# 1679933, 2022-11-12 10:33:32, --x (0%)

n=int(input())
group={}
con=[]
count=[]
for i in range(n):
    team,country=input().split()
    group[team]=country
    con.append(country)
x=input().strip().split()
while x[0]!='q':
    f=True
    for e in x:
        if e not in group:
            print('Not OK')
            f=False
        elif group[e] in count:
            print('Not OK')
            f=False
            break
        count.append(group[e])
    if f:
        print('OK')        
    x=input().split()
# 1680054, 2022-11-12 10:39:30, --- (0%)

n=int(input())
group={}
con=[]
count=[]
for i in range(n):
    team,country=input().split()
    group[team]=country
    con.append(country)
x=input().strip().split()
while x[0]!='q':
    f=True
    for e in x:
        if e not in group:
            print('Not OK')
            f=False
            break    
        elif group[e] in count:
            print('Not OK')
            f=False
            break
        count.append(group[e])
    if f:
        print('OK')        
    x=input().split()
# 1680201, 2022-11-12 10:46:13, PPP (100%)

n=int(input())
group={}
con=[]
for i in range(n):
    team,country=input().split()
    group[team]=country
    con.append(country)
x=input().strip().split()
count=[]
while x[0]!='q':
    f=True
    for e in x:
        if e not in group:
            print('Not OK')
            f=False
            break    
        elif group[e] in count:
            print('Not OK')
            f=False
            break
        count.append(group[e])
    if f:
        print('OK')        
    count=[]
    x=input().split()

6530090021
# 1678669, 2022-11-12 09:28:42, xxx (0%)

a = int(input()) ;team={};c={}
for i in range(a):
    a = input().split()
    team[a[0]] = a[1]
    c[a[1]] = 0
a = input()
while a != 'q':
    a=a.split()
    c[team[a[0]]]=c[team[a[0]]]+1
    c[team[a[1]]]=c[team[a[1]]]+1
    c[team[a[2]]]=c[team[a[2]]]+1
    r =True
    for i in c:
        if c[i] >1:
            print('Not OK')
            r=False
            break
    if r ==True:
        print('OK')
    a =input()
    
    

# 1678705, 2022-11-12 09:30:27, xxx (0%)

a = int(input()) ;team={};c={};ww=[]
for i in range(a):
    a = input().split()
    team[a[0]] = a[1]
    ww.append(a)
    
a = input()
while a != 'q':
    a=a.split()
    for i in ww:
        c[a[1]] = 0
    c[team[a[0]]]=c[team[a[0]]]+1
    c[team[a[1]]]=c[team[a[1]]]+1
    c[team[a[2]]]=c[team[a[2]]]+1
    r =True
    for i in c:
        if c[i] >1:
            print('Not OK')
            r=False
            break
    if r ==True:
        print('OK')
    a =input()
    
    

# 1678955, 2022-11-12 09:44:16, xx- (0%)

a = int(input()) ;team={};c={};ww=[];re=[]
for i in range(a):
    a = input().split()
    team[a[0]] = a[1]
    ww.append(a)
    
a = input()
while a != 'q':
    a=a.split()
    gg=True
    c={}
    for i in ww:
        c[i[1]] = 0
    for i in a:
        if i not in team:
            re.append('Not OK')
            gg =False
            break
    if gg == False:
        break
        
    
        
    c[team[a[0]]]=c[team[a[0]]]+1
    c[team[a[1]]]=c[team[a[1]]]+1
    c[team[a[2]]]=c[team[a[2]]]+1
    r =True
    for i in c:
        if c[i] >1:
            re.append('Not OK')
            r=False
            break
    if r ==True:
        re.append('OK')
    a =input()
for i in re:
    print(i)
    
    

# 1679076, 2022-11-12 09:51:18, PP- (67%)

a = int(input()) ;team={};c={};ww=[];re=[]
for i in range(a):
    a = input().split()
    team[a[0]] = a[1]
    ww.append(a)
    
a = input()
while a != 'q':
    a=a.split()
    gg=True
    c={}
    for i in ww:
        c[i[1]] = 0
    for i in a:
        if i not in team:
            re.append('Not OK')
            gg =False
            break
    if gg == False:
        break
        
    
    for i in a:
        c[team[i]]=c[team[i]]+1
    
    r =True
    for i in c:
        if c[i] >1:
            re.append('Not OK')
            r=False
            break
    if r ==True:
        re.append('OK')
    a =input()
for i in re:
    print(i)
    
    

# 1679156, 2022-11-12 09:55:27, PPx (67%)

a = int(input()) ;team={};c={};ww=[];re=[]
for i in range(a):
    a = input().split()
    team[a[0]] = a[1]
    ww.append(a)
    
a = input()
while a != 'q':
    a=a.split()
    gg=True
    c={}
    for i in ww:
        c[i[1]] = 0
    for i in a:
        if i not in team:
            re.append('Not OK')
            gg =False
            break
        break
    
        
    
    for i in a:
        c[team[i]]=c[team[i]]+1
    
    r =True
    for i in c:
        if c[i] >1:
            re.append('Not OK')
            r=False
            break
    if r ==True:
        re.append('OK')
    a =input()
for i in re:
    print(i)
    
    

# 1679244, 2022-11-12 10:00:34, --- (0%)

a = int(input()) ;team={};c={};ww=[];re=[]
for i in range(a):
    a = input().split()
    team[a[0]] = a[1]
    ww.append(a)
    
a = input()
while a != 'q':
    a=a.split()
    gg=True
    c={}
    for i in ww:
        c[i[1]] = 0
    for i in a:
        if i not in team:
            re.append('Not OK')
            gg =False
            break
    if gg != False:
        for i in a:
            c[team[i]]=c[team[i]]+1
        r =True
        for i in c:
            if c[i] >1:
                re.append('Not OK')
                r=False
                break
            if r ==True:
                re.append('OK')
    a =input()
            
    
        
    
    
for i in re:
    print(i)
    
    

# 1679286, 2022-11-12 10:02:13, PP- (67%)

a = int(input()) ;team={};c={};ww=[];re=[]
for i in range(a):
    a = input().split()
    team[a[0]] = a[1]
    ww.append(a)
    
a = input()
while a != 'q':
    a=a.split()
    gg=True
    c={}
    for i in ww:
        c[i[1]] = 0
    for i in a:
        if i not in team:
            re.append('Not OK')
            gg =False
            break
    if gg == False:
        break
        
    
    for i in a:
        c[team[i]]=c[team[i]]+1
    
    r =True
    for i in c:
        if c[i] >1:
            re.append('Not OK')
            r=False
            break
    if r ==True:
        re.append('OK')
    a =input()
for i in re:
    print(i)
# 1679330, 2022-11-12 10:04:41, PPP (100%)

a = int(input()) ;team={};c={};ww=[];re=[]
for i in range(a):
    a = input().split()
    team[a[0]] = a[1]
    ww.append(a)
    
a = input()
while a != 'q':
    a=a.split()
    gg=True
    c={}
    for i in ww:
        c[i[1]] = 0
    for i in a:
        if i not in team:
            re.append('Not OK')
            gg =False
            break
    if gg != False:
        for i in a:
            c[team[i]]=c[team[i]]+1
        r =True
        for i in c:
            if c[i] >1:
                re.append('Not OK')
                r=False
                break
        if r ==True:
            re.append('OK')
    a =input()
            
    
        
    
    
for i in re:
    print(i)
    
    


6531336721
# 1678546, 2022-11-12 09:21:59, xxx (0%)

dct = {} # {team : country}
for i in range(int(input())):
    team, country = input().split()
    dct[team] = country
while True:
    x = input()
    if x == 'q':
        break
    matching = x.split()
    if matching[0] not in dct or matching[1] not in dct or matching[2] not in dct or matching[3] not in dct:
        print('Not OK')
    elif (dct[matching[0]] == dct[matching[1]]) or (dct[matching[0]] == dct[matching[2]]) or (dct[matching[0]] == dct[matching[3]]) or (dct[matching[1]] == dct[matching[2]]) or (dct[matching[1]] == dct[matching[3]]) or (dct[matching[2]] == dct[matching[3]]):
        print('Not OK')
    else:
        print('OK')
# 1678696, 2022-11-12 09:30:06, xxx (0%)

dct = {} # {team : country}
for i in range(int(input())):
    team, country = input().split()
    dct[team] = country
y = []
while True:
    x = input()
    if x == 'q':
        break
    y.append(x)
for i in range(len(y)):
    matching = y[i].split()
    if matching[0] not in dct or matching[1] not in dct or matching[2] not in dct or matching[3] not in dct:
        print('Not OK')
    elif (dct[matching[0]] == dct[matching[1]]) or (dct[matching[0]] == dct[matching[2]]) or (dct[matching[0]] == dct[matching[3]]) or (dct[matching[1]] == dct[matching[2]]) or (dct[matching[1]] == dct[matching[3]]) or (dct[matching[2]] == dct[matching[3]]):
        print('Not OK')
    else:
        print('OK')
# 1678779, 2022-11-12 09:34:27, xxx (0%)

dct = {} # {team : country}
for i in range(int(input())):
    team, country = input().split()
    dct[team] = country
while True:
    x = input()
    if x == 'q':
        break
    matching = x.split()
    if matching[0] not in dct.keys() or matching[1] not in dct.keys() or matching[2] not in dct.keys() or matching[3] not in dct.keys():
        print('Not OK')
    elif (dct[matching[0]] == dct[matching[1]]) or (dct[matching[0]] == dct[matching[2]]) or (dct[matching[0]] == dct[matching[3]]) or (dct[matching[1]] == dct[matching[2]]) or (dct[matching[1]] == dct[matching[3]]) or (dct[matching[2]] == dct[matching[3]]):
        print('Not OK')
    else:
        print('OK')
# 1678795, 2022-11-12 09:35:07, xxx (0%)

dct = {} # {team : country}
n = int(input())
for i in range(n):
    team, country = input().split()
    dct[team] = country
while True:
    x = input()
    if x == 'q':
        break
    matching = x.split()
    if matching[0] not in dct.keys() or matching[1] not in dct.keys() or matching[2] not in dct.keys() or matching[3] not in dct.keys():
        print('Not OK')
    elif (dct[matching[0]] == dct[matching[1]]) or (dct[matching[0]] == dct[matching[2]]) or (dct[matching[0]] == dct[matching[3]]) or (dct[matching[1]] == dct[matching[2]]) or (dct[matching[1]] == dct[matching[3]]) or (dct[matching[2]] == dct[matching[3]]):
        print('Not OK')
    else:
        print('OK')
# 1678873, 2022-11-12 09:39:11, xxx (0%)

dct = {} # {team : country}
for i in range(int(input())):
    team, country = input().split()
    dct[team] = country
y = []
while True:
    x = input()
    if x == 'q':
        break
    y.append(x)
for i in range(len(y)):
    matching = y[i].split()
    if matching[0] not in dct or matching[1] not in dct or matching[2] not in dct or matching[3] not in dct:
        print('Not OK')
    elif (dct[matching[0]] == dct[matching[1]]) or (dct[matching[0]] == dct[matching[2]]) or (dct[matching[0]] == dct[matching[3]]) or (dct[matching[1]] == dct[matching[2]]) or (dct[matching[1]] == dct[matching[3]]) or (dct[matching[2]] == dct[matching[3]]):
        print('Not OK')
    else:
        print('OK')
# 1679400, 2022-11-12 10:08:41, --- (0%)

dct = {} # {team : country}
n = int(input())
for i in range(n):
    team, country = input().split()
    dct[team] = country
while True:
    try:
        x = input()
        if x == 'q':
            break
        matching = x.split()
        if matching[0] not in dct.keys() or matching[1] not in dct.keys() or matching[2] not in dct.keys() or matching[3] not in dct.keys():
            print('Not OK')
        elif (dct[matching[0]] == dct[matching[1]]) or (dct[matching[0]] == dct[matching[2]]) or (dct[matching[0]] == dct[matching[3]]) or (dct[matching[1]] == dct[matching[2]]) or (dct[matching[1]] == dct[matching[3]]) or (dct[matching[2]] == dct[matching[3]]):
            print('Not OK')
        else:
            print('OK')
    except:
        print('None')
# 1679430, 2022-11-12 10:10:31, --- (0%)

dct = {} # {team : country}
n = int(input())
for i in range(n):
    team, country = input().split()
    dct[team] = country
while True:
        x = input()
        if x == 'q':
            break
        matching = x.split()
        
# 1679618, 2022-11-12 10:20:31, PPP (100%)

dct = {} # {team : country}
n = int(input())
for i in range(n):
    team, country = input().split()
    dct[team] = country
while True:
    x = input()
    if x == 'q':
        break
    matching = x.split()
    lst = []
    check = False
    for e in matching:
        if e not in dct.keys():
            print('Not OK')
            check = True
            break
        else:
            lst.append(dct[e])
    if check == True:
        pass
    else:
        if len(set(lst)) == len(lst):
            print('OK')
        else:
            print('Not OK')
        



6230003221
# 1678758, 2022-11-12 09:33:11, x-x (0%)

team={} #country:team
country={}
for i in range(int(input())):
    t,c=input().split()
    country[t]=c
    if c not in team:
        team[c]=[t]
    else:
        team[c].append(t)
n=[e for e in input().split()]
OK=True
while n[0]!="q":
    for i in range(len(n)):
        for j in range(i+1,(len(n))):
            if country[n[i]]==country[n[j]]:
                OK=False
        if OK==True:
            print("OK")
        else:
            print("Not OK")
        n=[e for e in input().split()]
       
    
# 1678940, 2022-11-12 09:43:39, x-x (0%)

team={} #country:team
country={}
for i in range(int(input())):
    t,c=input().split()
    country[t]=c
    if c not in team:
        team[c]=[t]
    else:
        team[c].append(t)
n=[e for e in input().split()]
OK=True
while n[0]!="q":
    for i in range(len(n)):
        for j in range(i+1,(len(n))):
            if n[i] in country:
                if country[n[i]]==country[n[j]]:
                    OK=False
            else:
                OK=False
        if OK==True:
            print("OK")
        else:
            print("Not OK")
        n=[e for e in input().split()]
       
    

        
# 1679682, 2022-11-12 10:23:15, xxx (0%)

team={} #country:team
country={}
for i in range(int(input())):
    t,c=input().split()
    country[t]=c
    if c not in team:
        team[c]=[t]
    else:
        team[c].append(t)
n=[e for e in input().split()]
OK=True
while n[0]!="q":
    for i in range(len(n)):
        if n[i] in country:
            for j in range(1,len(n)):
                if country[n[i]]==country[n[j]]:
                    OK=False
                else:
                    OK=True
        else:
            Ok=False
        if OK==True:
            print("OK")
        else:
            print("Not OK")
        n=[e for e in input().split()]
       
# 1679934, 2022-11-12 10:33:36, xxx (0%)

team={} #country:team
country={}
for i in range(int(input())):
    t,c=input().split()
    country[t]=c
    if c not in team:
        team[c]=[t]
    else:
        team[c].append(t)
n=[e for e in input().split()]
OK=True
while n[0]!="q":
    for i in range(len(n)):
        if n[i] not in country:
            OK=False
        elif OK==True:
            for j in range(i+1,len(n)):
                if country[n[i]]==country[n[j]]:
                    OK=False
                else:
                    OK=True
        if OK==True:
            print("OK")
        else:
            print("Not OK")
        n=[e for e in input().split()]
# 1680029, 2022-11-12 10:38:21, xxx (0%)

team={} #country:team
country={}
for i in range(int(input())):
    t,c=input().split()
    country[t]=c
    if c not in team:
        team[c]=[t]
    else:
        team[c].append(t)
n=[e.strip() for e in input().split()]
OK=True
while n[0]!="q":
    for i in range(len(n)):
        if n[i] not in country:
            OK=False
        elif OK==True:
            for j in range(i+1,len(n)):
                if country[n[i]]==country[n[j]]:
                    OK=False
                else:
                    OK=True
        if OK==True:
            print("OK")
        else:
            print("Not OK")
        n=[e.strip() for e in input().split()]
# 1680443, 2022-11-12 10:56:18, PPx (67%)

team={} #country:team
country={}
for i in range(int(input())):
    t,c=input().split()
    country[t]=c
    if c not in team:
        team[c]=[t]
    else:
        team[c].append(t)
n=input().split()
while n[0]!="q":
    OK=True
    for i in range(len(n)):
        if n[i] not in country:
            OK=False
        elif OK==True:
            for j in range(i+1,len(n)):
                if country[n[i]]==country[n[j]]:
                    OK=False
    if OK==True:
        print("OK")
    else:
        print("Not OK")
    n=input().split()
       
    

# 1680516, 2022-11-12 10:59:46, PPP (100%)

team={} #country:team
country={}
for i in range(int(input())):
    t,c=input().split()
    country[t]=c
    if c not in team:
        team[c]=[t]
    else:
        team[c].append(t)
n=input().split()
while n[0]!="q":
    OK=True
    for i in range(len(n)):
        if n[i] not in country:
            OK=False
    if OK==True:
        for i in range(len(n)):
            for j in range(i+1,len(n)):
                if country[n[i]]==country[n[j]]:
                    OK=False
    if OK==True:
        print("OK")
    else:
        print("Not OK")
    n=input().split()
       
    

6231117321
# 1679304, 2022-11-12 10:03:06, --- (0%)

'''
Quiz3 #1
Password: good_LUCK
'''
import pprint
team_nation = {}
for i in range(int(input())):
    team,nat = [e.strip() for e in input().split()]
    if team not in team_nation: team_nation[team] = []
    team_nation[team].append(nat)
pprint.pprint(team_nation)

while True:
    country = []
    team_group = input().split()
    if len(team_group) == 1: break
    for team in team_group:
        if team not in team_nation.keys():
            print('Not OK')
            break
        else:
            country +=team_nation[team]
            check = []
            found = False
            for i in range(len(country)):
                check.append(country.count(country[i]))
        
                
#                     print('Not OK')
#                     found = True
#                     break
#             if found:
#                 print('OK')
#         
#     for t in country:
#         x = country.count(t)
#         if x>1:
#             print('Not OK')
#             break
#         else:
#             print('OK')
        
            
        

    

# 1679373, 2022-11-12 10:06:55, --- (0%)

'''
Quiz3 #1
Password: good_LUCK
'''
import pprint
team_nation = {}
for i in range(int(input())):
    team,nat = [e.strip() for e in input().split()]
    if team not in team_nation: team_nation[team] = []
    team_nation[team].append(nat)
pprint.pprint(team_nation)

while True:
    country = []
    check = []
    team_group = input().split()
    if len(team_group) == 1: break
    for team in team_group:
        if team not in team_nation.keys():
            print('Not OK')
            break
        else:
            country +=team_nation[team]
            
            found = False
            for i in range(len(country)):
                check.append(country.count(country[i]))
    found = False
    for ele in check:
        if ele !=1 :
            print('Not OK')
            found =True
            break
    if found:
        print('OK')
        
        
                
#                     print('Not OK')
#                     found = True
#                     break
#             if found:
#                 print('OK')
#         
#     for t in country:
#         x = country.count(t)
#         if x>1:
#             print('Not OK')
#             break
#         else:
#             print('OK')
        
            
        

    

# 1680363, 2022-11-12 10:53:39, --- (0%)

'''
Quiz3 #1
Password: good_LUCK
'''
import pprint
team_nation = {}
for i in range(int(input())):
    team,nat = [e.strip() for e in input().split()]
    if team not in team_nation: team_nation[team] = []
    team_nation[team].append(nat)
pprint.pprint(team_nation)

while True:
    country = []
    #check = []
    team_group = input().split()
    if len(team_group) == 1: break
    for team in team_group:
        if team not in team_nation.keys():
            print('Not OK')
            break
        else:
            country +=team_nation[team]
    check = []
    for i in range(len(country)):
        check.append(country.count(country[i]))
    #print(check)
    #found = False
    for ele in check:
        if ele !=1 :
            print('Not OK')
            found =True
            break
    #if found:
    print('OK')
#         
        
                
#                     print('Not OK')
#                     found = True
#                     break
#             if found:
#                 print('OK')
#         
#     for t in country:
#         x = country.count(t)
#         if x>1:
#             print('Not OK')
#             break
#         else:
#             print('OK')
        
            
        

    

# 1680715, 2022-11-12 11:06:53, xxx (0%)

'''
Quiz3 #1
Password: good_LUCK
'''
import pprint
team_nation = {}
for i in range(int(input())):
    team,nat = [e.strip() for e in input().split()]
    if team not in team_nation: team_nation[team] = []
    team_nation[team] += [nat]
pprint.pprint(team_nation)

x = input().strip()
while x!= 'q':
    out = set()
    t = input().split()
    found = False
    for team in t :
        if team not in team_nation.keys():
            print('Not OK')
            found = True
            break
        out.update(team_nation[team])
    if len(out) != len(t):
        print('Not OK')
    else:
        print('OK')
    






# while True:
#     country = []
#     #check = []
#     team_group = input().split()
#     if len(team_group) == 1: break
#     for team in team_group:
#         if team not in team_nation.keys():
#             print('Not OK')
#             break
#         else:
#             country +=team_nation[team]
#     check = []
#     for i in range(len(country)):
#         check.append(country.count(country[i]))
#     #print(check)
#     #found = False
#     for ele in check:
#         if ele !=1 :
#             print('Not OK')
#             found =True
#             break
#     #if found:
#     print('OK')
#         
        
                
#                     print('Not OK')
#                     found = True
#                     break
#             if found:
#                 print('OK')
#         
#     for t in country:
#         x = country.count(t)
#         if x>1:
#             print('Not OK')
#             break
#         else:
#             print('OK')
        
            
        

    

# 1681159, 2022-11-12 11:20:24, xxx (0%)

team_nation = {}
for i in range(int(input())):
    team,nat = [e.strip() for e in input().split()]
    if team not in team_nation: team_nation[team] = []
    team_nation[team] += [nat]
pprint.pprint(team_nation)

#x = input().strip()
while True:
    out = set()
    t = input().split()
    if len(t) == 1: break
    found = False
    for team in t :
        if team not in team_nation.keys():
            break
        else:
            out.update(team_nation[team])          
    if len(out) != len(t):
        print('Not OK')
    else:
        print('OK')
    
# 1681254, 2022-11-12 11:22:40, --- (0%)

'''
Quiz3 #1
Password: good_LUCK
'''
import pprint
team_nation = {}
for i in range(int(input())):
    team,nat = [e.strip() for e in input().split()]
    if team not in team_nation: team_nation[team] = []
    team_nation[team] += [nat]
pprint.pprint(team_nation)

#x = input().strip()
while True:
    out = set()
    t = input().split()
    if len(t) == 1: break
    found = False
    for team in t :
        if team not in team_nation.keys():
            break
        else:
            out.update(team_nation[team])          
    if len(out) != len(t):
        print('Not OK')
    else:
        if len(out) == len(t) and len(out) != 0:
            print('OK')
# 1681330, 2022-11-12 11:24:26, PPP (100%)

'''
Quiz3 #1
Password: good_LUCK
'''
import pprint
team_nation = {}
for i in range(int(input())):
    team,nat = [e.strip() for e in input().split()]
    if team not in team_nation: team_nation[team] = []
    team_nation[team] += [nat]
#pprint.pprint(team_nation)

#x = input().strip()
while True:
    out = set()
    t = input().split()
    if len(t) == 1: break
    found = False
    for team in t :
        if team not in team_nation.keys():
            break
        else:
            out.update(team_nation[team])          
    if len(out) != len(t):
        print('Not OK')
    else:
        if len(out) == len(t) and len(out) != 0:
            print('OK')

6530022421
# 1678523, 2022-11-12 09:20:10, PPx (67%)

d = {}
for i in range(int(input())):
    x, y = input().split()
    d[x] = y
a = input()
while a != 'q':
    m = a.split()
    l = []
    for e in m:
        l.append(d[e])
    s= set(l)
    if len(l) == len(s):
        print('OK')
    else:
        print('Not OK')
    a = input()
# 1678548, 2022-11-12 09:22:00, --x (0%)

d = {}
for i in range(int(input())):
    x, y = input().split()
    d[x] = y
a = input()
while a != 'q':
    m = a.split()
    l = []
    for e in m:
        l.append(d[e])
    s= set(l)
    ANS = []
    if len(l) == len(s):
        ANS.append('OK')
    else:
        ANS.append('Not OK')
    a = input()
for e in ANS:
    print(e)
# 1678652, 2022-11-12 09:27:50, --- (0%)

d = {}
for i in range(int(input())):
    x , y = input().split()
    d[x] = y
a = input()
while a != 'q':
    m = a.split()
    l = []
    for e in m:
        if e in d:
            l.append(d[e])
    s = set(l)
    ANS = []
    if len(s) == len(l):
        ANS.append('OK')
    else:
        ANS.append('Not OK')
    a = input()
for e in ANS:
    print(e)
# 1679002, 2022-11-12 09:47:18, --- (0%)

d = {}
for i in range(int(input())):
    x , y = input().split()
    d[x] = y
a = input()
ANS = []
while a != 'q':
    m = a.split()
    print(m)
    l = []
    for e in m:
        if e in d:
            l.append(d[e])
    s = set(l)
    if len(s) == len(m):
        ANS.append('OK')
    else:
        ANS.append('Not OK')
    a = input()
for e in ANS:
    print(e)
# 1679035, 2022-11-12 09:48:35, --- (0%)

d = {}
for i in range(int(input())):
    x , y = input().split()
    d[x] = y
a = input()
while a != 'q':
    m = a.split()
    print(m)
    l = []
    for e in m:
        if e in d:
            l.append(d[e])
    s = set(l)
    if len(s) == len(m):
        print('OK')
    else:
        print('Not OK')
    a = input()
# 1679039, 2022-11-12 09:48:57, PPP (100%)

d = {}
for i in range(int(input())):
    x , y = input().split()
    d[x] = y
a = input()
while a != 'q':
    m = a.split()
    l = []
    for e in m:
        if e in d:
            l.append(d[e])
    s = set(l)
    if len(s) == len(m):
        print('OK')
    else:
        print('Not OK')
    a = input()
# 1679060, 2022-11-12 09:50:03, PPP (100%)

d = {}
for i in range(int(input())):
    x , y = input().split()
    d[x] = y
a = input()
while a != 'q':
    m = a.split()
    l = []
    for e in m:
        if e in d:
            l.append(d[e])
    s = set(l)
    if len(s) == len(m):
        print('OK')
    else:
        print('Not OK')
    a = input()

6531202221
# 1679479, 2022-11-12 10:12:46, xxx (0%)

n= int(input())
k = 0
t = {}
all_t = []
while k < n:
    a = input()
    team1 = []
    for e in a:
        nameteam,country = e.split()
        if country in t:
            t[country] += [nameteam]
            all_t += [nameteam]
        else:
            t[country] = [nameteam]
            all_t += [nameteam]
    k += 1
t = list(t.values())
print(all_t)
print(t)
g = input()
while g != 'q':
    g1 = g.split()
    ans = ''
    for k in t:
        c = 0
        for j in g1:
            if j in k:
                c += 1
        if c > 1:
                ans = 'Not OK'
                break
        if c == 1:
                ans ='OK'
    for e in g1:
        if e not in all_t:
            ans = 'Not OK'
        break
    print(ans)
    g = input()
# 1679526, 2022-11-12 10:15:02, --- (0%)

n= int(input())
k = 0
t = {}
all_t = []
while k < n:
    a = input()
    team1 = []
    nameteam,country = a.split()
    if country in t:
        t[country] += [nameteam]
        all_t += [nameteam]
    else:
        t[country] = [nameteam]
        all_t += [nameteam]
    k += 1
t = list(t.values())
print(all_t)
print(t)
g = input()
while g != 'q':
    g1 = g.split()
    ans = ''
    for k in t:
        c = 0
        for j in g1:
            if j in k:
                c += 1
        if c > 1:
                ans = 'Not OK'
                break
        if c == 1:
                ans ='OK'
    for e in g1:
        if e not in all_t:
            ans = 'Not OK'
        break
    print(ans)
    g = input()
# 1679531, 2022-11-12 10:15:11, PP- (67%)

n= int(input())
k = 0
t = {}
all_t = []
while k < n:
    a = input()
    team1 = []
    nameteam,country = a.split()
    if country in t:
        t[country] += [nameteam]
        all_t += [nameteam]
    else:
        t[country] = [nameteam]
        all_t += [nameteam]
    k += 1
t = list(t.values())
g = input()
while g != 'q':
    g1 = g.split()
    ans = ''
    for k in t:
        c = 0
        for j in g1:
            if j in k:
                c += 1
        if c > 1:
                ans = 'Not OK'
                break
        if c == 1:
                ans ='OK'
    for e in g1:
        if e not in all_t:
            ans = 'Not OK'
        break
    print(ans)
    g = input()
# 1679756, 2022-11-12 10:26:10, --- (0%)

n= int(input())
k = 0
t = {}
all_t = []
while k < n:
    a = input()
    team1 = []
    nameteam,country = a.split()
    if country in t:
        t[country] += [nameteam]
        all_t += [nameteam]
    else:
        t[country] = [nameteam]
        all_t += [nameteam]
    k += 1
t = list(t.values())
g = input()
while g != 'q':
    g1 = g.split()
    ans = ''
    for k in t:
        c = 0
        for j in g1:
            if j in k:
                c += 1
        if c > 1:
                ans = 'Not OK'
                break
        if c == 1:
                ans ='OK'
        if c == 0:
                ans = 'Not OK'
    g = input()
# 1679760, 2022-11-12 10:26:21, --- (0%)

n= int(input())
k = 0
t = {}
all_t = []
while k < n:
    a = input()
    team1 = []
    nameteam,country = a.split()
    if country in t:
        t[country] += [nameteam]
        all_t += [nameteam]
    else:
        t[country] = [nameteam]
        all_t += [nameteam]
    k += 1
t = list(t.values())
g = input()
while g != 'q':
    g1 = g.split()
    ans = ''
    for k in t:
        c = 0
        for j in g1:
            if j in k:
                c += 1
        if c > 1:
                ans = 'Not OK'
                break
        if c == 1:
                ans ='OK'
        if c == 0:
                ans = 'Not OK'
    g = input()
# 1679820, 2022-11-12 10:29:08, --- (0%)

n= int(input())
k = 0
t = {}
all_t = []
while k < n:
    a = input()
    team1 = []
    nameteam,country = a.split()
    if country in t:
        t[country] += [nameteam]
        all_t += [nameteam]
    else:
        t[country] = [nameteam]
        all_t += [nameteam]
    k += 1
t = list(t.values())
print(all_t)
print(t)
g = input()
while g != 'q':
    g1 = g.split()
    ans = ''
    for k in t:
        c = 0
        for j in g1:
            if j in k:
                c += 1
        if c > 1:
                ans = 'Not OK'
                break
        if c == 1:
                ans ='OK'
    for e in g1:
        if e not in all_t:
            ans = 'Not OK'
    print(ans)
    g = input()
# 1679841, 2022-11-12 10:30:01, PPP (100%)

n= int(input())
k = 0
t = {}
all_t = []
while k < n:
    a = input()
    team1 = []
    nameteam,country = a.split()
    if country in t:
        t[country] += [nameteam]
        all_t += [nameteam]
    else:
        t[country] = [nameteam]
        all_t += [nameteam]
    k += 1
t = list(t.values())
g = input()
while g != 'q':
    g1 = g.split()
    ans = ''
    for k in t:
        c = 0
        for j in g1:
            if j in k:
                c += 1
        if c > 1:
                ans = 'Not OK'
                break
        if c == 1:
                ans ='OK'
    for e in g1:
        if e not in all_t:
            ans = 'Not OK'
    print(ans)
    g = input()

6530046521
# 1678625, 2022-11-12 09:26:14, xxx (0%)

n = int(input())
d = {} #{team: country}
for i in range(n):
    team, ct = input().split()
    if ct not in d:
        d[team] = []
    d[team].append(ct)
    
x = input().split()
l = []
while len(x) > 1:
    if t in x:
        for t in x:
            l.append(d[t])
        s = set(l)
        if len(s) != len(l):
            print('Not OK')
        else:
            print('OK')
    else:
        print('Not OK')
    x = input().split()
# 1678785, 2022-11-12 09:34:49, xxx (0%)

def dup(l):
    s = set()
    for e in l:
        if e in s:
            return True
        s.add(e)
    return False
    
n = int(input())
d = {} #{team: country}
for i in range(n):
    team, ct = input().split()
    if ct not in d:
        d[team] = []
    d[team].append(ct)
    
x = input().split()
l = []
while len(x) > 1:
    for t in x:
        if t in d:
            l.append(d[t])
        else:
            print('Not OK')
    if dup(l):
        print('Not OK')
    print('OK')

    x = input().split()
# 1678904, 2022-11-12 09:41:34, --- (0%)

n = int(input())
d = {} #{team: country}
for i in range(n):
    team, ct = input().split()
    if team not in d:
        d[team] = ct
    
x = input().split()
l = []
while len(x) > 1:
    for t in x:
        if t in d:
            l.append(d[t])
        else:
            print('Not OK')
    s = set(l)
    if len(s) != len(l):
        print('Not OK')
    else:
        print('OK')
    x = input().split()
# 1679082, 2022-11-12 09:51:30, --- (0%)

n = int(input())
d = {} #{team: country}
for i in range(n):
    team, ct = input().split()
    if team not in d:
        d[team] = ct
    
x = input().split()
l = []
while len(x) > 1:
    for t in x:
        if t in d:
            l.append(d[t])
        else:
            print('Not OK')
            break
    if t in d:
        s = set(l)
        if len(s) != len(l):
            print('Not OK')
        else:
            print('OK')
    x = input().split()
# 1679372, 2022-11-12 10:06:52, --- (0%)

n = int(input())
d = {} #{team: country}
for i in range(n):
    team, ct = input().split()
    if team not in d:
        d[team] = ct
print(d)
x = input().split()

while len(x) > 1:
    l = []
    for t in x:
        if t in d:
            l.append(d[t])
        else:
            print('Not OK')
            break
    if t in d:
        s = set(l)
        if len(s) != len(l):
            print('Not OK')
        else:
            print('OK')
    x = input().split()
# 1679401, 2022-11-12 10:08:45, --- (0%)

n = int(input())
d = {} #{team: country}
for i in range(n):
    team, ct = input().split()
    if team not in d:
        d[team] = ct
print(d)


while True:
    x = input().split()
    if len(x) == 1: break
    l = []
    for t in x:
        if t in d:
            l.append(d[t])
        else:
            print('Not OK')
            break
    if t in d:
        s = set(l)
        if len(s) != len(l):
            print('Not OK')
        else:
            print('OK')
# 1679486, 2022-11-12 10:13:02, PPP (100%)

n = int(input())
d = {} #{team: country}
for i in range(n):
    team, ct = input().split()
    if team not in d:
        d[team] = ct

while True:
    x = input().split()
    if len(x) == 1: break
    l = []
    for t in x:
        if t in d:
            l.append(d[t])
        else:
            print('Not OK')
            break
    if t in d:
        s = set(l)
        if len(s) != len(l):
            print('Not OK')
        else:
            print('OK')


6530050021
# 1678739, 2022-11-12 09:32:01, xxx (0%)

#co = {'eng': {'manu', 'liver'}}
co = {}
for i in range(int(input())):
    e = input().strip()
    v,k = e.split()
    if k not in co:
        co[k] = {v}
    else:
        co[k].add(v)
        
a = input().split()
while input!= "q":    
    a = set(a)
    result = "Not OK"
    for e in co:
        if a.issubset(e):
            result = "OK"
            
            
            
            
            
            
    print(result)
    
    
    
    a = input().split()

# 1678781, 2022-11-12 09:34:32, xxx (0%)

#co = {'eng': {'manu', 'liver'}}
co = {}
for i in range(int(input())):
    e = input().strip()
    v,k = e.split()
    if k not in co:
        co[k] = {v}
    else:
        co[k].add(v)
        
a = input().split()
while input!= "q":    
    a = set(a)
    result = "Not OK"
    for e in co:
        if a.issubset(e):
            result = "OK"
            
            
            
            
            
            
    print(result)
    
    
    
    a = input().split()

# 1678782, 2022-11-12 09:34:40, xxx (0%)

#co = {'eng': {'manu', 'liver'}}
co = {}
for i in range(int(input())):
    e = input().strip()
    v,k = e.split()
    if k not in co:
        co[k] = {v}
    else:
        co[k].add(v)
        
a = input().split()
while input!= "q":    
    a = set(a)
    result = "Not OK"
    for e in co:
        if a.issubset(e):
            result = "OK"
            
            
            
            
            
            
    print(result)
    
    
    
    a = input().split()
# 1678818, 2022-11-12 09:36:25, xxx (0%)

#co = {'eng': {'manu', 'liver'}}
co = {}
for i in range(int(input())):
    e = input().strip()
    v,k = e.split()
    if k not in co:
        co[k] = {v}
    else:
        co[k].add(v)
        
a = input().split()
b = []
while a != "[q]":    
    a = set(a)
    result = "Not OK"
    for e in co:
        if a.issubset(co[e]):
            result = "OK"        
    b.append(result) 
    a = input().split()

for e in b:
    print(e)
# 1678958, 2022-11-12 09:44:28, --- (0%)

#co = {'eng': {'manu', 'liver'}}
co = {}
for i in range(int(input())):
    e = input().strip()
    v,k = e.split()
    if k not in co:
        co[k] = {v}
    else:
        co[k].add(v)
        
a = input().split()
b = []
while a != ['q']:    
    a = set(a)
    result = "Not OK"
    for e in co:
        if a.issubset(co[e]):
            result = "OK"
            
            break
    b.append(result)     
    a = input().split()

for e in b:
    print(e)
# 1679247, 2022-11-12 10:00:42, --- (0%)

#co = {'1': {'a'}, '2': {'a'}, '3': {'a'}, '4': {'b'}, '5': {'b'}, '6': {'b'}}
co = {}
for i in range(int(input())):
    e = input().strip()
    k,v = e.split()
    if k not in co:
        co[k] = {v}
    else:
        co[k].add(v)
print(co)

# a = [1,2,3]       
a = input().split()
b = []
while a != ['q']:
    result = "OK"
    for i in range(len(a)):
        for j in range(i+1,len(a)):
            if a[i] not in co or a[j] not in co:
                result = "Not OK"
            else:
                if co[a[i]] == co[a[j]]:
                    result = "Not OK"
                    break
            
    b.append(result)     
    a = input().split()

for e in b:
    print(e)
# 1679264, 2022-11-12 10:01:31, PPP (100%)

#co = {'1': {'a'}, '2': {'a'}, '3': {'a'}, '4': {'b'}, '5': {'b'}, '6': {'b'}}
co = {}
for i in range(int(input())):
    e = input().strip()
    k,v = e.split()
    if k not in co:
        co[k] = {v}
    else:
        co[k].add(v)

# a = [1,2,3]       
a = input().split()
b = []
while a != ['q']:
    result = "OK"
    for i in range(len(a)):
        for j in range(i+1,len(a)):
            if a[i] not in co or a[j] not in co:
                result = "Not OK"
            else:
                if co[a[i]] == co[a[j]]:
                    result = "Not OK"
                    break
            
    b.append(result)     
    a = input().split()

for e in b:
    print(e)

6530083721
# 1678754, 2022-11-12 09:32:42, PPx (67%)

team = {}
ans = []
for i in range(int(input())):
    t,c = input().split()
    team[t] = c
g = input().split()
while g != ['q']:
    for i in range(len(g)):
        for k in range(i+1,len(g)):
            if g[k] not in team:
                found = True
                break
            if team[g[i]] == team[g[k]]:
                found = True
                break
            found = False
        if found:
            break
    ans.append(found)
    g = input().split()
for i in ans:
    if i:
        print('Not OK')
    else: print('OK')
# 1678798, 2022-11-12 09:35:15, PPx (67%)

team = {}
ans = []
for i in range(int(input())):
    t,c = input().split()
    team[t] = c
g = input().split()
while g != ['q']:
    for i in range(len(g)):
        for k in range(i+1,len(g)):
            if g[k] not in team:
                found = True
                break
            if team[g[i]].lower() == team[g[k]].lower():
                found = True
                break
            found = False
        if found:
            break
    ans.append(found)
    g = input().split()
for i in ans:
    if i: print('Not OK')
    else: print('OK')
# 1678806, 2022-11-12 09:35:59, PPx (67%)

team = {}
ans = []
for i in range(int(input())):
    t,c = input().split()
    team[t] = c
g = input().split()
while g != ['q']:
    for i in range(len(g)):
        for k in range(i+1,len(g)):
            if g[k] not in team:
                found = True
                break
            if team[g[i]] == team[g[k]]:
                found = True
                break
            found = False
        if found:
            break
    ans.append(found)
    found = False
    g = input().split()
for i in ans:
    if i: print('Not OK')
    else: print('OK')
# 1680315, 2022-11-12 10:52:10, PPx (67%)

team = {}
ans = []
for i in range(int(input())):
    t,c = input().split()
    team[t] = c
g = input().split()
while g != ['q']:
    for i in range(len(g)):
        if len(g) <= 1:
            found = True
            break
        for k in range(i+1,len(g)):
            if g[k] not in team:
                found = True
                break
            if team[g[i]] == team[g[k]]:
                found = True
                break
            found = False
        if found:
            break
    ans.append(found)
    found = False
    g = input().split()
for i in ans:
    if i: print('Not OK')
    else: print('OK')
# 1680331, 2022-11-12 10:52:38, PPx (67%)

team = {}
ans = []
for i in range(int(input())):
    t,c = input().split()
    team[t] = c
g = input().split()
while g != ['q']:
    for i in range(len(g)):
        if len(g) <= 1:
            found = False
            break
        for k in range(i+1,len(g)):
            if g[k] not in team:
                found = True
                break
            if team[g[i]] == team[g[k]]:
                found = True
                break
            found = False
        if found:
            break
    ans.append(found)
    found = False
    g = input().split()
for i in ans:
    if i: print('Not OK')
    else: print('OK')
# 1680343, 2022-11-12 10:52:53, PPx (67%)

team = {}
ans = []
for i in range(int(input())):
    t,c = input().split()
    team[t] = c
g = input().split()
while g != ['q']:
    for i in range(len(g)):
        for k in range(i+1,len(g)):
            if g[k] not in team:
                found = True
                break
            if team[g[i]] == team[g[k]]:
                found = True
                break
            found = False
        if found:
            break
    ans.append(found)
    found = False
    g = input().split()
for i in ans:
    if i: print('Not OK')
    else: print('OK')
# 1680551, 2022-11-12 11:01:09, PPP (100%)

team = {}
ans = []
for i in range(int(input())):
    t,c = input().split()
    team[t] = c
g = input().split()
while g != ['q']:
    for i in range(len(g)):
        for k in range(i+1,len(g)):
            if g[k] not in team or g[i] not in team:
                found = True
                break
            if team[g[i]] == team[g[k]]:
                found = True
                break
            found = False
        if found:
            break
    ans.append(found)
    found = False
    g = input().split()
for i in ans:
    if i: print('Not OK')
    else: print('OK')

6530153021
# 1678813, 2022-11-12 09:36:16, --- (0%)

team = {}
team1 = []
for k in range(int(input())):
    x = input().split()
    if x[1] not in team:
        team[x[1]] = []
    team[x[1]].append(x[0])
    if x[1] not in team1:
        team1.append(x[1])

while True :
    y = input().split()
    if len(y) == 1 : break
    coun = []
    
    for i in range(len(y)):
        for j in range(len(team1)):
            if y[i] in team[team1[j]]:
                coun.append(team1[j])
                
    print(coun)
    print(set(coun))
    
    if len(set(coun)) == len(coun):
        print('OK')
    
    else :
        print('Not OK')
        


# 1678839, 2022-11-12 09:37:25, PP- (67%)

team = {}
team1 = []
for k in range(int(input())):
    x = input().split()
    if x[1] not in team:
        team[x[1]] = []
    team[x[1]].append(x[0])
    if x[1] not in team1:
        team1.append(x[1])

while True :
    y = input().split()
    if len(y) == 1 : break
    coun = []
    
    for i in range(len(y)):
        for j in range(len(team1)):
            if y[i] in team[team1[j]]:
                coun.append(team1[j])
                
    
    
    if len(set(coun)) == len(coun):
        print('OK')
    
    else :
        print('Not OK')
# 1679062, 2022-11-12 09:50:07, xx- (0%)

team = {}
team1 = []
team2 = []
for k in range(int(input())):
    x = input().split()
    if x[1] not in team:
        team[x[1]] = []
    team[x[1]].append(x[0])
    if x[1] not in team1:
        team1.append(x[1])
    team2.append(x[0])
print(team2)
while True :
    y = input().split()
    if len(y) == 1 : break
    coun = []
    
    for i in range(len(y)):
        for j in range(len(team1)):
            if y[i] in team[team1[j]]:
                coun.append(team1[j])
                
    
    
    if len(set(coun)) == len(coun):
        print('OK')
    elif coun[2] not in team2:
        print('Not OK')
    else :
        print('Not OK')
        


# 1679067, 2022-11-12 09:50:28, --- (0%)

team = {}
team1 = []
team2 = []
for k in range(int(input())):
    x = input().split()
    if x[1] not in team:
        team[x[1]] = []
    team[x[1]].append(x[0])
    if x[1] not in team1:
        team1.append(x[1])
    team2.append(x[0])
print(team2)
while True :
    y = input().split()
    if len(y) == 1 : break
    coun = []
    
    for i in range(len(y)):
        for j in range(len(team1)):
            if y[i] in team[team1[j]]:
                coun.append(team1[j])
                
    
    
    if len(set(coun)) == len(coun):
        print('OK')
    
    else :
        print('Not OK')
        


# 1679073, 2022-11-12 09:50:56, xx- (0%)

team = {}
team1 = []
team2 = []
for k in range(int(input())):
    x = input().split()
    if x[1] not in team:
        team[x[1]] = []
    team[x[1]].append(x[0])
    if x[1] not in team1:
        team1.append(x[1])
    team2.append(x[0])

while True :
    y = input().split()
    if len(y) == 1 : break
    coun = []
    
    for i in range(len(y)):
        for j in range(len(team1)):
            if y[i] in team[team1[j]]:
                coun.append(team1[j])
                
    
    
    if len(set(coun)) == len(coun):
        print('OK')
    elif coun[2] not in team2:
        print('Not OK')
    else :
        print('Not OK')
        


# 1679075, 2022-11-12 09:51:14, PP- (67%)

team = {}
team1 = []
team2 = []
for k in range(int(input())):
    x = input().split()
    if x[1] not in team:
        team[x[1]] = []
    team[x[1]].append(x[0])
    if x[1] not in team1:
        team1.append(x[1])
    team2.append(x[0])

while True :
    y = input().split()
    if len(y) == 1 : break
    coun = []
    
    for i in range(len(y)):
        for j in range(len(team1)):
            if y[i] in team[team1[j]]:
                coun.append(team1[j])
                
    
    
    if len(set(coun)) == len(coun):
        print('OK')
    
    else :
        print('Not OK')
        


# 1679140, 2022-11-12 09:54:25, PPP (100%)

team = {}
team1 = []
team2 = []
for k in range(int(input())):
    x = input().split()
    if x[1] not in team:
        team[x[1]] = []
    team[x[1]].append(x[0])
    if x[1] not in team1:
        team1.append(x[1])
    team2.append(x[0])

while True :
    y = input().split()
    if len(y) == 1 : break
    coun = []
    
    for i in range(len(y)):
        for j in range(len(team1)):
            if y[i] in team[team1[j]]:
                coun.append(team1[j])
    ans = []    
    for e in y:
        if e not in team2:
            ans.append('Not OK')
    if len(set(coun)) == len(coun):
        ans.append('OK')
    
    else :
        ans.append('Not OK')
    print(ans[0])
        



6531348221
# 1678628, 2022-11-12 09:26:25, --x (0%)

team_name = {}
name_con = {}
check = []
for i in range(int(input())):
    team = input().strip().split()
    name, con = team[:]
    if con not in team_name:
        team_name[con] = []
    team_name[con].append(name)
    if name not in name_con:
        name_con[name] = ""
    name_con[name] = con
print(team_name)
print(name_con)
while True:
    data = input().strip().split()
    if data[0] == "q":
        break
    else:
        for name in data:
            condi = True
            if name_con[name] in check:
                condi = False
                break
            else:
                check.append(name_con[name])
            if name not in name_con.keys():
                condi = False
                break
        if condi == True:
            print("OK")
        else:
            print("Not OK")
# 1678744, 2022-11-12 09:32:14, --- (0%)

team_name = {}
name_con = {}
check = []
for i in range(int(input())):
    team = input().strip().split()
    name, con = team[:]
    if con not in team_name:
        team_name[con] = []
    team_name[con].append(name)
    if name not in name_con:
        name_con[name] = ""
    name_con[name] = con
while True:
    data = input().strip().split()
    if data[0] == "q":
        break
    else:
        for name in data:
            condi = True
            if name not in name_con.keys():
                condi = False
                break
            else:
                if name_con[name] in check:
                    condi = False
                else:
                    check.append(name_con[name])
        if condi == True:
            print("OK")
        else:
            print("Not OK")
# 1678789, 2022-11-12 09:34:55, --- (0%)

team_name = {}
name_con = {}
check = []
ans = []
for i in range(int(input())):
    team = input().strip().split()
    name, con = team[:]
    if con not in team_name:
        team_name[con] = []
    team_name[con].append(name)
    if name not in name_con:
        name_con[name] = ""
    name_con[name] = con
while True:
    data = input().strip().split()
    if data[0] == "q":
        break
    else:
        for name in data:
            condi = True
            if name not in name_con.keys():
                condi = False
                break
            else:
                if name_con[name] in check:
                    condi = False
                else:
                    check.append(name_con[name])
        # if condi == True:
        #     print("OK")
        # else:
        #     print("Not OK")
        if condi == True:
            ans.append("OK")
        else:
            ans.append("Not OK")
for a in ans:
    print(a)
# 1678824, 2022-11-12 09:36:44, --- (0%)

team_name = {}
name_con = {}
check = []
ans = []
for i in range(int(input())):
    team = input().strip().split()
    name, con = team[:]
    if con not in team_name:
        team_name[con] = []
    team_name[con].append(name)
    if name not in name_con:
        name_con[name] = ""
    name_con[name] = con
while True:
    data = input().strip().split()
    if data[0] == "q":
        break
    else:
        for name in data:
            condi = True
            if name not in name_con.keys():
                condi = False
                break
            else:
                if name_con[name] in check:
                    condi = False
                else:
                    check.append(name_con[name])
        if condi == True:
            print("OK")
        else:
            print("Not OK")
# 1678921, 2022-11-12 09:42:25, PP- (67%)

team_name = {}
name_con = {}
check = []
ans = []
for i in range(int(input())):
    team = input().strip().split()
    name, con = team[:]
    if con not in team_name:
        team_name[con] = []
    team_name[con].append(name)
    if name not in name_con:
        name_con[name] = ""
    name_con[name] = con
while True:
    data = input().strip().split()
    check = []
    if data[0] == "q":
        break
    else:
        for name in data:
            condi = True
            if name not in name_con.keys():
                condi = False
                break
            else:
                if name_con[name] in check:
                    condi = False
                else:
                    check.append(name_con[name])
        if condi == True:
            print("OK")
        else:
            print("Not OK")
# 1678928, 2022-11-12 09:42:56, PPP (100%)

team_name = {}
name_con = {}
check = []
ans = []
for i in range(int(input())):
    team = input().strip().split()
    name, con = team[:]
    if con not in team_name:
        team_name[con] = []
    team_name[con].append(name)
    if name not in name_con:
        name_con[name] = ""
    name_con[name] = con
while True:
    data = input().strip().split()
    check = []
    if data[0] == "q":
        break
    else:
        for name in data:
            condi = True
            if name not in name_con.keys():
                condi = False
                break
            else:
                if name_con[name] in check:
                    condi = False
                    break
                else:
                    check.append(name_con[name])
        if condi == True:
            print("OK")
        else:
            print("Not OK")
# 1678931, 2022-11-12 09:43:14, PPP (100%)

team_name = {}
name_con = {}
check = []
ans = []
for i in range(int(input())):
    team = input().strip().split()
    name, con = team[:]
    if con not in team_name:
        team_name[con] = []
    team_name[con].append(name)
    if name not in name_con:
        name_con[name] = ""
    name_con[name] = con
while True:
    data = input().strip().split()
    check = []
    if data[0] == "q":
        break
    else:
        for name in data:
            condi = True
            if name not in name_con.keys():
                condi = False
                break
            else:
                if name_con[name] in check:
                    condi = False
                    break
                else:
                    check.append(name_con[name])
        if condi == True:
            print("OK")
        else:
            print("Not OK")

6531501921
# 1679383, 2022-11-12 10:07:42, -xx (0%)

nationTeam = dict()
for i in range(int(input())):
    t,n = [e.split() for e in input().split()]
    nationTeam[t[0]] = n[0]
    #print(nationTeam)
while True :
    G = []
    nationSet = set() 
    x =input().split()
    G += x
    for i in G :
        print(i)
        nationSet.update([nationTeam[i]])
        if len(nationSet) == len(G):
            print('OK')
        else :
            print('Not OK')
    if input() == 'q':
        break
# 1679405, 2022-11-12 10:08:56, -xx (0%)

nationTeam = dict()
for i in range(int(input())):
    t,n = [e.split() for e in input().split()]
    nationTeam[t[0]] = n[0]
    #print(nationTeam)
while True :
    G = []
    nationSet = set() 
    x =input().split()
    G += x
    for i in G :
        #print(i)
        nationSet.update([nationTeam[i]])
    if len(nationSet) == len(G):
        print('OK')
    else :
        print('Not OK')
    if input() == 'q':
        break
# 1679481, 2022-11-12 10:12:47, -xx (0%)

nationTeam = dict()
for i in range(int(input())):
    t,n = [e.split() for e in input().split()]
    nationTeam[t[0]] = n[0]
    #print(nationTeam)
while True :
    G = []
    nationSet = set() 
    x =input().split()
    G += x
    for i in G :
        #print(i)
        if i in nationTeam :
            nationSet.update([nationTeam[i]])
        else :
            print('Not OK')
            G = []
            nationSet = set()
    if len(nationSet) == len(G):
        print('OK')
        G = []
        nationSet = set()
    else :
        print('Not OK')
        G = []
        nationSet = set()
    if input() == 'q':
        break
# 1679734, 2022-11-12 10:24:58, xxx (0%)

nationTeam = dict()
for i in range(int(input())):
    t,n = [e.split() for e in input().split()]
    nationTeam[t[0]] = n[0]
    #print(nationTeam)
while 1 :
    G = []
    nationSet = set() 
    x =input().split()
    G += x
    for i in G :
        #print(i)
        if i in nationTeam :
            nationSet.update([nationTeam[i]])
        else :
            print('Not OK')
            continue
    if len(nationSet) == len(G):
        print('OK')
        continue
    else :
        print('Not OK')
        continue
    if input() == 'q':
        break
    
# 1679762, 2022-11-12 10:26:31, xxx (0%)

nationTeam = dict()
for i in range(int(input())):
    t,n = [e.split() for e in input().split()]
    nationTeam[t[0]] = n[0]
    #print(nationTeam)
while True :
    G = []
    nationSet = set() 
    x =input().split()
    G += x
    for i in G :
        #print(i)
        if i in nationTeam :
            nationSet.update([nationTeam[i]])
        else :
            print('Not OK')
            G = []
            nationSet = set()
            continue
    if len(nationSet) == len(G):
        print('OK')
        G = []
        nationSet = set()
        continue
    else :
        print('Not OK')
        G = []
        nationSet = set()
        continue
    if input() == 'q':
        break
# 1679767, 2022-11-12 10:26:50, xxx (0%)

nationTeam = dict()
for i in range(int(input())):
    t,n = [e.split() for e in input().split()]
    nationTeam[t[0]] = n[0]
    #print(nationTeam)
while True :
    G = []
    nationSet = set() 
    x =input().split()
    G += x
    for i in G :
        #print(i)
        if i in nationTeam :
            nationSet.update([nationTeam[i]])
        else :
            print('Not OK')
            G = []
            nationSet = set()
            continue
    if len(nationSet) == len(G):
        print('OK')
        G = []
        nationSet = set()
        continue
    else :
        print('Not OK')
        G = []
        nationSet = set()
        continue
# 1680167, 2022-11-12 10:44:41, PPP (100%)

nationTeam = dict()
for i in range(int(input())):
    t,n = [e.split() for e in input().split()]
    nationTeam[t[0]] = n[0]
    #print(nationTeam)
while True :
    G = []
    nationSet = set() 
    x =input().split()
    G += x
    for i in G :
        #print(i)
        if i in nationTeam :
            nationSet.update([nationTeam[i]])
        elif i not in nationTeam and not 'q':
            print('Not OK')
        if x == ['q']:
            break
    if len(nationSet) == len(G):
        if x != ['q']:
            print('OK')
        if x == ['q']:
            break
    if len(nationSet) != len(G):
        if x == ['q']:
            break
        else:
            print('Not OK')

6531803421
# 1678945, 2022-11-12 09:43:50, --x (0%)

s = {}
d = []
for i in range (int(input())) :
    T,C = input().strip().split()
    s[T] = C
while True :
    g = input().strip().split()
    if g == ['q'] : break
    else :
        d.append(g)
x = [e for e in s.values()] 
for i in range (len(d)) :
    for e in range (len(d[i])) :
        if s[d[i][e]] == "" :
            print ('not OK')
            break
    for k in range (len(d[i])-1) :
        if s[d[i][k]] == s[d[i][k+1]] :
            print ('not OK')
            break
    print('OK')
# 1679622, 2022-11-12 10:20:47, x-x (0%)

s = {}
d = []
for i in range (int(input())) :
    T,C = input().strip().split()
    s[T] = C
while True :
    g = input().strip().split()
    if g == ['q'] : break
    else :
        d.append(g)
x = [e for e in s.values()]
y = [e for e in s.keys()]
for i in range (len(d)) : 
    for k in range (len(d)-1) :
        if d[i][k] not in y :
            print('Not OK')
            break
        elif s[d[i][k]] == s[d[i][k+1]] :
            print('Not OK')
            break
    print('OK')
# 1679781, 2022-11-12 10:27:31, --- (0%)

s = {}
d = []
for i in range (int(input())) :
    T,C = input().strip().split()
    s[T] = C
while True :
    g = input().strip().split()
    if g == ['q'] : break
    else :
        d.append(g)
x = [e for e in s.values()]
y = [e for e in s.keys()]
for i in range (len(d)) : 
    for k in range (len(d)-1) :
        if d[i][k] not in y :
            print('Not OK')
            break
        break
        if s[d[i][k]] == s[d[i][k+1]] :
            print('Not OK')
            break
    print('OK')
# 1679963, 2022-11-12 10:35:20, xPx (33%)

s = {}
d = []
for i in range (int(input())) :
    T,C = input().strip().split()
    s[T] = C
while True :
    g = input().strip().split()
    if g == ['q'] : break
    else :
        d.append(g)
x = {e for e in s.values()}
y = {e for e in s.keys()}
for i in range (len(d)) : 
    for k in range (len(d)-1) :
        p = True
        if d[i][k] in y and d[i][k+1] in y :                 
            if s[d[i][k]] == s[d[i][k+1]] :
                p = False
                break
        else :
            p = False
            break
    if p :
        print('OK')
    else : print('Not OK')
# 1681100, 2022-11-12 11:18:55, PP- (67%)

s = {}
d = []
a = []
p = True
for i in range (int(input())) :
    T,C = input().strip().split()
    s[T] = C
while True :
    g = input().strip().split()
    if g == ['q'] : break
    else :
        d.append(g)
x = {e for e in s.values()}
z = [i for i in x]
y = {e for e in s.keys()}
for k in d :  
    for i in k :
        if i not in y :
            p = False
            break
    if p :
        for o in range (len(k)) :
            a.append(s[k[o]])
        for i in x :
            if i in a :
                a.remove(i)
        if a != [] :
            p = False
            
           
    if p :
        print('OK')
    else : print('Not OK')
    a = []
# 1681233, 2022-11-12 11:22:11, PP- (67%)

s = {}
d = []
a = []
p = True
for i in range (int(input())) :
    T,C = input().strip().split()
    s[T] = C
while True :
    g = input().strip().split()
    if g == ['q'] : break
    else :
        d.append(g)
x = {e for e in s.values()}
z = [i for i in x]
y = {e for e in s.keys()}
for k in d :  
    for i in k :
        if i not in y :
            p = False
            break
    if p :
        for o in range (len(k)) :
            a.append(s[k[o]])
        for i in x :
            if i in a :
                a.remove(i)
        if a != [] :
            p = False
            
           
    if p :
        print('OK')
    else : print('Not OK')
    a = []
    P = True
# 1681299, 2022-11-12 11:23:55, PPP (100%)

s = {}
d = []
a = []
p = True
for i in range (int(input())) :
    T,C = input().strip().split()
    s[T] = C
while True :
    g = input().strip().split()
    if g == ['q'] : break
    else :
        d.append(g)
x = {e for e in s.values()}
z = [i for i in x]
y = {e for e in s.keys()}
for k in d :  
    for i in k :
        if i not in y :
            p = False
            break
    if p :
        for o in range (len(k)) :
            a.append(s[k[o]])
        for i in x :
            if i in a :
                a.remove(i)
        if a != [] :
            p = False
            
           
    if p :
        print('OK')
    else : print('Not OK')
    a = []
    p = True

6231404421
# 1681213, 2022-11-12 11:21:32, --- (0%)

team = {}
county = {}
tc = []
tt = []
for i in range(int(input())) :
    t,c = input().split()
    team[t] = c
    tt.append(t)
    if c not in county :
        county[c] = []
        tc.append(c)
    county[c].append(t)
    
group = []
while True :
    g =  [e for e in input().split()]
    if g[0] == 'q' and len(g) == 1 :
        break
    group.append(g)
for i in range(len(group)):
    tct =[]
    for e in range(len(group[i])):
        if group[i][e] not in tt :
            print('Not OK')
            break
        else :
            group[i][e] = team[group[i][e]]
            if group[i][e] not in tct :
                tct.append( group[i][e] )
            else :
                print('Not OK')
                break
    print('OK')
# 1681507, 2022-11-12 11:27:59, PPP (100%)

team = {}
county = {}
tc = []
tt = []
for i in range(int(input())) :
    t,c = input().split()
    team[t] = c
    tt.append(t)
    if c not in county :
        county[c] = []
        tc.append(c)
    county[c].append(t)
    
group = []
while True :
    g =  [e for e in input().split()]
    if g[0] == 'q' and len(g) == 1 :
        break
    group.append(g)
for i in range(len(group)):
    a = 0
    tct =[]
    for e in range(len(group[i])):
        if group[i][e] not in tt :
            a += 1
            break
        
        else :
            group[i][e] = team[group[i][e]]
            if group[i][e] not in tct :
                tct.append( group[i][e] )
            else :
                a += 1
                break
    if a == 1 :
        print('Not OK')
    else :
        print('OK')
# 1681524, 2022-11-12 11:28:17, PPP (100%)

team = {}
county = {}
tc = []
tt = []
for i in range(int(input())) :
    t,c = input().split()
    team[t] = c
    tt.append(t)
    if c not in county :
        county[c] = []
        tc.append(c)
    county[c].append(t)
    
group = []
while True :
    g =  [e for e in input().split()]
    if g[0] == 'q' and len(g) == 1 :
        break
    group.append(g)
for i in range(len(group)):
    a = 0
    tct =[]
    for e in range(len(group[i])):
        if group[i][e] not in tt :
            a += 1
            break
        
        else :
            group[i][e] = team[group[i][e]]
            if group[i][e] not in tct :
                tct.append( group[i][e] )
            else :
                a += 1
                break
    if a == 1 :
        print('Not OK')
    else :
        print('OK')
# 1681536, 2022-11-12 11:28:31, PPP (100%)

team = {}
county = {}
tc = []
tt = []
for i in range(int(input())) :
    t,c = input().split()
    team[t] = c
    tt.append(t)
    if c not in county :
        county[c] = []
        tc.append(c)
    county[c].append(t)
    
group = []
while True :
    g =  [e for e in input().split()]
    if g[0] == 'q' and len(g) == 1 :
        break
    group.append(g)
for i in range(len(group)):
    a = 0
    tct =[]
    for e in range(len(group[i])):
        if group[i][e] not in tt :
            a += 1
            break
        
        else :
            group[i][e] = team[group[i][e]]
            if group[i][e] not in tct :
                tct.append( group[i][e] )
            else :
                a += 1
                break
    if a == 1 :
        print('Not OK')
    else :
        print('OK')
# 1681556, 2022-11-12 11:28:52, PPP (100%)

team = {}
county = {}
tc = []
tt = []
for i in range(int(input())) :
    t,c = input().split()
    team[t] = c
    tt.append(t)
    if c not in county :
        county[c] = []
        tc.append(c)
    county[c].append(t)
    
group = []
while True :
    g =  [e for e in input().split()]
    if g[0] == 'q' and len(g) == 1 :
        break
    group.append(g)
for i in range(len(group)):
    a = 0
    tct =[]
    for e in range(len(group[i])):
        if group[i][e] not in tt :
            a += 1
            break
        
        else :
            group[i][e] = team[group[i][e]]
            if group[i][e] not in tct :
                tct.append( group[i][e] )
            else :
                a += 1
                break
    if a == 1 :
        print('Not OK')
    else :
        print('OK')
# 1681625, 2022-11-12 11:29:43, PPP (100%)

team = {}
county = {}
tc = []
tt = []
for i in range(int(input())) :
    t,c = input().split()
    team[t] = c
    tt.append(t)
    if c not in county :
        county[c] = []
        tc.append(c)
    county[c].append(t)
    
group = []
while True :
    g =  [e for e in input().split()]
    if g[0] == 'q' and len(g) == 1 :
        break
    group.append(g)
for i in range(len(group)):
    a = 0
    tct =[]
    for e in range(len(group[i])):
        if group[i][e] not in tt :
            a += 1
            break
        
        else :
            group[i][e] = team[group[i][e]]
            if group[i][e] not in tct :
                tct.append( group[i][e] )
            else :
                a += 1
                break
    if a == 1 :
        print('Not OK')
    else :
        print('OK')

6530002921
# 1679631, 2022-11-12 10:21:15, xxx (0%)

n = int(input())
d = {}
for i in range(n):
    t,c = input().split()
    if c not in d:
        d[c] = [t]
    else:
        d[c] += [t]

y=True
x = input().split()
while x != "q" :
    for j in d:
        t=0
        for k in range(len(x)):
             if x[k] in d[j] :
                t+=1
        if t==1 or t==0:
            y=True
        else:
            y=False
    x = input().split()

if y==True:
    print("OK")
else:
    print("Not OK")


# 1679720, 2022-11-12 10:24:22, --- (0%)

n = int(input())
d = {}
for i in range(n):
    t,c = input().split()
    if c not in d:
        d[c] = [t]
    else:
        d[c] += [t]

y=True
x = input().split()
while x[0] != 'q' :
    for j in d:
        t=0
        for k in range(len(x)):
             if x[k] in d[j] :
                t+=1
        if t==1 or t==0:
            y=True
        else:
            y=False
    x = input().split()

if y==True:
    print("OK")
else:
    print("Not OK")


# 1679746, 2022-11-12 10:25:31, --- (0%)

n = int(input())
d = {}
for i in range(n):
    t,c = input().split()
    if c not in d:
        d[c] = [t]
    else:
        d[c] += [t]

y=True
x = input().split()
while x[0] != 'q' :
    for j in d:
        t=0
        for k in range(len(x)):
             if x[k] in d[j] :
                t+=1
        if t==1 or t==0:
            y=True
        else:
            y=False
    if y==True:
        print("OK")
    else:
        print("Not OK")
    x = input().split()
# 1679836, 2022-11-12 10:29:49, PP- (67%)

n = int(input())
d = {}
for i in range(n):
    t,c = input().split()
    if c not in d:
        d[c] = [t]
    else:
        d[c] += [t]


x = input().split()
while x[0] != 'q' :
    y=True
    for j in d:
        t=0
        for k in range(len(x)):
             if x[k] in d[j] :
                t+=1
        if t==1 or t==0:
            y=True
        else:
            y=False
            break
    if y==True:
        print("OK")
    else:
        print("Not OK")
    x = input().split()






# 1680145, 2022-11-12 10:43:28, xxx (0%)

nn = int(input())
d = {}
t1=[]
for i in range(n):
    t,c = input().split()
    t1.append(t)
    if c not in d:
        d[c] = [t]
    else:
        d[c] += [t]


x = input().split()
while x[0] != 'q' :
    y=True
    for j in d:
        s=0
        for k in range(len(x)):
            if x[k] not in t1:
                y=False
                s=2
                break
            elif x[k] in d[j] :
                s+=1
        if s==1 or s==0:
            y=True
        else:
            y=False
            break
    if y==True:
        print("OK")
    else:
        print("Not OK")
    x = input().split()




# 1680159, 2022-11-12 10:44:23, PPP (100%)

n = int(input())
d = {}
t1=[]
for i in range(n):
    t,c = input().split()
    t1.append(t)
    if c not in d:
        d[c] = [t]
    else:
        d[c] += [t]


x = input().split()
while x[0] != 'q' :
    y=True
    for j in d:
        s=0
        for k in range(len(x)):
            if x[k] not in t1:
                y=False
                s=2
                break
            elif x[k] in d[j] :
                s+=1
        if s==1 or s==0:
            y=True
        else:
            y=False
            break
    if y==True:
        print("OK")
    else:
        print("Not OK")
    x = input().split()





6530009321
# 1679332, 2022-11-12 10:04:46, xxx (0%)

country1 = []
united = {}
for i in range(int(input())):
    name,country = input().split()
    united[name] = country
    country1.append(country)
    country2 = set(country1)
print(united)
print(country2)
y = input().split()
while y != 'q':
    united2 = {}
    country3 = []
    for e in y:
        if e in united:
            united2[e] = united[e]
            country3.append(united2[e])
            country4 = set(country3)
            if len(country4) < len(country3):
                print('Not OK')
                break
            elif united2[e] not in country2:
                print('Not OK')
                break
            else:
                print('OK')
                break
    y = input().split()
    if y == 'q':
        break
    
# 1679348, 2022-11-12 10:05:47, xxx (0%)

country1 = []
united = {}
for i in range(int(input())):
    name,country = input().split()
    united[name] = country
    country1.append(country)
    country2 = set(country1)
y = input().split()
while y != 'q':
    united2 = {}
    country3 = []
    for e in y:
        if e in united:
            united2[e] = united[e]
            country3.append(united2[e])
            country4 = set(country3)
            if len(country4) < len(country3):
                print('Not OK')
                break
            elif united2[e] not in country2:
                print('Not OK')
                break
            else:
                print('OK')
                break
    y = input().split()
    if y == 'q':
        break
# 1679393, 2022-11-12 10:08:15, xxx (0%)

country1 = []
united = {}
for i in range(int(input())):
    name,country = input().split()
    united[name] = country
    country1.append(country)
    country2 = set(country1)
y = input().split()
while y != 'q':
    united2 = {}
    country3 = []
    for e in y:
        if e in united:
            united2[e] = united[e]
            country3.append(united2[e])
            country4 = set(country3)
            if len(country4) < len(country3):
                print('Not OK')
                break
            elif united2[e] not in country2:
                print('Not OK')
                break
            else:
                print('OK')
                break
    y = input().split()
    if y == 'q':
        break
# 1679450, 2022-11-12 10:11:24, xxx (0%)

country1 = []
united = {}
for i in range(int(input())):
    name,country = input().split()
    united[name] = country
    country1.append(country)
    country2 = set(country1)
y = input().split()
while y != 'q':
    united2 = {}
    country3 = []
    for e in y:
        if e in united:
            united2[e] = united[e]
            country3.append(united2[e])
            country4 = set(country3)
            if len(country4) < len(country3):
                print('Not OK')
                
            elif united2[e] not in country2:
                print('Not OK')
                
            else:
                print('OK')
                
    y = input().split()
    if y == 'q':
        break
# 1679791, 2022-11-12 10:28:03, PPP (100%)

country1 = []
united = {}
for i in range(int(input())):
    name,country = input().split()
    united[name] = country
    country1.append(country)
    country2 = set(country1)
y = input().split()
while y != 'q':
    united2 = {}
    country3 = []
    for e in y:
        if e in united:
            united2[e] = united[e]
            country3.append(united2[e])
            country4 = set(country3)
    if len(country4) < len(y):
        print('Not OK')
    else:
        print('OK')
    y = input()
    if y == 'q':
        break
    else:
        y = y.split()
# 1679798, 2022-11-12 10:28:22, PPP (100%)

country1 = []
united = {}
for i in range(int(input())):
    name,country = input().split()
    united[name] = country
    country1.append(country)
    country2 = set(country1)
y = input().split()
while y != 'q':
    united2 = {}
    country3 = []
    for e in y:
        if e in united:
            united2[e] = united[e]
            country3.append(united2[e])
            country4 = set(country3)
    if len(country4) < len(y):
        print('Not OK')
    else:
        print('OK')
    y = input()
    if y == 'q':
        break
    else:
        y = y.split()

6531507721
# 1678860, 2022-11-12 09:38:30, TTT (0%)

n = int(input())
result = {}

for i in range(n):
    x = input().split()
    result[x[0]] = x[1]
    

find = input().split()

while find[0] != "q" :
    check = []
    for i in find :
        if result[i] not in check :
            ans = True
        else:
            ans = False
            
    if ans : print("OK")
    else: print("Not OK")
# 1679072, 2022-11-12 09:50:54, --x (0%)

n = int(input())
result = {}

for i in range(n):
    x = input().split()
    result[x[0]] = x[1]
    

find = input().split()

while find[0] != "q" :
    check = []
    for i in find :
        if result[i] not in check :
            ans = True
        else:
            ans = False
            
    if ans :
        print("OK")
    else:
        print("Not OK")
        
    find = input().split()

# 1679391, 2022-11-12 10:08:10, PPx (67%)

n = int(input())
result = {}

for i in range(n):
    x = input().split()
    result[x[0]] = x[1]
    

find = input().split()
final = []

while find[0] != "q" :
    check = []
    for i in find :
        if result[i] not in check and i in result :
            check.append(result[i])
            ans = True
        else:
            ans = False
            break
            
    if ans :
        final.append("OK")
    else:
        final.append("Not OK")
        
    find = input().split()
    
for i in final:
    print(i)
# 1679438, 2022-11-12 10:10:58, --- (0%)

n = int(input())
result = {}

for i in range(n):
    x = input().split()
    result[x[0]] = x[1]
    

find = input().split()
final = []

while find[0] != "q" :
    check = []
    for i in find :
        if i in result:
            if result[i] not in check and i in result :
                check.append(result[i])
                ans = True
        else:
            ans = False
            break
            
    if ans :
        final.append("OK")
    else:
        final.append("Not OK")
        
    find = input().split()
    
for i in final:
    print(i)

# 1679474, 2022-11-12 10:12:34, --- (0%)

n = int(input())
result = {}

for i in range(n):
    x = input().split()
    result[x[0]] = x[1]
    

find = input().split()
final = []

while find[0] != "q" :
    check = []
    for i in find :
        if i in result:
            if result[i] not in check :
                check.append(result[i])
                ans = True
        else:
            ans = False
            break
            
    if ans :
        final.append("OK")
    else:
        final.append("Not OK")
        
    find = input().split()
    
for i in final:
    print(i)
# 1679563, 2022-11-12 10:17:09, PPP (100%)

n = int(input())
result = {}

for i in range(n):
    x = input().split()
    result[x[0]] = x[1]
    

find = input().split()
final = []

while find[0] != "q" :
    check = []
    for i in find :
        if i in result:
            if result[i] not in check :
                check.append(result[i])
                ans = True
            else :
                ans = False
                break
        else:
            ans = False
            break
            
    if ans :
        final.append("OK")
    else:
        final.append("Not OK")
        
    find = input().split()
    
for i in final:
    print(i)

6531513421
# 1679188, 2022-11-12 09:57:02, --x (0%)

team1 = {}
for i in range(int(input())):
    team,coun = input().split()
    team1[team] = coun

name = input().split()
while name != ['q']:
    for e in range(len(name)):
        for i in team1[name[e]] :
            country = []
            if i not in country :
                country.append(i)
    if len(country) == len(name) :
        print('OK')
    else:
        print('Not OK')
    name = input().split()
# 1679469, 2022-11-12 10:12:18, PPx (67%)

team1 = {}
counn = {}
for i in range(int(input())):
    team,coun = input().split()
    team1[team] = coun
    counn[coun] = team

def find_country(team):
    a = team1[team]
    return a

name = input().split()
while name != ['q'] :
    b = []
    found = 0
    for i in name :
        d = find_country(i)
        if (d in counn) and (d not in b) :
            b.append(d)
        elif (d not in counn) or (d in b):
            found += 1
    if found == 0 :
        print('OK')
    else :
        print('Not OK')
    name = input().split()
# 1679828, 2022-11-12 10:29:29, TTT (0%)

team1 = {}
counn = {}
for i in range(int(input())):
    team,coun = input().split()
    team1[team] = coun
    counn[coun] = team

def find_country(team):
    a = team1[team]
    return a

name = input().split()
while name != ['q']:
    for e in name :
        if e not in team1 :
            print('Not OK')
            name = ['q']
            break
    while name != ['q']:
        b = []
        found = 0
        for i in name :
            if i in team1:
                d = find_country(i)
                if (d in counn) and (d not in b) :
                    b.append(d)
                elif (d not in counn) or (d in b):
                    found += 1
        if found == 0 :
            print('OK')
        else :
            print('Not OK')
    name = input().split()
# 1679879, 2022-11-12 10:31:14, PP- (67%)

team1 = {}
counn = {}
for i in range(int(input())):
    team,coun = input().split()
    team1[team] = coun
    counn[coun] = team

def find_country(team):
    a = team1[team]
    return a

name = input().split()
while name != ['q'] :
    b = []
    found = 0
    for i in name :
        if i in team1:
            d = find_country(i)
            if (d in counn) and (d not in b) :
                b.append(d)
            elif (d not in counn) or (d in b):
                found += 1
        else :
            print('Not OK')
    if found == 0 :
        print('OK')
    else :
        print('Not OK')
    name = input().split()
# 1679916, 2022-11-12 10:32:26, PP- (67%)

team1 = {}
counn = {}
for i in range(int(input())):
    team,coun = input().split()
    team1[team] = coun
    counn[coun] = team

def find_country(team):
    a = team1[team]
    return a

name = input().split()
while name != ['q'] :
    b = []
    found = 0
    for i in name :
        if i in team1:
            d = find_country(i)
            if (d in counn) and (d not in b) :
                b.append(d)
            elif (d not in counn) or (d in b) or (i not in team1) :
                found += 1
        else :
            print('Not OK')
    if found == 0 :
        print('OK')
    else :
        print('Not OK')
    name = input().split()
# 1679962, 2022-11-12 10:35:18, PPP (100%)

team1 = {}
counn = {}
for i in range(int(input())):
    team,coun = input().split()
    team1[team] = coun
    counn[coun] = team

def find_country(team):
    if team in team1:
        a = team1[team]
    else :
        a = 'haha'
    return a

name = input().split()
while name != ['q'] :
    b = []
    found = 0
    for i in name :
        d = find_country(i)
        if (d in counn) and (d not in b) :
            b.append(d)
        elif (d not in counn) or (d in b) or (i== 'haha'):
            found += 1
    if found == 0 :
        print('OK')
    else :
        print('Not OK')
    name = input().split()

6531525021
# 1679101, 2022-11-12 09:52:48, xxx (0%)

n =int(input())
d = {}
for i in range(n) :
    x,y = input().split()
    if y not in d :
        d[x]= [y]
    else :
        d[x].append(y)
n1 = input()
sa = []
while n1 != 'q' :
    xx= input().split()
    sa.append(xx)
    
    n1 = input()
#e=[t,y,u,i]

for e in sa:
    f = True
    for t in e :
        if t not in d :
            f = False
        else :
            if d[t] not in m :
                f = True
            else :
                f = False
    if f :
        print("OK")
    print('Not OK')
            
    
# 1679148, 2022-11-12 09:55:01, x-- (0%)

n =int(input())
d = {}
for i in range(n) :
    x,y = input().split()
    if y not in d :
        d[x]= [y]
    else :
        d[x].append(y)
n1 = input()
sa = []
while n1 != 'q' :
    xx= input().split()
    sa.append(xx)
    
    n1 = input()
#e=[t,y,u,i]
m = []
for e in sa:
    f = True
    for t in e :
        if t not in d :
            f = False
        else :
            if d[t] not in m :
                f = True
            else :
                f = False
    if f :
        print("OK")
    print('Not OK')
            
    
# 1679659, 2022-11-12 10:22:22, xxx (0%)

while n1 != 'q' :
    xx = n1.strip().split()
    sa.append(xx)
    n1 = input()
#e=[t,y,u,i]
f = True
for e in sa:
    m = []
    for t in e :
        if t not in d :
            f = False
        else :
            if d[t] not in m :
                m.append(d[t])
            else :
              f = False
    if f :
        print("OK")
        m = []
    else:
      print('Not OK')
      m = []

# 1679759, 2022-11-12 10:26:20, xxx (0%)

while n1 != 'q' :
    xx = n1.strip().split()
    sa.append(xx)
    n1 = input()
#e=[t,y,u,i]
f = True
for e in sa:
    m = []
    for t in e :
        if t not in d :
            f = False
        else :
            if d[t] not in m :
                m.append(d[t])
            else :
              f = False
    
    if len(m) == len(e):
       print("OK")
       m = []
    else:
     print('Not OK')
     m = []

# 1679780, 2022-11-12 10:27:30, xxx (0%)

while n1 != 'q' :
    xx = n1.strip().split()
    sa.append(xx)
    n1 = input()
#e=[t,y,u,i]
f = True
for e in sa:
    m = []
    for t in e :
        if t not in d :
            f = False
        else :
            if d[t] not in m :
                m.append(d[t])
            else :
              f = False
    
    if len(m) == len(e):
       print("OK")
       
    else:
      print('Not OK')
    
# 1679902, 2022-11-12 10:31:56, PPP (100%)

n =int(input())
d = {}
for i in range(n) :
    x,y = input().split()
    if y not in d :
        d[x]= [y]
    else :
        d[x].append(y)
sa = []
n1 = input()
while n1 != 'q' :
    xx = n1.strip().split()
    sa.append(xx)
    n1 = input()
#e=[t,y,u,i]
f = True
for e in sa:
    m = []
    for t in e :
        if t not in d :
            f = False
        else :
            if d[t] not in m :
                m.append(d[t])
            else :
              f = False
    
    if len(m) == len(e):
       print("OK")
    else:
      print('Not OK')

6530089521
# 1679431, 2022-11-12 10:10:35, xxx (0%)

ateam={}
for i in range (int(input())):
    team = input().split()
    ateam[team[0]]=team[1]
while True:
    group= input().split()
    if group =='q': break
    count={}
    for i in group:
        if i not in ateam:
            print('Not OK')
            pass
        if i in ateam:
            if ateam[i] in count:
                count[ateam[i]]+=1
            else: count[ateam[i]]=1
    for i in count:
        if count[i]>=2:
            print('Not OK')
            pass
            

# 1679713, 2022-11-12 10:24:00, xxx (0%)

def t(x):
    count={}
    for i in x:
        if i not in ateam:
            return 'Not OK'
        if ateam[i] in count:
            count[ateam[i]]+=1
        else: count[ateam[i]]=1
        for j in count:
            if count[j] >=2 :return 'Not OK'
        return 'OK'
ateam={}
for i in range (int(input())):
    team = input().split()
    ateam[team[0]]=team[1]
a=[]
while True:
    group= input().split()
    if group =='q': break
    a.append(group)
for h in a:
    print(t(h))
            

# 1680101, 2022-11-12 10:41:50, --- (0%)

def t(x):
    count={}
    for i in x:
        if i not in ateam:
            return 'Not OK'
        if ateam[i] in count:
            count[ateam[i]]+=1
        else: count[ateam[i]]=1
    for j in count:
        if count[j] >=2 :return 'Not OK'
    return 'OK'
ateam={}
for i in range (int(input())):
    team = input().split()
    ateam[team[0]]=team[1]
a=[]
print(ateam)
while True:
    group = input().split()
    if group[0] in 'q': break
    a.append(group)
for h in a:
    print(t(h))
            

# 1680323, 2022-11-12 10:52:23, --- (0%)

def t(x):
    count={}
    for i in x:
        if i not in ateam:
            return 'Not OK'
        if ateam[i] in count:
            count[ateam[i]]+=1
        else: count[ateam[i]]=1
    for j in count:
        if count[j] >=2 :return 'Not OK'
    return 'OK'
ateam={}
for i in range (int(input())):
    team = input().split()
    ateam[team[0]]=team[1]
a=[]
print(ateam)
while True:
    group = input()
    if group =='q': break
    group.split()
    a.append(group)
for h in a:
    print(t(h))
# 1680379, 2022-11-12 10:54:06, --- (0%)

def t(x):
    count={}
    for i in x:
        if i not in ateam:
            return 'Not OK'
        if ateam[i] in count:
            count[ateam[i]]+=1
        else: count[ateam[i]]=1
    for j in count:
        if count[j] >=2 :return 'Not OK'
    return 'OK'
ateam={}
for i in range (int(input())):
    team = input().split()
    ateam[team[0]]=team[1]
a=[]
while True:
    group = input()
    if group =='q': break
    group.split()
    a.append(group)
for h in a:
    print(t(h))
# 1680390, 2022-11-12 10:54:26, PPP (100%)

def t(x):
    count={}
    for i in x:
        if i not in ateam:
            return 'Not OK'
        if ateam[i] in count:
            count[ateam[i]]+=1
        else: count[ateam[i]]=1
    for j in count:
        if count[j] >=2 :return 'Not OK'
    return 'OK'
ateam={}
for i in range (int(input())):
    team = input().split()
    ateam[team[0]]=team[1]
a=[]
while True:
    group = input().split()
    if group[0] in 'q': break
    a.append(group)
for h in a:
    print(t(h))


6530091721
# 1678682, 2022-11-12 09:29:25, --- (0%)

n=int(input())
s={}
for i in range (n):
    team,nation=input().strip().split()
    if nation in s:
        s[nation]=s[nation]+[team]
    else:
        s[nation]=[team]
m=input()
while m!='q':
    n=set()
    m=m.split()
    for e in m:
        for key in s:
            if e in s[key]:
                n.add(key)
            else:
                pass
    if len(m)==len(n):
        print('OK')
    else:
        print('NOT OK')
    m=input() 
# 1678730, 2022-11-12 09:31:34, --- (0%)

n=int(input())
s={}
for i in range (n):
    team,nation=input().strip().split()
    if nation in s:
        s[nation]=s[nation]+[team]
    else:
        s[nation]=[team]
m=input()
while m!='q':
    n=set()
    m=m.split()
    for e in m:
        for key in s:
            if e in s[key]:
                n.add(key)
            else:
                pass
    if len(m)==len(n):
        print('OK')
    else:
        print('NOT OK')
    m=input()
# 1678826, 2022-11-12 09:36:48, --- (0%)

n=int(input())
s={}
for i in range (n):
  team,nation=input().strip().split()
  if nation in s:
    s[nation]=s[nation]+[team]
  else:
    s[nation]=[team]
m=input()
while m!='q':
  n=set()
  m=m.split()
  for e in m:
    for key in s:
      if e in s[key]:
        n.add(key)
      else:
        pass
  if len(m)==len(n):
    print('OK')
  else:
    print('NOT OK')
  m=input()
# 1678899, 2022-11-12 09:41:12, --- (0%)

n=int(input())
s={}
for i in range (n):
  team,nation=input().strip().split()
  if nation in s:
    s[nation]=s[nation]+[team]
  else:
    s[nation]=[team]
m=input()
while m!='q':
  n=set()
  m=m.split()
  if len(m)==1:
    print('NOT OK')
  else:
    for e in m:
      for key in s:
        if e in s[key]:
          n.add(key)
        else:
          pass
    if len(m)==len(n):
      print('OK')
    else:
      print('NOT OK')
  m=input()
# 1679677, 2022-11-12 10:23:08, --- (0%)

n=int(input())
s={}
for i in range (n):
  team,nation=input().strip().split()
  if nation in s:
    s[nation]=s[nation]+[team]
  else:
    s[nation]=[team]
m=input()
while m!='q':
  n=set()
  m=m.split()
  if len(m)==1:
    print('NOT OK')
  else:
    for e in m:
      for key in s:
        if e in s[key]:
          n.add(key)
        else:
          pass
    if len(m)==len(n):
      print('OK')
    else:
      print('NOT OK')
  m=input()
# 1679715, 2022-11-12 10:24:03, PPP (100%)

n=int(input())
s={}
for i in range (n):
  team,nation=input().strip().split()
  if nation in s:
    s[nation]=s[nation]+[team]
  else:
    s[nation]=[team]
m=input()
while m!='q':
  n=set()
  m=m.split()
  if len(m)==1:
    print('NOT OK')
  else:
    for e in m:
      for key in s:
        if e in s[key]:
          n.add(key)
        else:
          pass
    if len(m)==len(n):
      print('OK')
    else:
      print('Not OK')
  m=input()

6531514021
# 1678692, 2022-11-12 09:29:42, --x (0%)

teams = {t:c  for t,c in [input().split() for i in range(int(input()))]}
print(teams)
group = input()
r = []
while group != 'q' :
    team_g = group.split()
    b = True
    defult = teams[team_g[0]]
    for e in team_g[1:] :
        if e not in teams :
            b = False
            break
        else :
            if teams[e] == defult :
                b = False
                break
            elif teams[e] != defult :
                defult = teams[e]
    if b :
        r.append('OK')
    else :
        r.append('Not OK')
    group = input()
for e in r :
    print(e)

# 1678727, 2022-11-12 09:31:21, PPx (67%)

teams = {t:c  for t,c in [input().split() for i in range(int(input()))]}
group = input()
r = []
while group != 'q' :
    team_g = group.split()
    b = True
    defult = teams[team_g[0]]
    for e in team_g[1:] :
        if e not in teams :
            b = False
            break
        else :
            if teams[e] == defult :
                b = False
                break
            elif teams[e] != defult :
                defult = teams[e]
    if b :
        r.append('OK')
    else :
        r.append('Not OK')
    group = input()
for e in r :
    print(e)
# 1679277, 2022-11-12 10:01:58, --x (0%)

teams = {t:c  for t,c in [input().split() for i in range(int(input()))]}
print(teams)
group = input()
r = []
while group != 'q' :
    team_g = group.split()
    b = True
    defult = teams[team_g[0]]
    v = [teams[team_g[0]]]
    for e in team_g[1:] :
        if e not in teams :
            b = False
            break
        else :
            if teams[e] in v:
                b = False
            else :
                v.append(teams[e])
    if b :
        r.append('OK')
    else :
        r.append('Not OK')
    group = input()
for e in r :
    print(e)

# 1679285, 2022-11-12 10:02:11, PPx (67%)

teams = {t:c  for t,c in [input().split() for i in range(int(input()))]}
group = input()
r = []
while group != 'q' :
    team_g = group.split()
    b = True
    defult = teams[team_g[0]]
    v = [teams[team_g[0]]]
    for e in team_g[1:] :
        if e not in teams :
            b = False
            break
        else :
            if teams[e] in v:
                b = False
            else :
                v.append(teams[e])
    if b :
        r.append('OK')
    else :
        r.append('Not OK')
    group = input()
for e in r :
    print(e)
# 1680919, 2022-11-12 11:14:01, PPP (100%)

teams = {t:c  for t,c in [input().split() for i in range(int(input()))]}
# print(teams)
group = input()
r = []
while group != 'q' :
    team_g = group.split()
    b = True
    if team_g[0] in teams:
        defult = teams[team_g[0]]
        v = [teams[team_g[0]]]
        for e in team_g[1:] :
            if e not in teams :
                b = False
                break
            else :
                if teams[e] in v:
                    b = False
                else :
                    v.append(teams[e])
    else :
        b = False
    if b :
        r.append('OK')
    else :
        r.append('Not OK')
    group = input()
for e in r :
    print(e)



6530056821
# 1678550, 2022-11-12 09:22:16, xxx (0%)

def mli(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        return [l.strip().split() for l in f]
n = int(input())
d = {}
o = []
for i in range(n):
    t,c = input().strip()
    d[t] = c
n = input().split()
c = 0
for x in n:
    o.append(d[x])
for i in range(len(o)-1):
    for j in range(i+1,len(o)):
        if o[i] == o[j]:
            c+=1
if c>=1:
    print('Not OK')
else:
    print('OK')
while n!=['q']:
    n = input().split()
    if n!=['q']:
        c = 0
        for x in n:
            o.append(d[x])
        for i in range(len(o)-1):
            for j in range(i+1,len(o)):
                if o[i] == o[j]:
                    c+=1
        if c>=1:
            print('Not OK')
        else:
            print('OK')
    

    






































# 1678567, 2022-11-12 09:23:13, --x (0%)

n = int(input())
d = {}
o = []
for i in range(n):
    t,c = input().split()
    d[t] = c
n = input().split()
c = 0
for x in n:
    o.append(d[x])
for i in range(len(o)-1):
    for j in range(i+1,len(o)):
        if o[i] == o[j]:
            c+=1
if c>=1:
    print('Not OK')
else:
    print('OK')
while n!=['q']:
    n = input().split()
    if n!=['q']:
        c = 0
        for x in n:
            o.append(d[x])
        for i in range(len(o)-1):
            for j in range(i+1,len(o)):
                if o[i] == o[j]:
                    c+=1
        if c>=1:
            print('Not OK')
        else:
            print('OK')
# 1678635, 2022-11-12 09:26:59, --- (0%)

def mli(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        return [l.strip().split() for l in f]
n = int(input())
d = {}
o = []
for i in range(n):
    t,c = input().split()
    d[t] = c
n = input().split()
c = 0
for x in n:
    if x in d.keys():
        o.append(d[x])
for i in range(len(o)-1):
    for j in range(i+1,len(o)):
        if o[i] == o[j]:
            c+=1
if c>=1:
    print('Not OK')
else:
    print('OK')
while n!=['q']:
    n = input().split()
    if n!=['q']:
        c = 0
        for x in n:
            if x in d.keys():
                o.append(d[x])
        for i in range(len(o)-1):
            for j in range(i+1,len(o)):
                if o[i] == o[j]:
                    c+=1
        if c>=1:
            print('Not OK')
        else:
            print('OK')
    

    






































# 1678667, 2022-11-12 09:28:38, --- (0%)

def mli(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        return [l.strip().split() for l in f]
n = int(input())
d = {}
o = []
for i in range(n):
    t,c = input().split()
    d[t] = c
n = input().split()
c = 0
for x in n:
    if x in d.keys():
        o.append(d[x])
    else:
        c+=1
for i in range(len(o)-1):
    for j in range(i+1,len(o)):
        if o[i] == o[j]:
            c+=1
if c>=1:
    print('Not OK')
else:
    print('OK')
while n!=['q']:
    n = input().split()
    if n!=['q']:
        c = 0
        for x in n:
            if x in d.keys():
                o.append(d[x])
            else:
                c+=1
        for i in range(len(o)-1):
            for j in range(i+1,len(o)):
                if o[i] == o[j]:
                    c+=1
        if c>=1:
            print('Not OK')
        else:
            print('OK')
    

    






































# 1678712, 2022-11-12 09:30:40, PPP (100%)

def mli(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        return [l.strip().split() for l in f]
n = int(input())
d = {}
o = []
for i in range(n):
    t,c = input().split()
    d[t] = c
n = input().split()
c = 0
for x in n:
    
    if x in d.keys():
        o.append(d[x])
    else:
        c+=1
for i in range(len(o)-1):
    for j in range(i+1,len(o)):
        if o[i] == o[j]:
            c+=1
if c>=1:
    print('Not OK')
else:
    print('OK')
while n!=['q']:
    o = []
    n = input().split()
    if n!=['q']:
        c = 0
        for x in n:
            if x in d.keys():
                o.append(d[x])
            else:
                c+=1
        for i in range(len(o)-1):
            for j in range(i+1,len(o)):
                if o[i] == o[j]:
                    c+=1
        if c>=1:
            print('Not OK')
        else:
            print('OK')
    

    







































6530064821
# 1679595, 2022-11-12 10:19:23, --- (0%)

n = int(input())  #ประเทศเดียวกันห้ามอยู่ด้วยกัน
d = {}
for i in range(n):
    f,c = input().split()
#     f = f.strip()
#     c = c.strip()
    if c not in d:
        d[c] = {f}
    else:
        d[c].add(f)      # d = {Endland: {Liverpool, Mancity}, Spain: {Barcelona, Real}}
x = []
y = []
j = []
t = False
while True:
    b = input().split()
    if b[0] == "q":break
    s = set(b)
    x.append(s)   # x=[{'Liverpool', 'Ajax', 'Dortmund', 'Milan'}, {'Liverpool', 'PSG', 'Barcelona', 'Real'}, {'Celtic', 'Milan', 'PSG', 'ManCity', 'Ajax'}, {'Real', 'Bayern', 'ManCity', 'Ajax', 'SamyanFC'}]
    for e in d:
        r = len(s&d[e])
    
    if t==False:
        print("Not OK")
    else:
        t = True
        print("OK")
# 1679690, 2022-11-12 10:23:27, PP- (67%)

n = int(input())  #ประเทศเดียวกันห้ามอยู่ด้วยกัน
d = {}
for i in range(n):
    f,c = input().split()
#     f = f.strip()
#     c = c.strip()
    if c not in d:
        d[c] = {f}
    else:
        d[c].add(f)      # d = {Endland: {Liverpool, Mancity}, Spain: {Barcelona, Real}}
x = []
y = []
j = []
while True:
    b = input().split()
    if b[0] == "q":break
    s = set(b)
    x.append(s)   # x=[{'Liverpool', 'Ajax', 'Dortmund', 'Milan'}, {'Liverpool', 'PSG', 'Barcelona', 'Real'}, {'Celtic', 'Milan', 'PSG', 'ManCity', 'Ajax'}, {'Real', 'Bayern', 'ManCity', 'Ajax', 'SamyanFC'}]
    for e in d:
        r = len(s&d[e])
        y.append(r)
        g = set(y)
        u = g - {1,0}
    if len(u) == 0:
        print("OK")
    else:
        print("Not OK")
# 1679988, 2022-11-12 10:36:46, PP- (67%)

n = int(input())  #ประเทศเดียวกันห้ามอยู่ด้วยกัน
d = {}
w = set()
for i in range(n):
    f,c = input().split()
#     f = f.strip()
#     c = c.strip()
    w.add(f)      # w ={ชื่อทีมทั้งหมดที่มี}
    if c not in d:
        d[c] = {f}
    else:
        d[c].add(f)      # d = {Endland: {Liverpool, Mancity}, Spain: {Barcelona, Real}}
x = []
y = []
j = []
while True:
    b = input().split()
    if b[0] == "q":break
    s = set(b)
    x.append(s)   # x=[{'Liverpool', 'Ajax', 'Dortmund', 'Milan'}, {'Liverpool', 'PSG', 'Barcelona', 'Real'}, {'Celtic', 'Milan', 'PSG', 'ManCity', 'Ajax'}, {'Real', 'Bayern', 'ManCity', 'Ajax', 'SamyanFC'}]
    for e in d:
        r = len(s&d[e])
        y.append(r)
        g = set(y)
        u = g - {1,0}
    r = True
    for k in b:
        if k not in w:
            r = False
    if r == False:
        print("Not OK")
    elif len(u) == 0:
        r = True
        print("OK")
    
    else:
        print("Not OK")
# 1680001, 2022-11-12 10:37:15, PP- (67%)

n = int(input())  #ประเทศเดียวกันห้ามอยู่ด้วยกัน
d = {}
for i in range(n):
    f,c = input().split()
#     f = f.strip()
#     c = c.strip()
    if c not in d:
        d[c] = {f}
    else:
        d[c].add(f)      # d = {Endland: {Liverpool, Mancity}, Spain: {Barcelona, Real}}
x = []
y = []
j = []
while True:
    b = input().split()
    if b[0] == "q":break
    s = set(b)
    x.append(s)   # x=[{'Liverpool', 'Ajax', 'Dortmund', 'Milan'}, {'Liverpool', 'PSG', 'Barcelona', 'Real'}, {'Celtic', 'Milan', 'PSG', 'ManCity', 'Ajax'}, {'Real', 'Bayern', 'ManCity', 'Ajax', 'SamyanFC'}]
    for e in d:
        r = len(s&d[e])
        y.append(r)
        g = set(y)
        u = g - {1,0}
    if len(u) == 0:
        print("OK")
    else:
        print("Not OK")
# 1680285, 2022-11-12 10:50:38, PPP (100%)

n = int(input())  #ประเทศเดียวกันห้ามอยู่ด้วยกัน
d = {}
w = set()
for i in range(n):
    f,c = input().split()
#     f = f.strip()
#     c = c.strip()
    w.add(f)      # w ={ชื่อทีมทั้งหมดที่มี}
    if c not in d:
        d[c] = {f}
    else:
        d[c].add(f)      # d = {Endland: {Liverpool, Mancity}, Spain: {Barcelona, Real}}
x = []
j = []
while True:
    b = input().split()
    if b[0] == "q":break
    s = set(b)
    x.append(s)   # x=[{'Liverpool', 'Ajax', 'Dortmund', 'Milan'}, {'Liverpool', 'PSG', 'Barcelona', 'Real'}, {'Celtic', 'Milan', 'PSG', 'ManCity', 'Ajax'}, {'Real', 'Bayern', 'ManCity', 'Ajax', 'SamyanFC'}]
    y = []
    for e in d:
        r = len(s&d[e])
        y.append(r)
    g = set(y)
    u = g - {1,0}
    
    r = True
    for k in b:
        if k not in w:
            r = False
    if r == False:
        print("Not OK")
    elif len(u) == 0:
        r = True
        print("OK")
    else:
        r = True
        print("Not OK")

6530080821
# 1679186, 2022-11-12 09:56:59, PP- (67%)

n = int(input())
d = {}
for i in range(n):
    name,pra = input().split()
    name = name.strip()
    pra = pra.strip()
    d[name] = pra
    
def fffff(x) :
    for i in range(len(x)-1):
        for j in range(i+1,len(x)):
            if d[x[i]] == d[x[j]]:
                return 'Not OK'
            else:
                return 'OK'
cout = False
x = input().split()
while x[0] != 'q':
    for e in x:
        if e not in d:
            cout = True
            print('Not OK')
            break
    if cout == True:
        break   
    else:
        print (fffff(x))
            
        
            
            
    x = input().split()
            
        
    
    
    


                


# 1679266, 2022-11-12 10:01:37, PP- (67%)

n = int(input())
d = {}
for i in range(n):
    name,pra = input().split()
    name = name.strip()
    pra = pra.strip()
    d[name] = pra
    
def fffff(x) :
    for i in range(len(x)-1):
        for j in range(i+1,len(x)):
            if d[x[i]] == d[x[j]]:
                return 'Not OK'
    return 'OK'
cout = False
x = input().split()
while x[0] != 'q':
    for e in x:
        if e not in d:
            cout = True
            print('Not OK')
            break
    if cout == True:
        break   
    else:
        print (fffff(x))
            
        
            
            
    x = input().split()
            
        
    
    
    


                


# 1679447, 2022-11-12 10:11:20, PP- (67%)

n = int(input())
d = {}
for i in range(n):
    name,pra = input().split()
    name = name.strip()
    pra = pra.strip()
    d[name] = pra
    
def fffff(x) :
    for i in range(len(x)-1):
        for j in range(i+1,len(x)):
            if d[x[i]] == d[x[j]]:
                return 'Not OK'
    return 'OK'

cout = False
x = input().split()
while x[0] != 'q':
    for e in x:
        if e not in d:
            cout = True
            print('Not OK')
            break
    if cout == True:
        break   
    else:
        print (fffff(x))
    x = input().split()
            
        
    
    
    


                



# 1679521, 2022-11-12 10:14:33, PP- (67%)

def fffff(x) :
    for i in range(len(x)-1):
        for j in range(i+1,len(x)):
            if d[x[i]] == d[x[j]]:
                return 'Not OK'
    return 'OK'

n = int(input())
d = {}
for i in range(n):
    name,pra = input().split()
    name = name.strip()
    pra = pra.strip()
    d[name] = pra
    
cout = False
x = input().split()
while x[0] != 'q':
    for e in x:
        if e not in d:
            cout = True
            print('Not OK')
            break
    if cout == True:
        break   
    else:
        print(fffff(x))
    x = input().split()
            
        
    
    
    


                



# 1679548, 2022-11-12 10:16:13, PPP (100%)

def fffff(x) :
    for i in range(len(x)-1):
        for j in range(i+1,len(x)):
            if d[x[i]] == d[x[j]]:
                return 'Not OK'
    return 'OK'

n = int(input())
d = {}
for i in range(n):
    name,pra = input().split()
    name = name.strip()
    pra = pra.strip()
    d[name] = pra
    
cout = False
x = input().split()
while x[0] != 'q':
    for e in x:
        if e not in d:
            cout = True
            print('Not OK')
            break
       
    else:
        print(fffff(x))
    x = input().split()
            
        
    
    
    


                




6530140821
# 1678581, 2022-11-12 09:23:46, PP- (67%)

n = int(input())
i=0
team={}
while i != n:
    i+=1
    a, b= input().split()
    team[a] = b
while True:
    g = input().split()
    res = []
    rr = []
    if g != ["q"]:
        for i in g:
            if i in team:
                res.append(team[i])
            else:
                print("Not OK")
                break
        for e in res:
            if e not in rr:
                rr.append(e)
        if len(rr) == len(res):
            print("OK")
        else:
            print("Not OK")
    else:
        break

        
# 1678640, 2022-11-12 09:27:10, --- (0%)

n = int(input())
i=0
team={}
while i != n:
    i+=1
    a, b= input().split()
    team[a] = b
while True:
    g = input().split()
    res = []
    rr = []
    if g != ["q"]:
        for i in g:
            if i in team:
                res.append(team[i])
            else:
                print("Not OK")
                break
        for e in res:
            if e not in rr:
                rr.append(e)
        if len(rr) == len(res) and len(rr) != 1:
            print("OK")
        else:
            print("Not OK")
        print(res)
    else:
        break

        
# 1678643, 2022-11-12 09:27:20, --- (0%)

n = int(input())
i=0
team={}
while i != n:
    i+=1
    a, b= input().split()
    team[a] = b
while True:
    g = input().split()
    res = []
    rr = []
    if g != ["q"]:
        for i in g:
            if i in team:
                res.append(team[i])
            else:
                print("Not OK")
                break
        for e in res:
            if e not in rr:
                rr.append(e)
        if len(rr) == len(res):
            print("OK")
        else:
            print("Not OK")
        print(res)
    else:
        break
# 1678649, 2022-11-12 09:27:36, PP- (67%)

n = int(input())
i=0
team={}
while i != n:
    i+=1
    a, b= input().split()
    team[a] = b
while True:
    g = input().split()
    res = []
    rr = []
    if g != ["q"]:
        for i in g:
            if i in team:
                res.append(team[i])
            else:
                print("Not OK")
                break
        for e in res:
            if e not in rr:
                rr.append(e)
        if len(rr) == len(res) and len(rr) != 1:
            print("OK")
        else:
            print("Not OK")
    else:
        break
# 1678711, 2022-11-12 09:30:38, PPP (100%)

n = int(input())
i=0
team={}
while i != n:
    i+=1
    a, b= input().split()
    team[a] = b
while True:
    g = input().split()
    res = []
    rr = []
    cnt = 0
    if g != ["q"]:
        for i in g:
            if i in team:
                res.append(team[i])
            else:
                print("Not OK")
                cnt = 1
                break
        for e in res:
            if e not in rr:
                rr.append(e)
        if len(rr) == len(res) and cnt != 1:
            print("OK")
        elif len(rr) != len(res) and cnt == 0:
            print("Not OK")
    else:
        break

        

6530145021
# 1679111, 2022-11-12 09:53:07, xxx (0%)

tdic = {}; ans = []
for i in range(int(input())):
    team,country = input().strip().split()
    if country not in tdic: tdic[team] = [country]
    else: tdic[team].append(country)
while True:
    x = input().strip()
    if x == "q": break
    tlist = x.split
    c = []
    b = 0
    for e in tlist:
        if e not in tdic:
            b = -1
            ans.append("Not OK")
            break
        if tdic[e] not in c: c.append(tdic[e])
        else:
            ans.append("Not OK")
            b = -1
            break
    if b != -1:
        ans.append("OK")
print("\n".join(ans))
        
            
            

# 1679336, 2022-11-12 10:05:16, PPP (100%)

tdic = {}; ans = []
for i in range(int(input())):
    team,country = input().strip().split()
    if country not in tdic: tdic[team] = [country]
    else: tdic[team].append(country)
while True:
    x = input().strip()
    if x == "q": break
    tlist = x.split()
    check = []
    t = 0
    for e in tlist:
        if e not in tdic:
            t = -1
            ans.append("Not OK")
            break
        if tdic[e] not in check: check.append(tdic[e])
        else:
            ans.append("Not OK")
            t = -1
            break
    if t != -1:
        ans.append("OK")
print("\n".join(ans))
# 1679368, 2022-11-12 10:06:37, PPP (100%)

tdic = {}; ans = []
for i in range(int(input())):
    team,country = input().strip().split()
    if country not in tdic: tdic[team] = [country]
    else: tdic[team].append(country)
while True:
    x = input().strip()
    if x == "q": break
    tlist = x.split()
    check = []
    t = 0
    for m in tlist:
        if m not in tdic:
            t = -1
            ans.append("Not OK")
            break
        if tdic[m] not in check: check.append(tdic[m])
        else:
            ans.append("Not OK")
            t = -1
            break
    if t != -1:
        ans.append("OK")
print("\n".join(ans))

# 1680229, 2022-11-12 10:47:48, PPP (100%)

tdic = {}
ans = []
for i in range(int(input())):
    team,country = input().strip().split()
    if country not in tdic: tdic[team] = [country]
    else: tdic[team].append(country)
while True:
    x = input().strip()
    if x == "q": break
    tlist = x.split()
    check = []
    t = 0
    for m in tlist:
        if m not in tdic:
            t = -1
            ans.append("Not OK")
            break
        if tdic[m] not in check: check.append(tdic[m])
        else:
            ans.append("Not OK")
            t = -1
            break
    if t != -1:
        ans.append("OK")
print("\n".join(ans))
# 1680284, 2022-11-12 10:50:35, PPP (100%)

tdic = {}
ans = []
n = int(input())
for i in range(n):
    team,country = input().strip().split()
    if country not in tdic:
        tdic[team] = [country]
    else:
        tdic[team].append(country)
while True:
    x = input().strip()
    if x == "q":
        break
    tlist = x.split()
    check = []
    t = 0
    for m in tlist:
        if m not in tdic:
            t = -1
            ans.append('Not OK')
            break
        if tdic[m] not in check:
            check.append(tdic[m])
        else:
            ans.append("Not OK")
            t = -1
            break
    if t != -1:
        ans.append("OK")
print("\n".join(ans))

6530194721
# 1678838, 2022-11-12 09:37:21, --- (0%)

n = int(input())
allteam ={}
for i in range(n):
    team,con=input().split()
    allteam[team] = con
x = input()
while x!='q':
    check =[]
    mt=x.split()
    for t in mt:
        if t in allteam:
            if allteam[t] not in check:
                check.append(allteam[t])
                c = True
            else:
                c = False
        else:
            c = False
    if c == False:
        print('Not OK')
        break
    x = input()
if c==True:
    print('OK')
# 1678859, 2022-11-12 09:38:23, PP- (67%)

n = int(input())
allteam ={}
for i in range(n):
    team,con=input().split()
    allteam[team] = con
x = input()
while x!='q':
    check =[]
    mt=x.split()
    for t in mt:
        if t in allteam:
            if allteam[t] not in check:
                check.append(allteam[t])
                c = True
            else:
                c = False
        else:
            c = False
    if c == False:
        print('Not OK')
    if c==True:
      print('OK')
    x = input()

# 1678938, 2022-11-12 09:43:35, xxx (0%)

n = int(input())
allteam ={}
for i in range(n):
    team,con=input().split()
    allteam[team] = con
x = input()
while x!='q':
    check =[]
    mt=x.split()
    c == True
    for t in mt:
        if t in allteam:
            if c ==True:
                if allteam[t] not in check:
                    check.append(allteam[t])
                else:
                    c = False
        else:
            c = False
    if c == False:
        print('Not OK')
    if c==True:
      print('OK')
    x = input()
# 1678972, 2022-11-12 09:45:19, xxx (0%)

n = int(input())
allteam ={}
for i in range(n):
    team,con=input().split()
    allteam[team] = con
x = input()
while x!='q':
    check =[]
    mt=x.split()
    c == True
    for t in mt:
        if t in allteam:
            if c ==True:
                if allteam[t] not in check:
                    check.append(allteam[t])
                else:
                    c = False
            else:
                c=False
        else:
            c = False
    if c == False:
        print('Not OK')
    if c==True:
      print('OK')
    x = input()
# 1679009, 2022-11-12 09:47:36, PPP (100%)

n = int(input())
allteam ={}
for i in range(n):
    team,con=input().split()
    allteam[team] = con
x = input()
while x!='q':
    check =[]
    mt=x.split()
    c = True
    for t in mt:
        if t in allteam:
            if c ==True:
                if allteam[t] not in check:
                    check.append(allteam[t])
                else:
                    c = False
            else:
                c=False
        else:
            c = False
    if c == False:
        print('Not OK')
    if c==True:
      print('OK')
    x = input()

6130394021
# 1678887, 2022-11-12 09:40:15, xxx (0%)

n = int(input())
club_of_nation = {}
for i in range(n):
    club,nation = input().split()
    club_of_nation[club] = nation
#print(club_of_nation)
while True:
    x = input().split()
    if len(x) == 1 and x == "q":
        break
    check_team = set()
    for i in range(len(x)):
        if x[i] not in club_of_nation:
            break
        check_team.add(club_of_nation[x[i]])
    if len(x) == len(check_team):
        print("OK")
    else:
        print("Not OK")
# 1678966, 2022-11-12 09:44:51, --- (0%)

n = int(input())
club_of_nation = {}
for i in range(n):
    club,nation = input().split()
    club_of_nation[club] = nation
#print(club_of_nation)
x = input()
while x != "q":
    x.split()
    check_team = set()
    for i in range(len(x)):
        if x[i] not in club_of_nation:
            break
        check_team.add(club_of_nation[x[i]])
    if len(x) == len(check_team):
        print("OK")
    else:
        print("Not OK")
    x = input()
# 1679043, 2022-11-12 09:49:08, xxx (0%)

n = int(input())
club_of_nation = {}
for i in range(n):
    club,nation = input().split()
    club_of_nation[club] = nation
#print(club_of_nation)
x = input().split()
while x != "q":
    if x == "q": break
    check_team = set()
    for i in range(len(x)):
        if x[i] not in club_of_nation:
            break
        check_team.add(club_of_nation[x[i]])
    if len(x) == len(check_team):
        print("OK")
    else:
        print("Not OK")
    x = input().split()
# 1679182, 2022-11-12 09:56:50, PPP (100%)

n = int(input())
club_of_nation = {}
for i in range(n):
    club,nation = input().split()
    club_of_nation[club] = nation
#print(club_of_nation)
x = input().split()
while x != ["q"]:
    if x == ["q"]:
        break
    check_team = set()
    for i in range(len(x)):
        if x[i] not in club_of_nation:
            break
        check_team.add(club_of_nation[x[i]])
    if len(x) == len(check_team):
        print("OK")
    else:
        print("Not OK")
    x = input().split()

6230065121
# 1678800, 2022-11-12 09:35:25, --x (0%)

n = int(input())
team_dict = {}
# input as team name and country
for i in range(n):
    team, country = input().split()
    team_dict[team] = country
    
teams_input = input()
while teams_input != 'q':
    teams = teams_input.split()
    # check if teams are in the same country
    if len(set([team_dict[team] for team in teams])) == 1:
        print('OK')
    else:
        print('Not OK')

    teams_input = input()


# 1678989, 2022-11-12 09:46:40, --x (0%)

n = int(input())
team_dict = {}
# input as team name and country
for i in range(n):
    team, country = input().split()
    team_dict[team] = country
    
teams_input = input()
while teams_input != 'q':
    teams = teams_input.split()
    # check if teams are in the same country
    if len(set([team_dict[team] for team in teams])) == 1:
        print('OK')
    else:
        print('Not OK')

    teams_input = input()
# 1679048, 2022-11-12 09:49:23, --x (0%)

n = int(input())
team_dict = {}
# input as team name and country
for i in range(n):
    team, country = input().split()
    team_dict[team] = country
    
teams_input = input()
while teams_input != 'q':
    teams = teams_input.split()
    # check if teams are in the same country
    if len(set([team_dict[team] for team in teams])) == 1:
        print('OK')
    else:
        print('Not OK')

    teams_input = input()
# 1679195, 2022-11-12 09:57:30, PPP (100%)

n = int(input())
team_dict = {}
# input as team name and country
for i in range(n):
    team, country = input().split()
    team_dict[team] = country
    
teams_input = input()
while teams_input != 'q':
    teams = teams_input.split()
    status = False
    
    for team in teams:
        if team not in team_dict:
            print('Not OK')
            status = True
            break
    if status:
        teams_input = input()
        continue
    # check if teams are in the same country
    if len(set([team_dict[team] for team in teams])) == len(teams):
        print('OK')
    else:
        print('Not OK')

    teams_input = input()


    


    


6230425421
# 1678913, 2022-11-12 09:42:07, --- (0%)

country = {}
for i in range(int(input())) :
    team,coun = input().split()
    country[team] = (coun)


while True :
    x = input().split()
    if x[0] == 'q' : break
    group = []
    for e in set(x) :
        if e in country :
            group.append(country[e])
        else :
            group.append(e)
    g = set(group)
    if len(g) == len(group) :
        print('Ok')
    else :
        print('Not ok')
# 1678926, 2022-11-12 09:42:46, PP- (67%)

country = {}
for i in range(int(input())) :
    team,coun = input().split()
    country[team] = (coun)


while True :
    x = input().split()
    if x[0] == 'q' : break
    group = []
    for e in set(x) :
        if e in country :
            group.append(country[e])
        else :
            group.append(e)
    g = set(group)
    if len(g) == len(group) :
        print('OK')
    else :
        print('Not OK')
# 1679351, 2022-11-12 10:05:56, --- (0%)

# {ทีม : ประเทศ}
country = {}
for i in range(int(input())) :
    team,coun = input().split()
    country[team] = (coun)


while True :
    x = input().split()
    if x[0] == 'q' : break
    group = []
    for e in x :
        if e in country :
            group.append(country[e])
    g = set(group)
#     print(g)
#     print(group)
#     print(x)
    if len(g) == len(group) == len(x) :
        print('OK')
    else :
        print('Not Ok')
# 1679367, 2022-11-12 10:06:35, PPP (100%)

# {ทีม : ประเทศ}
country = {}
for i in range(int(input())) :
    team,coun = input().split()
    country[team] = (coun)


while True :
    x = input().split()
    if x[0] == 'q' : break
    group = []
    for e in x :
        if e in country :
            group.append(country[e])
    g = set(group)
#     print(g)
#     print(group)
#     print(x)
    if len(g) == len(group) == len(x) :
        print('OK')
    else :
        print('Not OK')

6431112321
# 1678742, 2022-11-12 09:32:09, --- (0%)

x = []
y = {}
for i in range(int(input())) :
    team , c = input().strip().split()
    y[team] = c
a = input().strip().split()
while a != ['q'] :
    t = True
    for i in range(len(a)):
        if a[i] not in y :
            t = False
    if t == True :
        print('OK')
    else :
        print('Not OK')
    a = input().strip().split()
# 1678890, 2022-11-12 09:40:30, --- (0%)

x = []
y = {}
for i in range(int(input())) :
    team , c = input().strip().split()
    y[team] = c
a = input().strip().split()
while a != ['q'] :
    t = True
    for i in range(len(a)):
        if a[i] not in y :
            t = False 
    if t == True :
        x.append('OK')
    else :
        x.append('Not OK')
    a = input().strip().split()
for i in range(len(x)):
    print(x[i])
# 1679231, 2022-11-12 09:59:41, --- (0%)

w = []
y = {}
for i in range(int(input())) :
    team , c = input().strip().split()
    y[team] = c
a = input().strip().split()
while a != ['q'] :
    t = True
    x = []
    for i in range(len(a)):
        if a[i] not in y :
            t = False
    if t == True :
        for i in a :
            x.append([[i],y[i]])
        for i in range(len(x)):
            for j in range(i+1,len(x),1) :
                if x[i][1] != x[j][1] :
                    t = False
    if t == True :
        w.append('OK')
    else :
        w.append('Not OK')
    a = input().strip().split()
for i in range(len(w)):
    print(w[i])
# 1679268, 2022-11-12 10:01:39, PPP (100%)

w = []
y = {}
for i in range(int(input())) :
    team , c = input().strip().split()
    y[team] = c
a = input().strip().split()
while a != ['q'] :
    t = True
    x = []
    for i in range(len(a)):
        if a[i] not in y :
            t = False
    if t == True :
        for i in a :
            x.append([[i],y[i]])
        for i in range(len(x)):
            for j in range(i+1,len(x),1) :
                if x[i][1] == x[j][1] :
                    t = False
                    
    if t == True :
        w.append('OK')
    else :
        w.append('Not OK')
    a = input().strip().split()
for i in range(len(w)):
    print(w[i])

6430303721
# 1679098, 2022-11-12 09:52:22, --- (0%)

nation_team = {}
for e in range(int(input())):
    t,n = [e.strip() for e in input().split()]
    if n not in nation_team:
        nation_team[n] = []
    nation_team[n].append(t)
# 1679192, 2022-11-12 09:57:13, xxx (0%)

nation_team = {}
for e in range(int(input())):
    t,n = [e.strip() for e in input().split()]
    if n not in nation_team:
        nation_team[n] = []
    nation_team[n].append(t)

while True:
    x = input().split()
    i = []
    if x == 'q':
        break
    for e in x:
        for j in nation_team:
            if e in nation_team[j]:
                i.append(e)
                nation_team[j].pop(e)
    if len(i) != len(x):
        print('Not OK')
# 1679378, 2022-11-12 10:07:06, --- (0%)

nation_team = {}
for e in range(int(input())):
    t,n = [e.strip() for e in input().split()]
    if n not in nation_team:
        nation_team[n] = []
    nation_team[n].append(t)

while True:
    x = input().split()
    i = []
    if x[0] == 'q':
        break
    for e in x:
        for j in nation_team:
            if e in nation_team[j]:
                i.append(e)
    if len(i) != len(x):
        print('Not OK')
    else:
        print('OK')

     
        

# 1680114, 2022-11-12 10:42:14, PPP (100%)

nation_team = {}
for e in range(int(input())):
    t,n = [e.strip() for e in input().split()]
    if t not in nation_team:
        nation_team[t] = []
    nation_team[t].append(n)

while True:
    x = input().split()
    if x[0] == 'q': break
    team = []
    y = []
    for e in nation_team:
        for i in x:
            if e == i:
                team.append(i)
    if len(x) != len(team):
        print('Not OK')
    else:
        y = []
        z = 0
        for e in team:
            y.append(nation_team[e])
        y.sort()
        for e in range(len(y)-1):
            if y[e] == y[e+1]:
                z = 1
        if z == 1: print('Not OK')
        elif z == 0: print('OK')


6430382221
# 1679045, 2022-11-12 09:49:12, --- (0%)

a = {}
for i in range(int(input())):
    team , coun = input().split()
    a[team] = coun
b = []   
while True:
    c = []
    eli = input().split()
    if eli == ['q']: break
    for i in eli:
             
        if i in a:
            c.append(a[i])
    b.append(c)
print(b)
for i in b:
    z = True
    k = []
    for e in i:
        if e not in k:
            k.append(e)
    if k == i:
        print("OK")
    if k != i:
        print('Not OK')

# 1679049, 2022-11-12 09:49:25, PP- (67%)

a = {}
for i in range(int(input())):
    team , coun = input().split()
    a[team] = coun
b = []   
while True:
    c = []
    eli = input().split()
    if eli == ['q']: break
    for i in eli:
             
        if i in a:
            c.append(a[i])
    b.append(c)
for i in b:
    z = True
    k = []
    for e in i:
        if e not in k:
            k.append(e)
    if k == i:
        print("OK")
    if k != i:
        print('Not OK')
# 1679801, 2022-11-12 10:28:30, PP- (67%)

a = {}
for i in range(int(input())):
    team , coun = input().split()
    a[team] = coun
b = []   
while True:
    c = []
    eli = input().split()
    if eli == ['q']: break
    for i in eli:
        if i not in a:
            c.append('sus')
        if i in a:
            c.append(a[i])
    b.append(c)
for i in b:
    z = True
    k = []
    for e in i:
        if e == 'sus':
            print('Not OK')
            break
        if e not in k:
            k.append(e)
    if k == i:
        print("OK")
    if k != i:
        print('Not OK')
# 1679885, 2022-11-12 10:31:18, PPP (100%)

a = {}
for i in range(int(input())):
    team , coun = input().split()
    a[team] = coun
b = []   
while True:
    c = []
    eli = input().split()
    if eli == ['q']: break
    for i in eli:
        if i not in a:
            c.append('sus')
        if i in a:
            c.append(a[i])
    b.append(c)
for i in b:
    z = True
    k = []
    for e in i:
        if e == 'sus':
            k.append('sus')
            k.append('sus')
        if e not in k:
            k.append(e)
    if k == i:
        print("OK")
    if k != i:
        print('Not OK')


6531407621
# 1678868, 2022-11-12 09:38:53, xxx (0%)

t = {}
for i  in range(int(input())):
    x = input().split()
    t[x[0]] = x[1]
print(g)      
inp = input().split()
while inp == "q":
    
        l = []
        for e in inp:
            if e in t:
                l.append(t[e])
            else:
                l.append("no")
        print(l)
    
        if "no" in l or len(set(l)) < len(inp):
            print("Not OK")
        else:
            print("OK")
        inp = input().split()

# 1678874, 2022-11-12 09:39:22, --- (0%)

t = {}
for i  in range(int(input())):
    x = input().split()
    t[x[0]] = x[1]
    
inp = input().split()
while inp == "q":
    
        l = []
        for e in inp:
            if e in t:
                l.append(t[e])
            else:
                l.append("no")
    
        if "no" in l or len(set(l)) < len(inp):
            print("Not OK")
        else:
            print("OK")
        inp = input().split()
# 1678965, 2022-11-12 09:44:50, --- (0%)

t = {}
for i  in range(int(input())):
    x = input().split()
    t[x[0]] = x[1]
print(t)
inp = input().split()
while inp[0] != "q":
    l = []
    for e in inp:
        if e in t:
            l.append(t[e])
        else:
            l.append("no")
    print(l)
    if "no" in l or len(set(l)) < len(inp):
        print("Not OK")
    else:
        print("OK")
    inp = input().split()

# 1678987, 2022-11-12 09:46:34, PPP (100%)

t = {}
for i  in range(int(input())):
    x = input().split()
    t[x[0]] = x[1]

inp = input().split()
while inp[0] != "q":
    l = []
    for e in inp:
        if e in t:
            l.append(t[e])
        else:
            l.append("no")
    
    if "no" in l or len(set(l)) < len(inp):
        print("Not OK")
    else:
        print("OK")
    inp = input().split()

6530039121
# 1679600, 2022-11-12 10:19:41, --- (0%)

n=int(input())
team={}
country=[]
for i in range(n):
    club_name,club_country=input().split()
    team[club_name]=club_country
    country.append(club_name)

s=[]
for e in input().split():
    s.append(e)
while s[0]!='q':
    country=[]
    check=True
    for i in s:
        if i not in country:
            check=False
        else:
            country.append(team[i])
    if len(country)== len(set(country)) and check==True:
        print('OK')
    else:
        print('Not OK')
    s=[]
    for e in input().split():
        s.append(e)

# 1679997, 2022-11-12 10:37:04, --- (0%)

n=int(input())
team={}
country=[]
for i in range(n):
    club_name,club_country=input().split()
    team[club_name]=club_country
    country.append(club_name)

s=[]
for e in input().split():
    s.append(e)
while s[0]!='q':
    c=[]
    check=True
    for i in s:
        if i not in country:
            check=False
        else:
            country.append(team[i])
    if len(c)== len(set(c)) and check==True:
        print('OK')
    else:
        print('Not OK')
    s=[e for e in input().split()]   

# 1680162, 2022-11-12 10:44:30, PPP (100%)

n=int(input())
team={}
FC=[]
for i in range(n):
    x=input().split()
    club_name=x[0]
    club_country=x[1]
    team[club_name]=club_country
    FC.append(club_name)
s=[]
for e in input().split():
    s.append(e)
while s[0]!='q':
    c=[]
    check=True
    for i in s:
        if i not in FC:
            check=False
        else:
            c.append(team[i])
    if len(c)== len(set(c)) and check==True:
        print('OK')
    else:
        print('Not OK')
    s=[]
    for e in input().split():
        s.append(e) 


# 1680894, 2022-11-12 11:12:59, PPP (100%)

n=int(input())
FC=[]
team={}
for i in range(n):
    x=input().split()
    club_name=x[0].strip()
    club_country=x[1].strip()
    team[club_name]=club_country
    FC.append(club_name)
s=[]
for k in input().split():
    s.append(k)
while s[0]!='q':
    c=[]
    check=True
    for i in s:
        if i not in FC:
            check=False
        else:
            c.append(team[i])
    if len(c)== len(set(c)) and check==True:
        print('OK')
    else:
        print('Not OK')
    s=[]
    for k in input().split():
        s.append(k) 



6530052221
# 1679641, 2022-11-12 10:21:43, xxx (0%)

n = int(input())
d = {}
l = []
c = []
for i in range(n):
    t = input().split()
    d[t[0]] = t[1]
    t = []
s = input().split()
while s != "q":
    l = []
    c = []
    for e in s:
        if e not in d:
            print("Not OK")
            break
        else:
            l.append(d[e])
    for f in l:
        if f not in c:
            c.append(f)
    if len(c) == len(s):
        print("OK")
    else:
        print("Not OK")
    s = input().split()

# 1679688, 2022-11-12 10:23:23, xxx (0%)

n = int(input())
d = {}
l = []
c = []
for i in range(n):
    t = input().split()
    d[t[0]] = t[1]
    t = []
s = input().split()
while s != "q":
    l = []
    c = []
    for e in s:
        if e not in d:
            break
        else:
            l.append(d[e])
    for f in l:
        if f not in c:
            c.append(f)
    if len(c) == len(s):
        print("OK")
    else:
        print("Not OK")
    s = input().split()
# 1679797, 2022-11-12 10:28:20, xxx (0%)

n = int(input())
d = {}
l = []
c = []
ans = []
for i in range(n):
    t = input().split()
    d[t[0]] = t[1]
    t = []
s = input().split()
while s != "q":
    l = []
    c = []
    for e in s:
        if e not in d:
            break
        else:
            l.append(d[e])
    for f in l:
        if f not in c:
            c.append(f)
    if len(c) == len(s):
        ans.append("OK")
    else:
        ans.append("Not OK")
    s = input().split()
for g in ans:
    print(g)
# 1679950, 2022-11-12 10:34:44, PPP (100%)

n = int(input())
d = {}
l = []
c = []
ans = []
for i in range(n):
    t = input().split()
    d[t[0]] = t[1]
    t = []
s = input().split()
while s != ["q"]:
    l = []
    c = []
    for e in s:
        if e not in d:
            break
        else:
            l.append(d[e])
    for f in l:
        if f not in c:
            c.append(f)
    if len(c) == len(s):
        ans.append("OK")
    else:
        ans.append("Not OK")
    s = input().split()
for g in ans:
    print(g)

6530054521
# 1679215, 2022-11-12 09:58:50, --- (0%)

#822678
p={}
k=[]
n=int(input())
for i in range(n):
    x,y=input().strip().split()
    if y not in p:
        p[x]=y
    else:
        p[x]+=y
m=input()
b=0
ans=[]
ans1={}
b=''
while m!='q':
    k=[]
    o=m.strip().split()
    for e in o:
        if e in p:
            k.append(p[e])
        else:
            k.append('Not_f')
    k.sort()
    print(k)
    while (b!='OK')and(b!='Not OK'):
        for i in range(1,len(k)):
            if k[i-1]=='Not_f':
                ans.append('Not OK')
                b='Not OK'
                break
            elif k[i-1]==k[i]:
                ans.append('Not OK')
                b='Not OK'
                break
            else:
                pass
        if b=='':
            b='OK'
            ans.append('OK')
    b=''
    m=input()
for e in ans:
    print(e)

# 1679246, 2022-11-12 10:00:42, --- (0%)

#822678
p={}
k=[]
n=int(input())
for i in range(n):
    x,y=input().strip().split()
    if y not in p:
        p[x]=y
    else:
        p[x]+=y
m=input()
b=0
ans=[]
ans1=''
b=''
while m!='q':
    k=[]
    o=m.strip().split()
    for e in o:
        if e in p:
            k.append(p[e])
        else:
            k.append('Not_f')
    k.sort()
    print(k)
    while (b!='OK')and(b!='Not OK'):
        for i in range(1,len(k)):
            if k[i-1]=='Not_f':
                ans.append('Not OK')
                b='Not OK'
                break
            elif k[i-1]==k[i]:
                ans.append('Not OK')
                b='Not OK'
                break
            else:
                pass
        if b=='':
            b='OK'
            ans.append('OK')
    b=''
    m=input()
for e in ans:
    ans1+=e+'\n'
print(ans1.strip())

# 1679259, 2022-11-12 10:01:11, --- (0%)

#822678
p={}
k=[]
n=int(input().strip())
for i in range(n):
    x,y=input().strip().split()
    if y not in p:
        p[x]=y
    else:
        p[x]+=y
m=input().strip()
b=0
ans=[]
ans1=''
b=''
while m!='q':
    k=[]
    o=m.strip().split()
    for e in o:
        if e in p:
            k.append(p[e])
        else:
            k.append('Not_f')
    k.sort()
    print(k)
    while (b!='OK')and(b!='Not OK'):
        for i in range(1,len(k)):
            if k[i-1]=='Not_f':
                ans.append('Not OK')
                b='Not OK'
                break
            elif k[i-1]==k[i]:
                ans.append('Not OK')
                b='Not OK'
                break
            else:
                pass
        if b=='':
            b='OK'
            ans.append('OK')
    b=''
    m=input().strip()
for e in ans:
    ans1+=e+'\n'
print(ans1.strip())

# 1679265, 2022-11-12 10:01:32, PPP (100%)

#822678
p={}
k=[]
n=int(input().strip())
for i in range(n):
    x,y=input().strip().split()
    if y not in p:
        p[x]=y
    else:
        p[x]+=y
m=input().strip()
b=0
ans=[]
ans1=''
b=''
while m!='q':
    k=[]
    o=m.strip().split()
    for e in o:
        if e in p:
            k.append(p[e])
        else:
            k.append('Not_f')
    k.sort()

    while (b!='OK')and(b!='Not OK'):
        for i in range(1,len(k)):
            if k[i-1]=='Not_f':
                ans.append('Not OK')
                b='Not OK'
                break
            elif k[i-1]==k[i]:
                ans.append('Not OK')
                b='Not OK'
                break
            else:
                pass
        if b=='':
            b='OK'
            ans.append('OK')
    b=''
    m=input().strip()
for e in ans:
    ans1+=e+'\n'
print(ans1.strip())


6530085021
# 1679104, 2022-11-12 09:52:51, --- (0%)

n = int(input())
dic = {}
for i in range(n):
    t,c = input().split()
    if c in dic:
        dic[c].add(t)
    else:
        dic[c] = {t}
se = set()
for i in dic:
    se = se.union(dic[i])
l = input().split()
while l[0] != "q":
    p = True
    l = set(l)
    for i in dic:
        if len(dic[i].intersection(l)) != 1 and len(dic[i].intersection(l)) != 0:
            p = False
    for j in l:
        if j not in se:
            p = False
    if p == True:
        print("Ok")
    else:
        print("Not OK")
    l = input().split()
# 1679162, 2022-11-12 09:55:49, --- (0%)

n = int(input())
dic = {}
for i in range(n):
    t,c = input().split()
    if c in dic:
        dic[c].add(t)
    else:
        dic[c] = {t}
se = set()
for i in dic:
    se = se.union(dic[i])
l = input().split()
lis = []
while l[0] != "q":
    p = True
    l = set(l)
    for i in dic:
        if len(dic[i].intersection(l)) != 1 and len(dic[i].intersection(l)) != 0:
            p = False
    for j in l:
        if j not in se:
            p = False
    if p == True:
        lis.append("ok")
    else:
        lis.append("not ok")
    l = input().split()
for j in lis:
    print(j)
# 1679174, 2022-11-12 09:56:18, --- (0%)

n = int(input())
dic = {}
for i in range(n):
    t,c = input().split()
    if c in dic:
        dic[c].add(t)
    else:
        dic[c] = {t}
se = set()
for i in dic:
    se = se.union(dic[i])
l = input().split()
lis = []
while l[0] != "q":
    p = True
    l = set(l)
    for i in dic:
        if len(dic[i].intersection(l)) != 1 and len(dic[i].intersection(l)) != 0:
            p = False
    for j in l:
        if j not in se:
            p = False
    if p == True:
        lis.append("Ok")
    else:
        lis.append("Not Ok")
    l = input().split()
for j in lis:
    print(j)
# 1679184, 2022-11-12 09:56:53, PPP (100%)

n = int(input())
dic = {}
for i in range(n):
    t,c = input().split()
    if c in dic:
        dic[c].add(t)
    else:
        dic[c] = {t}
se = set()
for i in dic:
    se = se.union(dic[i])
l = input().split()
lis = []
while l[0] != "q":
    p = True
    l = set(l)
    for i in dic:
        if len(dic[i].intersection(l)) != 1 and len(dic[i].intersection(l)) != 0:
            p = False
    for j in l:
        if j not in se:
            p = False
    if p == True:
        lis.append("OK")
    else:
        lis.append("Not OK")
    l = input().split()
for j in lis:
    print(j)

6530098121
# 1679233, 2022-11-12 09:59:53, --- (0%)

numofteam = int(input())
team_country = {}
for i in range(numofteam):
    team,country = input().split()
    team_country[team] = country

group = input().split()
group_c1 = []
group_c2 = set()
while group[0] != "q":
    for i in group:
        if i not in team_country:
            print("Not OK")
        else:
            group_c1.append(team_country[i])
            group_c2.add(team_country[i])
    a = 0
    for i in group_c2:
        a+=1
    if len(group_c1) != a:
        print("Not OK")
        break
    elif len(group_c1) == a:
        print("OK")
        break
    group = input().split()
# 1679366, 2022-11-12 10:06:30, --- (0%)

numofteam = int(input())
team_country = {}
for i in range(numofteam):
    team,country = input().split()
    team_country[team] = country

group = input().split()
group_c1 = []
group_c2 = set()
while group[0] != "q":
    for i in group:
        if i not in team_country:
            print("Not OK")
        else:
            group_c1.append(team_country[i])
            group_c2.add(team_country[i])
    a = 0
    for i in group_c2:
        a+=1
    if len(group_c1) != a:
        print("Not OK")
    elif len(group_c1) == a:
        print("OK")
    group = input().split()
# 1679507, 2022-11-12 10:13:50, PP- (67%)

numofteam = int(input())
team_country = {}
for i in range(numofteam):
    team,country = input().split()
    team_country[team] = country

group = input().split()
while group[0] != "q":
    group_c1 = []
    group_c2 = set()
    for i in group:
        if i not in team_country:
            print("Not OK")
        else:
            group_c1.append(team_country[i])
            group_c2.add(team_country[i])
    a = 0
    for i in group_c2:
        a+=1
    if len(group_c1) != a:
        print("Not OK")
    elif len(group_c1) == a:
        print("OK")
    group = input().split()

# 1679709, 2022-11-12 10:23:54, PPP (100%)

numofteam = int(input())
team_country = {}
for i in range(numofteam):
    team,country = input().split()
    team_country[team] = country

group = input().split()
while group[0] != "q":
    group_c1 = []
    group_c2 = set()
    for i in group:
        if i not in team_country:
            print("Not OK")
        else:
            group_c1.append(team_country[i])
            group_c2.add(team_country[i])
    a = 0
    for i in group_c2:
        a+=1
    if len(group_c1)==len(group):
        if len(group_c1) != a:
            print("Not OK")
        elif len(group_c1) == a:
            print("OK")
    group = input().split()

6530100721
# 1679170, 2022-11-12 09:56:13, xxx (0%)

country = {}
n = int(input())
for i in range(n):
    team, c = input().split()
    country[team] = c

while True:
    x = input().split()
    if x == 'q': break
    unmatch = False
    for j in x:
        if j not in country:
                unmatch = True
        else:
            rep = country[j]
            for k in x:
                if k not in country:
                    unmatch = True
                elif country[k] == rep and k != j:
                    unmatch = True
    if unmatch == True:
        print('Not OK')
    else:
        print('OK')
# 1679198, 2022-11-12 09:57:40, xxx (0%)

country = {}
n = int(input())
for i in range(n):
    team, c = input().split()
    country[team] = c

while True:
    x = input().split()
    if x == 'q': False
    unmatch = False
    for j in x:
        if j not in country:
                unmatch = True
        else:
            rep = country[j]
            for k in x:
                if k not in country:
                    unmatch = True
                elif country[k] == rep and k != j:
                    unmatch = True
    if unmatch == True:
        print('Not OK')
    else:
        print('OK')
# 1679208, 2022-11-12 09:58:16, xxx (0%)

country = {}
n = int(input())
for i in range(n):
    team, c = input().split()
    country[team] = c

while True:
    x = input().split()
    if x == 'q': False
    unmatch = False
    for j in x:
        if j not in country:
            unmatch = True
        else:
            rep = country[j]
            for k in x:
                if k not in country:
                    unmatch = True
                elif country[k] == rep and k != j:
                    unmatch = True
    if unmatch == True:
        print('Not OK')
    else:
        print('OK')
# 1679248, 2022-11-12 10:00:44, PPP (100%)

country = {}
n = int(input())
for i in range(n):
    team, c = input().split()
    country[team] = c

while True:
    x = input().split()
    if len(x) == 1 and x[0] =='q': break
    else:
        unmatch = False
        for j in x:
            if j not in country:
                unmatch = True
            else:
                rep = country[j]
                for k in x:
                    if k not in country:
                        unmatch = True
                    elif country[k] == rep and k != j:
                        unmatch = True
        if unmatch == True:
            print('Not OK')
        else:
            print('OK')

6530124821
# 1679478, 2022-11-12 10:12:45, xxx (0%)


allteam = {}
teamname = []
for i in range(n):
    a, b = input().split()
    allteam[a]=b
    teamname.append(a)

match = []
A = True
while A:
    a = input().split()
    if a != ['q']:
        match.append(a)
    else:
        A = False

        
out=[]
for e in match:
    for t in range(len(e)-1):
        for p in range(1,len(e)):
            if e[t] in teamname and e[p] in teamname:
                if allteam[e[t]] != allteam[e[p]]:
                    a = 'OK'
                else:
                    a = 'Not OK'
                    break
            else:
                a = 'Not OK'
                break
    out.append(a)
            
for i in range(len(out)):
    print(out[i])
# 1679488, 2022-11-12 10:13:08, P-- (33%)

n = int(input())

allteam = {}
teamname = []
for i in range(n):
    a, b = input().split()
    allteam[a]=b
    teamname.append(a)

match = []
A = True
while A:
    a = input().split()
    if a != ['q']:
        match.append(a)
    else:
        A = False

        
out=[]
for e in match:
    for t in range(len(e)-1):
        for p in range(1,len(e)):
            if e[t] in teamname and e[p] in teamname:
                if allteam[e[t]] != allteam[e[p]]:
                    a = 'OK'
                else:
                    a = 'Not OK'
                    break
            else:
                a = 'Not OK'
                break
    out.append(a)
            
for i in range(len(out)):
    print(out[i])

# 1680071, 2022-11-12 10:40:09, PP- (67%)

n = int(input())

allteam = {}
teamname = []
for i in range(n):
    a, b = input().split()
    allteam[a]=b
    teamname.append(a)
    

match = []
A = True
while A:
    a = input().split()
    if a != ['q']:
        match.append(a)
    else:
        A = False

        
out=[]
for e in match:
    for t in range(len(e)-1):
        if a == 'Not OK':
            break
        for p in range(t+1,len(e)):
            if e[t] not in teamname or e[p] not in teamname:
                a = 'Not OK'
                break
            else:
                if allteam[e[t]] == allteam[e[p]]:
                    a = 'Not OK'
                    break
                else:
                    a = 'OK'
    out.append(a)
            
for i in range(len(out)):
    print(out[i])

# 1680339, 2022-11-12 10:52:50, PPP (100%)

n = int(input())

allteam = {}
teamname = []
for i in range(n):
    a, b = input().split()
    allteam[a]=b
    teamname.append(a)
    

match = []
A = True
while A:
    a = input().split()
    if a != ['q']:
        match.append(a)
    else:
        A = False

        
out=[]
for e in match:
    for t in range(len(e)-1):
        for p in range(t+1,len(e)):
            if e[t] not in teamname or e[p] not in teamname:
                a = 'Not OK'
                break
            else:
                if allteam[e[t]] == allteam[e[p]]:
                    a = 'Not OK'
                    break
                else:
                    a = 'OK'
        if a == 'Not OK':
            break
    out.append(a)
            
for i in range(len(out)):
    print(out[i])


6530141421
# 1678531, 2022-11-12 09:20:57, --- (0%)

tdic = {}
for i in range(int(input())):
    team,country = input().strip().split()
    if country not in tdic: tdic[team] = [country]
    else: tdic[team].append(country)
while True:
    x = input().strip()
    if x == "q": break
    tlist = x.split()
    check = []
    c = 0
    for e in tlist:
        if e not in tdic:
            c = -1
            print("NOT OK")
            break
        if tdic[e] not in check: check.append(tdic[e])
        else:
            print("NOT OK")
            c = -1
            break
    if c != -1:
        print("OK")
# 1678551, 2022-11-12 09:22:17, --- (0%)

tdic = {}; ans = []
for i in range(int(input())):
    team,country = input().strip().split()
    if country not in tdic: tdic[team] = [country]
    else: tdic[team].append(country)
while True:
    x = input().strip()
    if x == "q": break
    tlist = x.split()
    check = []
    c = 0
    for e in tlist:
        if e not in tdic:
            c = -1
            ans.append("NOT OK")
            break
        if tdic[e] not in check: check.append(tdic[e])
        else:
            ans.append("NOT OK")
            c = -1
            break
    if c != -1:
        ans.append("OK")
print("\n".join(ans))
# 1678557, 2022-11-12 09:22:41, PPP (100%)

tdic = {}; ans = []
for i in range(int(input())):
    team,country = input().strip().split()
    if country not in tdic: tdic[team] = [country]
    else: tdic[team].append(country)
while True:
    x = input().strip()
    if x == "q": break
    tlist = x.split()
    check = []
    c = 0
    for e in tlist:
        if e not in tdic:
            c = -1
            ans.append("Not OK")
            break
        if tdic[e] not in check: check.append(tdic[e])
        else:
            ans.append("Not OK")
            c = -1
            break
    if c != -1:
        ans.append("OK")
print("\n".join(ans))
# 1681123, 2022-11-12 11:19:31, PPP (100%)

tdic = {}
for i in range(int(input())):
    team,country = input().strip().split()
    if country not in tdic: tdic[team] = [country]
    else: tdic[team].append(country)
while True:
    x = input().strip()
    if x == "q": break
    tlist = x.split()
    check = []
    c = 0
    for e in tlist:
        if e not in tdic:
            c = -1
            print("Not OK")
            break
        if tdic[e] not in check: check.append(tdic[e])
        else:
            print("Not OK")
            c = -1
            break
    if c != -1:
        print("OK")

6530142021
# 1679425, 2022-11-12 10:10:12, --- (0%)

d_team_pt = {}
d_pt_teams = {}
for k in range(int(input())):
    team,pt = input().split()
    if team not in d_team_pt:
        d_team_pt[team] = pt
#     else:
#         d_team_pt[team].add(pt)
    if pt not in d_pt_teams:
        d_pt_teams[pt] = {team}
    else:
        d_pt_teams[pt].add(team)
print(d_team_pt)
print(d_pt_teams)
while True:
    teams = input()
    if teams == 'q':
        break
    team = teams.split()
    ans = set()
    for t in team:
        if t in d_team_pt:
            ans.add(d_team_pt[t])
#         else:
#             ans.add('5')
    if len(ans) != len(team):
        print('Not OK')
    elif len(team) == len(ans):
        print('OK')
# 1679487, 2022-11-12 10:13:04, --- (0%)

d_team_pt = {}
d_pt_teams = {}
for k in range(int(input())):
    team,pt = input().split()
    if team not in d_team_pt:
        d_team_pt[team] = pt
#     else:
#         d_team_pt[team].add(pt)
    if pt not in d_pt_teams:
        d_pt_teams[pt] = {team}
    else:
        d_pt_teams[pt].add(team)
print(d_team_pt)
print(d_pt_teams)
while True:
    teams = input()
    if teams == 'q':
        break
    team = teams.split()
    ans = set()
    for t in team:
        if t in d_team_pt:
            ans.add(d_team_pt[t])
#         else:
#             ans.add('5')
    if len(ans) != len(team):
        print('Not OK')
    else:
        print('OK')
# 1679502, 2022-11-12 10:13:37, --- (0%)

d_team_pt = {}
d_pt_teams = {}
for k in range(int(input())):
    team,pt = input().split()
    if team not in d_team_pt:
        d_team_pt[team] = pt

    if pt not in d_pt_teams:
        d_pt_teams[pt] = {team}
    else:
        d_pt_teams[pt].add(team)
print(d_team_pt)
print(d_pt_teams)
while True:
    teams = input()
    if teams == 'q':
        break
    team = teams.split()
    ans = set()
    for t in team:
        if t in d_team_pt:
            ans.add(d_team_pt[t])

    if len(ans) != len(team):
        print('Not OK')
    else:
        print('OK')
# 1679564, 2022-11-12 10:17:16, PPP (100%)

d_team_pt = {}
for k in range(int(input())):
    team,pt = input().split()
    if team not in d_team_pt:
        d_team_pt[team] = pt

   

while True:
    teams = input()
    if teams == 'q':
        break
    team = teams.split()
    ans = set()
    for t in team:
        if t in d_team_pt:
            ans.add(d_team_pt[t])

    if len(ans) != len(team):
        print('Not OK')
    else:
        print('OK')

6530205021
# 1679051, 2022-11-12 09:49:42, --- (0%)

'''
good_LUCK
'''
contr = {}
for i in range(int(input())) :
    a = input().split()
    contr[a[0]] = a[1] 
        
print(contr)

s = True
while True :
    check = {}
    a = input().split()
    if len(a) == 1 :
        break
    for i in a :
        if i not in contr :
            check[i] = 20
        else :
            if contr[i] in check :
                check[contr[i]] += 1
            else :
                check[contr[i]] = 1
    for i in check :
        if check[i] > 1 :
            s = False
            break
    if s == True :
        print("OK")
    else :
        print("Not OK")
        
        
            
                
                
               

# 1679061, 2022-11-12 09:50:03, PP- (67%)

'''
good_LUCK
'''
contr = {}
for i in range(int(input())) :
    a = input().split()
    contr[a[0]] = a[1] 
        


s = True
while True :
    check = {}
    a = input().split()
    if len(a) == 1 :
        break
    for i in a :
        if i not in contr :
            check[i] = 20
        else :
            if contr[i] in check :
                check[contr[i]] += 1
            else :
                check[contr[i]] = 1
    for i in check :
        if check[i] > 1 :
            s = False
            break
    if s == True :
        print("OK")
    else :
        print("Not OK")
        
        
            
                
                
               

# 1679149, 2022-11-12 09:55:02, --- (0%)

'''
good_LUCK
'''
contr = {}
for i in range(int(input())) :
    a = input().split()
    contr[a[0]] = a[1] 
        


while True :
    s = True
    check = {}
    a = input().split()
    if len(a) == 1 :
        break
    for i in a :
        if i not in contr :
            check[i] = 20
        else :
            if contr[i] in check :
                check[contr[i]] += 1
            else :
                check[contr[i]] = 1
    print(check)
    for i in check :
        if check[i] > 1 :
            s = False
            break
    if s == True :
        print("OK")
    else :
        print("Not OK")
        
        
            
                
                
               

# 1679152, 2022-11-12 09:55:17, PPP (100%)

'''
good_LUCK
'''
contr = {}
for i in range(int(input())) :
    a = input().split()
    contr[a[0]] = a[1] 
        


while True :
    s = True
    check = {}
    a = input().split()
    if len(a) == 1 :
        break
    for i in a :
        if i not in contr :
            check[i] = 20
        else :
            if contr[i] in check :
                check[contr[i]] += 1
            else :
                check[contr[i]] = 1
    
    for i in check :
        if check[i] > 1 :
            s = False
            break
    if s == True :
        print("OK")
    else :
        print("Not OK")
        
        
            
                
                
               


6531338021
# 1678794, 2022-11-12 09:35:07, xxx (0%)

d = {}
for tc in range(int(input())):
    t, c = input().split()
    d[t] = c

while True:
    l1 = []
    l2 = []
    x = input().split()
    if x == "q" : break
    for i in x:
        l1.append(d[i])
    for j in l1:
        if j not in l2:
            l2.append(j)
    
    if len(l1) != len(l2):
        print("Not OK")
    elif len(l1) == len(l2) :
        print("OK")
    
    

# 1679524, 2022-11-12 10:14:48, --- (0%)

d = {}
for tc in range(int(input())):
    t, c = input().split()
    d[t] = c
print(d)
ch = []

while True:
    l1 = []
    l2 = []
    x = input()
    if x == "q": break
    x = x.split()
    for i in x:
        if i not in d.keys():
            l1.append("NF")
        else:
            l1.append(d[i])
    for j in l1:
        if j not in l2:
            l2.append(j)
    if "NF" in l1:
        ch.append("Not OK")
    elif len(l1) != len(l2):
        ch.append("Not OK")
    elif len(l1) == len(l2):
        ch.append("OK")

for i in range(len(ch)):
    print(ch[i])
    
    

# 1679535, 2022-11-12 10:15:27, --- (0%)

d = {}
for tc in range(int(input())):
    t, c = input().split()
    d[t] = c
print(d)
# ch = []

while True:
    l1 = []
    l2 = []
    x = input()
    if x == "q": break
    x = x.split()
    for i in x:
        if i not in d.keys():
            l1.append("NF")
        else:
            l1.append(d[i])
    for j in l1:
        if j not in l2:
            l2.append(j)
    if "NF" in l1:
        print("Not OK")
    elif len(l1) != len(l2):
        print("Not OK")
    elif len(l1) == len(l2):
        print("OK")

    
    

# 1679551, 2022-11-12 10:16:20, PPP (100%)

d = {}
for tc in range(int(input())):
    t, c = input().split()
    d[t] = c
# print(d)
# ch = []

while True:
    l1 = []
    l2 = []
    x = input()
    if x == "q": break
    x = x.split()
    for i in x:
        if i not in d.keys():
            l1.append("NF")
        else:
            l1.append(d[i])
    for j in l1:
        if j not in l2:
            l2.append(j)
    if "NF" in l1:
        print("Not OK")
    elif len(l1) != len(l2):
        print("Not OK")
    elif len(l1) == len(l2):
        print("OK")

    
    


6531021021
# 1679375, 2022-11-12 10:06:59, --- (0%)

n=int(input())
teamlist={}
teamset=[]
for i in range(n):
    teamset=input().split( )
    teamlist[teamset[0]]=teamset[1]
    teamset=[]
# print(teamlist)
m=[]

while not 'q' in m :
    m.append(input())
#print(m)
    for i in range(len(m)):
        if m[i]!= 'q' :
            x=m[i].split( )
            #for j in range(len(x)):
    #print(x)
    for j in range(len(x)):
        if x[j] in teamlist :
            #if teamlist[x[j]] != teamlist[x[j:len(x)]]:
                print('OK')
        else:
            print('Not OK')
                

# 1679692, 2022-11-12 10:23:29, --- (0%)

n=int(input())
teamlist={}
teamset=[]
for i in range(n):
    teamset=input().split( )
    teamlist[teamset[0]]=teamset[1]
    teamset=[]
# print(teamlist)
m=[]
z=[]
while not 'q' in m :
    m.append(input())
m.remove('q')
#print(m)
for i in range(len(m)):
    if m[i]!= 'q' :
       x=m[i].split( )
            #for j in range(len(x)):
    #print(x)
    for j in range(len(x)):
        if x[j] in teamlist :
            #if teamlist[x[j]] != teamlist[x[j:len(x)]]:
            z.append('T')
        else:
            z.append('F')
    if not 'F' in z:
        print('OK')
    if 'F' in z:
        print('Not OK')

                

# 1680270, 2022-11-12 10:50:07, --- (0%)

n=int(input())
teamlist={}
teamset=[]
for i in range(n):
    teamset=input().split( )
    teamlist[teamset[0]]=teamset[1]
    teamset=[]
# print(teamlist)
m=[]
z=[]
check=[]
l=[]
while not 'q' in m :
    m.append(input())
m.remove('q')
#print(m)
for i in range(len(m)):
    if m[i]!= 'q' :
       x=m[i].split( )
            #for j in range(len(x)):
    #print(x)   
    for j in range(len(x)):
        if x[j] in teamlist:
            check.append(teamlist[x[j]])
            check2=check
    print(check2)
    for k in range(len(check)):
        l.append(check[k])
        check2.remove(check[k])
        #print(check[k])
        if (x[j] in teamlist) :#and (check[k] not in [check2]):    
            z.append('T')
        if (x[j] not in teamlist) :
            z.append('F')
        check2.append(l)
        #print(check2)
        
    if not 'F' in z:
        print('OK')
    if 'F' in z:
        print('Not OK')
    check=[]

                

# 1681026, 2022-11-12 11:16:58, PPP (100%)

n=int(input())
teamlist={}
teamset=[]
for i in range(n):
    teamset=input().split( )
    teamlist[teamset[0]]=teamset[1]
    teamset=[]
# print(teamlist)
m=[]
z=[]
check=[]
check2=[]
l=[]
while not 'q' in m :
    m.append(input())
m.remove('q')
#print(m)
for i in range(len(m)):
    if m[i]!= 'q' :
       x=m[i].split( )
            #for j in range(len(x)):
    #print(x)   
    for j in range(len(x)):
        if x[j] in teamlist:
            check.append(teamlist[x[j]])
            check2.append(teamlist[x[j]])
    #print(check2)
    #for j in range(len(x)):
        if x[j] not in teamlist:
            z.append('F')
    for k in range(len(check)):
            #print(check[k])
            l.append(check[k])
            check2.remove(check[k])
            #print(check[k])
            #print(check2)
            if (check[k] not in check2):    
                z.append('T')
#             if (x[j] not in teamlist) :
#                 z.append('F')
            if check[k] in check2:
                z.append('F')
            check2.append(l)
            l=[]
            #print(z)
        #print(check2)
        
    if not 'F' in z:
        print('OK')
    if 'F' in z:
        print('Not OK')
    z=[]
    check=[]
    check2=[]

                


6531807021
# 1678924, 2022-11-12 09:42:38, --- (0%)

n = int(input())
#dict key=ทีม value=ประเทศ
d = {}
for i in range(n):
    team,country = input().split(" ")
    d[team] = country
#print(d)
#d = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany',
#'Dortmund': 'Germany', 'Barcelona': 'Spain','Milan': 'Italy', 'PSG': 'France',
#'Ajax': 'Holland', 'Real': 'Spain', 'Celtic': 'Scotland'}
#-------------------------------
#สร้างgroup
group = input().strip()
while group != 'q':
    group2 = []
    group1 = group.split(" ")
    print(group1) #group1 = ['Liverpool', 'Barcelona', 'PSG', 'Real\r']
    for i in group1:
        if i in d:
            group2.append(d[i])
        else:
            group2.append('omg')
    #print(group2)
    c = 0
    for e in group2:
        c = group2.count(e)
    if c==1:
        print('OK')
    else:
        print('Not OK')

    group = input().strip()
# 1679166, 2022-11-12 09:56:00, --- (0%)

n = int(input())
#dict key=ทีม value=ประเทศ
d = {}
for i in range(n):
    team,country = input().split(" ")
    d[team] = country
#print(d)
d = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany',
'Dortmund': 'Germany', 'Barcelona': 'Spain','Milan': 'Italy', 'PSG': 'France',
'Ajax': 'Holland', 'Real': 'Spain', 'Celtic': 'Scotland'}
#-------------------------------
#สร้างgroup
group = input().strip()
while group != 'q':
    group2 = []
    group1 = group.split(" ")
    #print(group1) #group1 = ['Liverpool', 'Barcelona', 'PSG', 'Real\r']
    for i in group1:
        if i in d:
            group2.append(d[i])
        else:
            group2.append('omg')
    print(group2)
    c = 0
    d = {}
    for e in group2:
        c = group2.count(e)
        d[e] = c
    #print(d)
    oh = []
    for i in d:
        if d[i] == 1 and i!='omg':
            oh.append('OK')
        else:
            oh.append('Not OK')
    #print(oh)
    a = oh.count('Not OK')
    if a>=1:
        print('Not OK')
    else:
        print('OK')

    group = input().strip()
# 1679179, 2022-11-12 09:56:46, --- (0%)

n = int(input())
#dict key=ทีม value=ประเทศ
d = {}
for i in range(n):
    team,country = input().split(" ")
    d[team] = country
#print(d)
d = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany',
'Dortmund': 'Germany', 'Barcelona': 'Spain','Milan': 'Italy', 'PSG': 'France',
'Ajax': 'Holland', 'Real': 'Spain', 'Celtic': 'Scotland'}
#-------------------------------
#สร้างgroup
group = input().strip()
while group != 'q':
    group2 = []
    group1 = group.split(" ")
    #print(group1) #group1 = ['Liverpool', 'Barcelona', 'PSG', 'Real\r']
    for i in group1:
        if i in d:
            group2.append(d[i])
        else:
            group2.append('omg')
    #print(group2)
    c = 0
    d = {}
    for e in group2:
        c = group2.count(e)
        d[e] = c
    #print(d)
    oh = []
    for i in d:
        if d[i] == 1 and i!='omg':
            oh.append('OK')
        else:
            oh.append('Not OK')
    #print(oh)
    a = oh.count('Not OK')
    if a>=1:
        print('Not OK')
    else:
        print('OK')

    group = input().strip()
# 1679505, 2022-11-12 10:13:45, PPP (100%)

n = int(input())
#dict key=ทีม value=ประเทศ
d = {}
for i in range(n):
    team,country = input().strip().split(" ")
    d[team] = country
#print(d)
#d = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany',
#'Dortmund': 'Germany', 'Barcelona': 'Spain','Milan': 'Italy', 'PSG': 'France',
#'Ajax': 'Holland', 'Real': 'Spain', 'Celtic': 'Scotland'}
#-------------------------------
#สร้างgroup
group = input().strip()
while group != 'q':
    group2 = []
    group1 = group.split(" ")
    #print(group1) #group1 = ['Liverpool', 'Barcelona', 'PSG', 'Real\r']
    for i in group1:
        if i in d:
            group2.append(d[i])
        else:
            group2.append('omg')
    #print(group2)
    c = 0
    h = {}
    for e in group2:
        c = group2.count(e)
        h[e] = c
    #print(d)
    oh = []
    for i in h:
        if h[i] == 1 and i!='omg':
            oh.append('OK')
        else:
            oh.append('Not OK')
    #print(oh)
    a = oh.count('Not OK')
    if a>=1:
        print('Not OK')
    else:
        print('OK')
    group = input().strip()

6230148621
# 1678891, 2022-11-12 09:40:38, --- (0%)

n = int(input())
d = {}
for i in range(n):
    a,b = input().split()
    if a in d:
        d[a].append(b)
    else:
        d[a] = [b]
teams = input()

def check_team(teams):
    teams = teams.split()
    for i in range(len(teams)):
        if teams[i] in d:
            for j in range(len(teams)):
                if teams[i] != teams[j] and teams[j] in d[teams[i]]:
                    return False
    return True
    
while(teams != 'q'):
    if check_team(teams):
        print('OK')
    else:
        print('Not OK')
    teams = input()
# 1679105, 2022-11-12 09:52:55, PPP (100%)

n = int(input())
d = {}
for i in range(n):
    a,b = input().split()
    if a in d:
        pass
    else:
        d[a] = b
teams = input()
def check_team(teams):
    teams = teams.split()
    for i in range(len(teams)):
        if teams[i] in d:
            for j in range(len(teams)):
                if not teams[j] in d: return False
                if i != j and d[teams[j]] == d[teams[i]]:
                    return False
    return True
    
while(teams != 'q'):
    if check_team(teams):
        print('OK')
    else:
        print('Not OK')
    teams = input()
# 1679491, 2022-11-12 10:13:17, PPP (100%)

n = int(input())
d = {}
for i in range(n):
    a,b = input().split()
    if a in d:
        pass
    else:
        d[a] = b
teams = input()
def check_team(teams):
    teams = teams.split()
    for i in range(len(teams)):
        if teams[i] in d:
            for j in range(len(teams)):
                if not teams[j] in d:
                    return False
                if i != j and d[teams[j]] == d[teams[i]]:
                    return False
    return True
    
while(teams != 'q'):
    if check_team(teams):
        print('OK')
    else:
        print('Not OK')
    teams = input()

6231010821
# 1678738, 2022-11-12 09:31:59, PPP (100%)

n = int(input())
country_dict = dict()
for i in range(n):
    text = input()
    team, country = text.split()
    country_dict[team] = country
while(True):
    text = input()
    if text == "q":
        break
    country_set = set()
    ok = True
    for team in text.split():
        if team not in country_dict:
            ok = False
            break
        if country_dict[team] in country_set:
            ok = False
            break
        country_set.add(country_dict[team])
    if ok:
        print("OK")
    else:
        print("Not OK")
# 1678937, 2022-11-12 09:43:34, PPP (100%)

n = int(input())
country_dict = dict()
for i in range(n):
    text = input()
    team, country = text.split()
    country_dict[team] = country
while(True):
    text = input()
    if text == "q":
        break
    country_set = set()
    ok = True
    for team in text.split():
        if team not in country_dict:
            ok = False
            break
        if country_dict[team] in country_set:
            ok = False
            break
        country_set.add(country_dict[team])
    if ok:
        print("OK")
    else:
        print("Not OK")
# 1679327, 2022-11-12 10:04:38, PPP (100%)

n = int(input())
country_dict = dict()
for i in range(n):
    text = input()
    team, country = text.split()
    country_dict[team] = country
while(True):
    text = input()
    if text == "q":
        break
    country_set = set()
    ok = True
    for team in text.split():
        if team not in country_dict:
            ok = False
            break
        if country_dict[team] in country_set:
            ok = False
            break
        country_set.add(country_dict[team])
    if ok:
        print("OK")
    else:
        print("Not OK")

6231718521
# 1679085, 2022-11-12 09:51:35, xxx (0%)

n=int(input())
database={}
check=[]
for i in range (n):
    x=input()
    city,country=x.split()
    database[city]=country
print(database)
m=input().split()
while m!= 'q':
    ans=[]
    for n in m:
        if n in database:
            ans.append(database[n])
    for o in ans:
        if o not in check:
            check.append(o)
    if len(check)==len(ans):
        print('OK')
    else:
        print('Not OK')
    m=input().split()




# 1679679, 2022-11-12 10:23:11, --- (0%)

n=int(input())
database={}
show=[]
for i in range (n):
    x=input()
    city,country=x.split()
    database[city]=country
print(database)
m=input()
while m!= 'q':
    m=m.split()
    ans=[]
    for n in m:
        if n in database:
            ans.append(database[n])
    print(ans)
    if len(m)==len(ans):
        check=[]
        for o in ans:
            if o not in check:
                check.append(o)
        print(check)
        if len(check)==len(ans):
            show.append('OK')
        else:
            show.append('Not OK')
    else:
        show.append('Not OK')
    m=input()
for x in show:
    print(x)







        

    

    


# 1679721, 2022-11-12 10:24:27, PPP (100%)

n=int(input())
database={}
show=[]
for i in range (n):
    x=input()
    city,country=x.split()
    database[city]=country
m=input()
while m!= 'q':
    m=m.split()
    ans=[]
    for n in m:
        if n in database:
            ans.append(database[n])
    if len(m)==len(ans):
        check=[]
        for o in ans:
            if o not in check:
                check.append(o)
        if len(check)==len(ans):
            show.append('OK')
        else:
            show.append('Not OK')
    else:
        show.append('Not OK')
    m=input()
for x in show:
    print(x)


6231120121
# 1680618, 2022-11-12 11:03:39, PPx (67%)

n = int(input())

Team = []
for i in range(n):
    team = input().split()
    Team.append(team)
Team_Data = {}
for e in Team:
    Team_Data[e[0]] = e[1] 


group = []
group = input().split()

while group[0] != 'q':
    Ok = True
    for i in range(len(group)) :
        for j in range(i+1,len(group)):
            if group[i] and group[j] in Team_Data :
                if Team_Data[group[i]] == Team_Data[group[j]]:
                    Ok = False
            else :
                Ok = False
            
    if Ok == False :
        print('Not OK')
    else:
        print('OK')
    group =input().split()
# 1681043, 2022-11-12 11:17:23, PPP (100%)

n = int(input())

Team = []
for i in range(n):
    team = input().split()
    Team.append(team)
Team_Data = {}
for e in Team:
    Team_Data[e[0]] = e[1] 


group = []
group = input().split()

while group[0] != 'q':
    Ok = True
    for i in range(len(group)) :
        for j in range(i+1,len(group)):
            if group[i]  in Team_Data and group[j]  in Team_Data:
                if Team_Data[group[i]] == Team_Data[group[j]]:
                    Ok = False
            else :
                Ok = False
            
    if Ok == False :
        print('Not OK')
    else:
        print('OK')
    group =input().split()
            
           
# 1681104, 2022-11-12 11:19:01, PPP (100%)

n = int(input())

Team = []
for i in range(n):
    team = input().split()
    Team.append(team)
Team_Data = {}
for e in Team:
    Team_Data[e[0]] = e[1] 


group = []
group = input().split()

while group[0] != 'q':
    Ok = True
    for i in range(len(group)) :
        for j in range(i+1,len(group)):
            if group[i]  in Team_Data and group[j]  in Team_Data:
                if Team_Data[group[i]] == Team_Data[group[j]]:
                    Ok = False
            else :
                Ok = False
            
    if Ok == False :
        print('Not OK')
    else:
        print('OK')
    group =input().split()

6431501821
# 1679252, 2022-11-12 10:01:03, --- (0%)

#{team : country,}
cp = {}
for i in range(int(input())):
    team,ct = input().strip().split(' ')
    cp[team] = ct

q = input()
check = []
out = []
k = True
while q != 'q':
    q = q.split(' ')
    for i in range(len(q)):
        if q[i] not in cp:
            cp[q[i]] = 0
    check.append(q)
    for i in range(len(check)): #4
        for j in range(len(check[i])): #วนแต่ละทีมใน1กลุ่ม
            if cp[check[i][j]] == 0:
                k = False
                
            for m in range(j+1,len(check[i])):
                if cp[check[i][j]] == cp[check[i][m]]:
                    k = False
    if k :
        out.append('OK')
    else:
        out.append('Not OK') 
                           
    q = input()
        
    





# 1679269, 2022-11-12 10:01:41, --- (0%)

#{team : country,}
cp = {}
for i in range(int(input())):
    team,ct = input().strip().split(' ')
    cp[team] = ct

q = input()
check = []
out = []
k = True
while q != 'q':
    q = q.split(' ')
    for i in range(len(q)):
        if q[i] not in cp:
            cp[q[i]] = 0
    check.append(q)
    for i in range(len(check)): #4
        for j in range(len(check[i])): #วนแต่ละทีมใน1กลุ่ม
            if cp[check[i][j]] == 0:
                k = False
                
            for m in range(j+1,len(check[i])):
                if cp[check[i][j]] == cp[check[i][m]]:
                    k = False
    if k :
        out.append('OK')
    else:
        out.append('Not OK') 
                           
    q = input()
    for e in out:
      print(e)
# 1681060, 2022-11-12 11:17:49, PPP (100%)

#{team : country,}
cp = {}
for i in range(int(input())):
    team,ct = input().strip().split(' ')
    cp[team] = ct

x = input()

out = []


while x != 'q':
    k = True
    y = x.strip().split(' ')
    for i in range(len(y)):
        if y[i] not in cp:
            cp[y[i]] = 0
    new = []
    for j in range(len(y)):
        new.append(cp[y[j]])
    for a in range(len(new)):
        for b in range(a+1,len(new)):
            if new[a] == new[b]:
                k = False
            if new[a] == 0:
                k = False
            if new[b] == 0:
                k = False
    if k == True:
        out.append('OK')
    else:
        out.append('Not OK')
        
    x = input()
for e in out:
    print(e)

        
    






6431540221
# 1679858, 2022-11-12 10:30:28, --- (0%)

ct = {}
ct1 = {}
key = []
y = 0
for i in range(int(input())) :
    team, city = [e.strip() for e in input().split()]
    if team not in ct : ct[team] = []
    ct[team].append(city)
    key.append(team)
    
while True:
    x = [e.strip() for e in input().split()]
    sts = 'OK'
    if len(x) == 1 and x[0] == 'q': break
    y += 1
    for z in x :
        if z not in key :
            ct[z] = ['A']
            ct1[y] = 'Not Ok'
    for j in range (len(x)-1) :
        for k in range (j+1,len(x)) :
            a = x[j]
            b = x[k]
            #if ct[a] == 'A' or ct[b] == 'A' :
            #    ct1[y] = 'Not Ok'
            if ct[x[j]] == ct[x[k]] :
                sts = 'Not Ok'
                ct1[y] = sts
            else :
                ct1[y] = sts
for i in range(y) :
    print(ct1[i+1])
    
    

# 1680787, 2022-11-12 11:09:11, --- (0%)

ct = {}
ct1 = {}
key = []
y = 0
for i in range(int(input())) :
    team, city = [e.strip() for e in input().split()]
    if team not in ct : ct[team] = []
    ct[team].append(city)
    key.append(team)
    
while True:
    x = [e.strip() for e in input().split()]
    sts = 'OK'
    if len(x) == 1 and x[0] == 'q': break
    y += 1
    for z in x :
        if z not in key :
            ct[z] = ['A']
    for j in range (len(x)-1) :
        for k in range (j+1,len(x)) :
            a = x[j]
            b = x[k]
            if x[j] not in key :
                sts = 'Not Ok'
                ct1[y] = sts
            elif x[k] not in key :
                sts = 'Not Ok'
                ct1[y] = sts
            elif ct[x[j]] == ct[x[k]] :
                sts = 'Not Ok'
                ct1[y] = sts
            
            else :
                ct1[y] = sts
for i in range(y) :
    print(ct1[i+1])

# 1680809, 2022-11-12 11:09:59, PPP (100%)

ct = {}
ct1 = {}
key = []
y = 0
for i in range(int(input())) :
    team, city = [e.strip() for e in input().split()]
    if team not in ct : ct[team] = []
    ct[team].append(city)
    key.append(team)
    
while True:
    x = [e.strip() for e in input().split()]
    sts = 'OK'
    if len(x) == 1 and x[0] == 'q': break
    y += 1
    for z in x :
        if z not in key :
            ct[z] = ['A']
    for j in range (len(x)-1) :
        for k in range (j+1,len(x)) :
            a = x[j]
            b = x[k]
            if x[j] not in key :
                sts = 'Not OK'
                ct1[y] = sts
            elif x[k] not in key :
                sts = 'Not OK'
                ct1[y] = sts
            elif ct[x[j]] == ct[x[k]] :
                sts = 'Not OK'
                ct1[y] = sts
            
            else :
                ct1[y] = sts
for i in range(y) :
    print(ct1[i+1])

6431804021
# 1679200, 2022-11-12 09:57:47, --- (0%)

d = {}
l = []
c = 0
g = []

n = int(input())
for i in range(n) :
    x = input().split()
    d[x[0]] = x[1]
    l.append(x[0])
    
while c == 0 :
    k = 0
    m = input().split()
    if m == ['q'] : break
    
    for i in m :
        if i not in l :
            k = 1 ; break
        g.append(d[i])
        if len(set(g)) != len(g) :
            k = 1 ; break


    if k == 0 :
        print('OK')
    else :
        print('Not OK')

# 1679314, 2022-11-12 10:03:31, --- (0%)

d = {}
l = []
c = 0
g = []

n = int(input())
for i in range(n) :
    x = input().split()
    d[x[0]] = x[1]
    l.append(x[0])
    
while c == 0 :
    k = 0
    m = input().split()
    if m == ['q'] : break
    
    for i in m :
        if i not in l :
            k = 1 ; break
        g.append(d[i])
        if len(set(g)) != len(g) :
            k = 1 ; break


    if k == 0 :
        print('OK')
    else :
        print('Not OK')
    k = 0
# 1679409, 2022-11-12 10:09:04, PPP (100%)

d = {}
l = []
c = 0


n = int(input())
for i in range(n) :
    x = input().split()
    d[x[0]] = x[1]
    l.append(x[0])
    
while c == 0 :
    g = []
    k = 0
    m = input().split()
    if m == ['q'] : break
    
    for i in m :
        if i not in l :
            k += 1 ; break
        g.append(d[i])
        if len(set(g)) != len(g) :
            k += 1 ; break


    if k == 0 :
        print('OK')
    elif k != 0 :
        print('Not OK')        


6430064721
# 1679824, 2022-11-12 10:29:16, xxx (0%)

n=int(input())
s={}
for i in range(n):
    name,c=input().split()
    if name not in s:
        s[name] = [c]
    else: s[name].append(c)


while True:
    d=set()
    x=input().split()
    if len(x)==1 : #ถ้าผิดเติม q
        break
    else:
        for i in x:
            if i in s:
                if i not in d:
                    d.add(s[i])
            else:
                print("Not OK")
                
    if len(d) != len(x):
        print("Not OK")
    else:
        print("OK")
        
        
        

# 1680327, 2022-11-12 10:52:34, PP- (67%)

n=int(input())
s={} ; s2={}
for i in range(n):
    name,c=input().split()
    s[name] = c
    if c not in s2:
        s2[c] = [name]
    else: s2[c].append(name)
    
while True:
    d=[]
    d2=set()
    x=input().split()
    if len(x)==1 : #ถ้าผิดเติม q
        break
    else:
        for i in x:
            if i not in s.keys():
                print("Not OK")
            else:
                d.append(s[i])
        d2.update(d)
    if len(d2) != len(d):
        print("Not OK")
    elif len(d2) == len(d):
        print("OK")
# 1680796, 2022-11-12 11:09:32, PPP (100%)

n=int(input())
s={} ; s2={}
for i in range(n):
    name,c=input().split()
    s[name] = c
    if c not in s2:
        s2[c] = [name]
    else: s2[c].append(name)    
while True:
    d=[]
    d2=set()
    T=True
    x=input().split()
    if len(x)==1 : #ถ้าผิดเติม q
        break
    for i in x:
        if i in s.keys():
            d.append(s[i])
        else:
            print("Not OK")
            T=False
            break
    d2.update(d)
    if len(d2) != len(d):
        print("Not OK")
    elif len(d2) == len(d) and T:
        print("OK")

6431025421
# 1679063, 2022-11-12 09:50:08, --x (0%)

country = {}
for i in range(int(input())):
    x = input().split()
    country[x[0]] = x[1]
y1 = []    
while True:
      y = input().split()
      if y != ['q']:
         y1.append(y)
      if y == ['q']:break
for i in range(len(y1)):
    for j in y1[i]:
        for k in set(y1[i]):
           if country[k] == country[j]:
              print('Not OK')
           else:
              print('OK') 
# 1679191, 2022-11-12 09:57:11, --x (0%)

country = {}
for i in range(int(input())):
    x = input().split()
    country[x[0]] = x[1]
y1 = []    
while True:
      y = input().split()
      if y != ['q']:
         y1.append(y)
      if y == ['q']:break
for i in range(len(y1)):
    for j in y1[i]:
        for k in y1[i][1:]:
           if country[j] == country[k]:
              print('Not OK')
           else:
              print('OK') 
# 1679362, 2022-11-12 10:06:23, PPP (100%)

country = dict()
for i in range(int(input())):
    x = input().strip().split()
    if x[1] not in country:
        country[x[1]] = {x[0]}
    else:
        temp = country.get(x[1])
        temp.add(x[0])        
while True:
    names = input().strip().split()
    team = [i for i in names]
    if len(names) == 1:
        break
    counts = []
    for i in country:
        for j in names:
            if j in country[i]:
                counts.append(i)
    ch = []
    for i in counts:
        if counts.count(i) > 1:
           ch.append(False)
        else:
            ch.append(True)
    
    if len(team) != len(counts) or False in ch:
        print("Not OK")
    else:
        print("OK")



6430201321
# 1678907, 2022-11-12 09:41:49, --- (0%)

n = int(input())
t = {}
a_t = []
for i in range(n):
    a = input().split()
    a_t.append(a[0])
    t[a[0]] = a[1]

b = ''
s = set()
while b != ['q']:
    o = 0
    b = input().split()
    for i in b:
        if i in a_t:
            s.add(t[i])
        else:
            o += 1
        
    if len(s) < len(b):
        o += 1
    
    if o > 0:
        print(s)
        print(b)
        print(o)
        print('Not OK')
    elif o == 0:
        print('OK')
        

# 1678935, 2022-11-12 09:43:26, --- (0%)

n = int(input())
t = {}
a_t = []
for i in range(n):
    a = input().split()
    a_t.append(a[0])
    t[a[0]] = a[1]

b = ''
s = set()
while True:
    o = 0
    b = input().split()
    for i in b:
        if i in a_t:
            s.add(t[i])
        else:
            o += 1
        
    if len(s) < len(b):
        o += 1
    
    if b == ['q']:
        break
    elif o > 0:

        print('Not OK')
    elif o == 0:
        print('OK')
        

# 1678982, 2022-11-12 09:46:23, PPP (100%)

n = int(input())
t = {}
a_t = []
for i in range(n):
    a = input().split()
    a_t.append(a[0])
    t[a[0]] = a[1]

b = ''
s = set()
while True:
    s = set()
    o = 0
    b = input().split()
    for i in b:
        if i in a_t:
            s.add(t[i])
        else:
            o += 1
        
    if len(s) < len(b):
        o += 1
    
    if b == ['q']:
        break
    elif o > 0:

        print('Not OK')
        
    elif o == 0:

        print('OK')
        


6432036521
# 1679130, 2022-11-12 09:53:59, --x (0%)

n = int(input())
t = dict()
for i in range(n):
    x, y = input().split()
    t[x]=y
ans=list()
q = input()
while q!='q':
    check=q.split()
    tf = True
    nation=list(t[check[0]])
    for c in check:
        if c not in t:
            ans.append("Not OK")
            tf = False
            break
        else:
            if t[c] in nation:
                ans.append("Not OK")
                tf = False
                break
            else:
                nation.append(t[c])
    if tf == True:ans.append("OK")
    q=input()
for c in ans:
    print(c)
# 1679142, 2022-11-12 09:54:36, --x (0%)

n = int(input())
t = dict()
for i in range(n):
    x, y = input().split()
    t[x]=y
ans=list()
q = input()
while q!='q':
    check=q.split()
    tf = True
    nation=list(t[check[0]])
    for c in check:
        if c not in t:
            ans.append("Not OK")
            tf = False
            break
        else:
            if t[c] in nation:
                ans.append("Not OK")
                tf = False
                break
            else:
                nation.append(t[c])
    if tf == True:ans.append("OK")
    q=input()
for c in ans:
    print(c)
# 1679932, 2022-11-12 10:33:31, PPP (100%)

n = int(input())
t = dict()
for i in range(n):
    x, y = input().split()
    t[x]=y
ans=list()
q = input()
while q!='q':
    check=q.split()
    tf = True
    nation=list()
    for c in check:
        if c not in t:
            ans.append("Not OK")
            tf = False
            break
        else:
            if t[c] in nation:
                ans.append("Not OK")
                tf = False
                break
            else:
                nation.append(t[c])
    if tf == True:ans.append("OK")
    q=input()
for c in ans:
    print(c)

6530003521
# 1678562, 2022-11-12 09:22:55, compilation error (0%)

d = {}
for i n range(int(input())) :
    x = input().split()
    if x[1] not in d :
        d[[x[0]]] = [x[1]]
    else :
        d[x[0]].append(x[1])


x = input().split()
all = []
found = False
while x != ['q'] :
    for e in x :
        if d[e] not in all :
            all.append(d[e])
            
        else :
            print('Not OK')
            found = True
    if not found :
        print('OK')
      
    x = input().split()

# 1678575, 2022-11-12 09:23:32, xxx (0%)

d = {}
for i in range(int(input())) :
    x = input().split()
    if x[1] not in d :
        d[[x[0]]] = [x[1]]
    else :
        d[x[0]].append(x[1])


x = input().split()
all = []
found = False
while x != ['q'] :
    for e in x :
        if d[e] not in all :
            all.append(d[e])
            
        else :
            print('Not OK')
            found = True
    if not found :
        print('OK')
      
    x = input().split()

# 1678820, 2022-11-12 09:36:29, PPP (100%)

d = {}
for i in range(int(input())) :
    x = input().split()
    if x[0] not in d :
        d.update({x[0]:x[1]})
    else :
        d[x[0]].append(x[1])

x = input().split()
ans = []
while x != ['q'] :
    All = []
    found = False
    for e in x :
        if e not in d :
            ans.append('Not OK')
            found = True
            break
        if d[e] not in All :
            All.append(d[e])
            
        else :
            ans.append('Not OK')
            found = True
            break
    if not found :
        ans.append('OK')
    x = input().split()
for e in ans :
    print(e)


6530008721
# 1678678, 2022-11-12 09:29:06, --- (0%)

#input -> {team: {country}}
group = {}
for i in range(int(input())):
    t = input().strip().split()
    if t[0] not in group: group[t[0]] = set()
    group[t[0]].add(t[1])

result= []
while True:
    bracket = input().strip().split()
    if len(bracket) == 1 and bracket[0] == 'q': break
    check = []
    fx = True
    for e in bracket:
        if e not in group:
            result.append('Not OK')
            break
        if group[e] in check:
            result.append('Not OK')
            fx = False
            break
        else:
            check.append(group[e])
    if fx:
        result.append("OK")
print(result)       
    

# 1678689, 2022-11-12 09:29:36, --- (0%)

#input -> {team: {country}}
group = {}
for i in range(int(input())):
    t = input().strip().split()
    if t[0] not in group: group[t[0]] = set()
    group[t[0]].add(t[1])

result= []
while True:
    bracket = input().strip().split()
    if len(bracket) == 1 and bracket[0] == 'q': break
    check = []
    fx = True
    for e in bracket:
        if e not in group:
            result.append('Not OK')
            fx = False
            break
        if group[e] in check:
            result.append('Not OK')
            fx = False
            break
        else:
            check.append(group[e])
    if fx:
        result.append("OK")
print(result)       
    

# 1678701, 2022-11-12 09:30:17, PPP (100%)

#input -> {team: {country}}
group = {}
for i in range(int(input())):
    t = input().strip().split()
    if t[0] not in group: group[t[0]] = set()
    group[t[0]].add(t[1])

result= []
while True:
    bracket = input().strip().split()
    if len(bracket) == 1 and bracket[0] == 'q': break
    check = []
    fx = True
    for e in bracket:
        if e not in group:
            result.append('Not OK')
            fx = False
            break
        if group[e] in check:
            result.append('Not OK')
            fx = False
            break
        else:
            check.append(group[e])
    if fx:
        result.append("OK")
for e in result:
    print(e)
    


6530011521
# 1679470, 2022-11-12 10:12:24, --x (0%)

nc = {}
for i in range(int(input())):
    name, country = input().split()
    if name not in nc: nc[name] = ''
    nc[name] = country
while True:
    names = input().split()
    if names[0] == 'q': break
    for j in range(len(names)):
        for k in range(j+1,len(names)):
            if nc[names[j]] == nc[names[k]]:
                print('Not OK')
# 1679532, 2022-11-12 10:15:16, PPx (67%)

nc = {}
for i in range(int(input())):
    name, country = input().split()
    if name not in nc: nc[name] = ''
    nc[name] = country
while True:
    names = input().split()
    if names[0] == 'q': break
    O = True
    for j in range(len(names)):
        for k in range(j+1,len(names)):
            if nc[names[j]] == nc[names[k]]:
                O = False
    if O == True:
        print('OK')
    else:
        print('Not OK')
# 1680295, 2022-11-12 10:51:08, PPP (100%)

def check(l, c):
    for i in l:
        if i not in c:
            return True
nc = {}
for i in range(int(input())):
    name, country = input().split()
    if name not in nc: nc[name] = ''
    nc[name] = country
while True:
    names = input().split()
    O = True
    if names[0] == 'q': break
    elif check(names, nc) == True:
        O = False
    else:
        for j in range(len(names)):
            for k in range(j+1,len(names)):
                if nc[names[j]] == nc[names[k]]:
                    O = False
    if O == True:
        print('OK')
    else:
        print('Not OK')

6530398421
# 1678943, 2022-11-12 09:43:47, xxx (0%)

n = int(input())
y = []
for i in range(n):
    y.append(input().split())


team_country = {}
for c in range(len(y)):
    team_country[y[c][0]] = y[c][1]
    

s = set()    
x = input().split()
c = set(x)
while x != q:
    for d in x:
        if d in b:
            s.add(b[d])
        else:
            print("Not OK")
    if (c - b) == set():
        print("OK")
    else:
        print("Not OK")
# 1679458, 2022-11-12 10:11:45, xxx (0%)

n = int(input())
y = []
for i in range(n):
    y.append(input().split())


team_country = {}
for c in range(len(y)):
    team_country[y[c][0]] = y[c][1]
    

s = set()    
x = input().split()
c = set()
for f in range(len(x)):
    c.add(x[f])

while x != "q":
    for a in x:
        if a in team_country.keys():
            s.add(team_country[a])
        
            
        
    if len(c) - len(s) == 0:
        print("OK")
    else:
        print("Not OK")
    x = input().split()
# 1679718, 2022-11-12 10:24:11, PPP (100%)

n = int(input())
y = []
for i in range(n):
    y.append(input().split())


team_country = {}
for c in range(len(y)):
    team_country[y[c][0]] = y[c][1]


s = set()    
x = input().split()
c = set()




while x != ["q"]:
    for f in range(len(x)):
        c.add(x[f])
    for a in x:
        if a in team_country.keys():
            s.add(team_country[a])
        
            
        
    if len(c) - len(s) == 0:
        print("OK")
    else:
        print("Not OK")
    
    
    x = input().split()
    s = set()
    c = set()

6530042021
# 1679283, 2022-11-12 10:02:10, PPP (100%)

n = int(input())
r = dict()
for i in range(n):
    t,c = input().strip().split()
    r[t] = c

m = input().strip()
out = []
while m != 'q':
    group = m.split()
    out.append(group)
    m = input().strip()



y = []
k = []
for group in out:
    z = []
    #print(group)
    for t in group:
        c = 0
        if t not in r:
            y.append('Not OK')
            print('Not OK')
            c = 1
            break
        elif r[t] in z:
            y.append('Not OK')
            print('Not OK')
            c = 1
            break
        elif r[t] not in z:
            z.append(r[t])
    y.append('OK')
    if c != 1:
        print('OK')
# 1679312, 2022-11-12 10:03:26, PPP (100%)

n = int(input())
r = dict()
for i in range(n):
    t,c = input().strip().split()
    r[t] = c

m = input().strip()
out = []
while m != 'q':
    group = m.split()
    out.append(group)
    m = input().strip()



y = []
k = []
for group in out:
    z = []
    #print(group)
    for t in group:
        c = 0
        if t not in r:
            y.append('Not OK')
            print('Not OK')
            c = 1
            break
        elif r[t] in z:
            y.append('Not OK')
            print('Not OK')
            c = 1
            break
        elif r[t] not in z:
            z.append(r[t])
    y.append('OK')
    if c != 1:
        print('OK')
# 1680488, 2022-11-12 10:58:36, PPP (100%)

n = int(input())
r = dict()
for i in range(n):
    t,c = input().strip().split()
    r[t] = c

m = input().strip()
out = []
while m != 'q':
    group = m.split()
    out.append(group)
    m = input().strip()


for group in out:
    z = []
    for t in group:
        c = 0
        if t not in r:
            print('Not OK')
            c = 1
            break
        elif r[t] in z:
            print('Not OK')
            c = 1
            break
        elif r[t] not in z:
            z.append(r[t])
    if c != 1:
        print('OK')



6530062521
# 1679565, 2022-11-12 10:17:24, --- (0%)

n = int(input())
club = {}
for i in range(n) :
    c,n = input().split()
    club[c] = n
while True:
    g = input().split()
    check = set()
    fu = False
    for e in g:
        if e not in club:
            print("Not OK")
            fu = True
            break
        check.add(club[e])
    if fu == True : break
    if len(check) == len(g):
        print("OK")
    else : print("Not OK")
    if len(g) == 0 and g[0] == 'q':
        break
        

# 1679786, 2022-11-12 10:27:49, xxx (0%)

n = int(input())
club = {}
for i in range(n) :
    c,n = input().split()
    club[c] = n
while True:
    g = input().split()
    if len(g) == 0 and g[0] == 'q':
        break
    check = set()
    fu = False
    for e in g:
        if e not in club:
            print("Not OK")
            fu = True
            break
        check.add(club[e])
    if fu == True : pass
    elif len(check) == len(g):
        print("OK")
    else : print("Not OK")
    
      
# 1679898, 2022-11-12 10:31:44, PPP (100%)

n = int(input())
club = {}
for i in range(n) :
    c,n = input().split()
    club[c] = n
while True:
    g = input().split()
    if len(g) == 1 and g[0] == 'q':
        break
    check = set()
    fu = False
    for e in g:
        if e not in club:
            print("Not OK")
            fu = True
            break
        check.add(club[e])
    if fu == True : pass
    elif len(check) == len(g):
        print("OK")
    else : print("Not OK")
    


6530063121
# 1678664, 2022-11-12 09:28:32, --- (0%)

d={}
for k in range(int(input())):
    x,y=input().split()
    d[x]=y
print(d)
while True:
    i=input()
    if i=="q":break
    else:
        j=i.split()
        lj=len(j)
        groupset=set()
        for team in j:
            if team  in d:
                groupset.add(d[team])
        if len(groupset)!=lj:
            print("Not OK")
        else:
            print("OK")
                
            
            
    
    

# 1678704, 2022-11-12 09:30:23, --x (0%)

d={}
for k in range(int(input())):
    x,y=input().split()
    d[x]=y
print(d)
while True:
    i=input()
    if i=="q":break
    else:
        j=i.split()
        lj=len(j)
        groupset=set()
        for team in j:
            if team  in d:
                print("Not OK")
                break
            else:
                groupset.add(d[team])
        if len(groupset)!=lj:
            print("Not OK")
        else:
            print("OK")
                
            
            
    
    

# 1678797, 2022-11-12 09:35:11, PPP (100%)

d={}
for k in range(int(input())):
    x,y=input().split()
    d[x]=y
while True:
    i=input()
    if i=="q":break
    else:
        j=i.split()
        lj=len(j)
        groupset=set()
        for team in j:
            if team  in d:
                groupset.add(d[team])
        if len(groupset)!=lj:
            print("Not OK")
        else:
            print("OK")
                
            
            
    
    


6530076321
# 1678843, 2022-11-12 09:37:31, x-x (0%)

n = int(input())
team ={}
for i in range(n):
    name,con = input().split()
    team[name] = con

choice = [[e for e in input().split()]]

for a,b,c,d in choice:
    if team[a] != team[b] and team[a] != team[c] and team[a] != team[d] and team[b] != team[c] and team[b] != team[d] and team[c] != team[d]:
            print("OK")
    else:
        print("Not OK")
# 1679154, 2022-11-12 09:55:23, --- (0%)

n = int(input())
team ={}
club =[]
for i in range(n):
    name,con = input().split()
    team[name] = con
    club.append(name)

choice = [e for e in input().split()]
while choice[0] != 'q':
    country=[]
    check = True
    for i in choice:
        if choice not in club:
            check = False
        else:
            country.append(team[i])
    if len(country) == len(set(country)) and check == True:
        print("OK")
    else:
        print("Not OK")
    choice = [e for e in input().split()]
# 1679194, 2022-11-12 09:57:23, PPP (100%)

n = int(input())
team ={}
club =[]
for i in range(n):
    name,con = input().split()
    team[name] = con
    club.append(name)

choice = [e for e in input().split()]
while choice[0] != 'q':
    country=[]
    check = True
    for i in choice:
        if i not in club:
            check = False
        else:
            country.append(team[i])
    if len(country) == len(set(country)) and check == True:
        print("OK")
    else:
        print("Not OK")
    choice = [e for e in input().split()]

6530097521
# 1678799, 2022-11-12 09:35:17, --- (0%)

a = int(input())

team_c = {}
for i in range(a):
    team,country = input().split()
    team_c[team] = country


def check(team_c,team):
    country = set()
    ans = "OK"
    for i in team:
        if i in team_c:
            country.add(team_c[i])
        else:
            country.add("None")
        
    print(country)
    if "None" in country:
        ans  = "Not OK"
        
    if "None" not in country:
        if len(country) < 4:
            ans  = "Not OK"
    
    return ans


c = input().split()
while c != ["q"] :
    print(check(team_c,c))
    c = input().split()
    

# 1678803, 2022-11-12 09:35:40, -P- (33%)

a = int(input())

team_c = {}
for i in range(a):
    team,country = input().split()
    team_c[team] = country


def check(team_c,team):
    country = set()
    ans = "OK"
    for i in team:
        if i in team_c:
            country.add(team_c[i])
        else:
            country.add("None")
    
    if "None" in country:
        ans  = "Not OK"
        
    if "None" not in country:
        if len(country) < 4:
            ans  = "Not OK"
    
    return ans


c = input().split()
while c != ["q"] :
    print(check(team_c,c))
    c = input().split()
    

# 1678817, 2022-11-12 09:36:23, PPP (100%)

a = int(input())

team_c = {}
for i in range(a):
    team,country = input().split()
    team_c[team] = country


def check(team_c,team):
    country = set()
    ans = "OK"
    for i in team:
        if i in team_c:
            country.add(team_c[i])
        else:
            country.add("None")
    
    if "None" in country:
        ans  = "Not OK"
        
    if "None" not in country:
        if len(country) < len(team):
            ans  = "Not OK"
    
    return ans


c = input().split()
while c != ["q"] :
    print(check(team_c,c))
    c = input().split()
    


6530099821
# 1678528, 2022-11-12 09:20:52, --x (0%)

d = {}
for i in range(int(input())):
    a,b = input().split()
    d[a] = b

z = True
while z == True:
    c = input().split()
    if c == ['q']:
        break
    n = 0
    s = set()
    for i in c:
        n += 1
        s.add(d[i])
        
if len(s) != n:
    print('Not OK')
else:
    print('OK')
# 1678569, 2022-11-12 09:23:15, PP- (67%)

d = {}
for i in range(int(input())):
    a,b = input().split()
    d[a] = b

z = True
while z == True:
    c = input().split()
    if c == ['q']:
        break
    n = 0
    s = set()
    for i in c:
        if i in d:
            n += 1
            s.add(d[i])
    if len(s) != n:
        print('Not OK')
    else:
        print('OK') 
# 1678609, 2022-11-12 09:25:23, PPP (100%)

d = {}
for i in range(int(input())):
    a,b = input().split()
    d[a] = b

z = True
while z == True:
    c = input().split()
    if c == ['q']:
        break
    n = 0
    s = set()
    ch = 0
    for i in c:
        if i in d:
            n += 1
            s.add(d[i])
        else:
            ch = 1
    if ch == 1:
        print('Not OK')
    if ch == 0:
        if len(s) != n:
            print('Not OK')
        else:
            print('OK')  

6530104221
# 1678479, 2022-11-12 08:55:36, --- (0%)

x=input()
print(x)
# 1678977, 2022-11-12 09:46:03, --- (0%)

def checkFalse(x):
    for i in range(len(x)-1):
        if x[i]==x[i+1]:
            return False
            break
    return True


n=int(input()) ; team=dict() ;TEAM=[] ;ans=[]

for i in range(n):
    t,c=input().split()
    team[t]=c ; TEAM.append(t)
    
while True:
    x=input().split()
    if x[0]=='q': break
    lol=[]
    for e in x:
        if e in TEAM:
            lol.append(team[e])
        else:
            lol.append('')
    ans.append(lol)

# check=True
# for k in ans:
#     if '' in k:
#         out.append('NOT OK') ; check=False
#     else:
#         for i in range(len(sorted(k))-1):
#             if sorted(k)[i]==sorted(k)[i+1]:
#                 out.append('NOT OK') ; check=False
#                 break
#         if check==True:
#             out.append('OK')
# print(ans)

for e in ans:
    if '' in e:
        print('NOT OK')
    else:
        if checkFalse(sorted(e))==False:
            print('NOT OK')
        else:
            print('OK')
# 1678997, 2022-11-12 09:46:59, PPP (100%)

def checkFalse(x):
    for i in range(len(x)-1):
        if x[i]==x[i+1]:
            return False
            break
    return True


n=int(input()) ; team=dict() ;TEAM=[] ;ans=[]

for i in range(n):
    t,c=input().split()
    team[t]=c ; TEAM.append(t)
    
while True:
    x=input().split()
    if x[0]=='q': break
    lol=[]
    for e in x:
        if e in TEAM:
            lol.append(team[e])
        else:
            lol.append('')
    ans.append(lol)

for e in ans:
    if '' in e:
        print('Not OK')
    else:
        if checkFalse(sorted(e))==False:
            print('Not OK')
        else:
            print('OK')

6530105921
# 1678543, 2022-11-12 09:21:44, TTT (0%)

n = int(input())
ateam= {}
for i in range(n):
    team,coun = input().strip().split()
    ateam[team] = coun
x = input().strip().split()
while x[0] != "q":
    ch = []
    for e in x:
        if e not in ateam:
            print("Not OK")
            break
        else:
            if ateam[e] in ch:
                print("Not OK")
                break
            ch.append(ateam[e])
    print("OK")
# 1678579, 2022-11-12 09:23:40, --- (0%)

n = int(input())
ateam= {}
for i in range(n):
    team,coun = input().strip().split()
    ateam[team] = coun
x = input().strip().split()
while x[0] != "q":
    ch = []
    for e in x:
        if e not in ateam:
            print("Not OK")
            break
        else:
            if ateam[e] in ch:
                print("Not OK")
                break
            ch.append(ateam[e])
    print("OK")
    x = input().strip().split()
# 1678626, 2022-11-12 09:26:17, PPP (100%)

n = int(input())
ateam= {}
for i in range(n):
    team,coun = input().strip().split()
    ateam[team] = coun
x = input().strip().split()
while x[0] != "q":
    ch = []
    ok = True
    for e in x:
        if e not in ateam:
            ok = False
            break
        else:
            if ateam[e] in ch:
                ok = False
                break
            ch.append(ateam[e])
    if ok:
        print("OK")
    else:
        print("Not OK")
    x = input().strip().split()


6530114521
# 1678735, 2022-11-12 09:31:42, --- (0%)

n = int(input())
dicts = {}
for i in range(n) :
    team,con = input().split()
    if con not in dicts :
        dicts[con] = [team]
    else :
        dicts[con].append(team)
print(dicts)
while True :
    sets = set() 
    a = input().split()
    if a[0] == 'q' :
        break
    else :
        for l in a :
            for j in dicts :
                if l in dicts[j] :
                    sets.add(j)
        if len(sets) == len(a) :
            print('OK')
        else :
            print('Not OK')
# 1678775, 2022-11-12 09:34:07, --- (0%)

n = int(input())
dicts = {}
for i in range(n) :
    team,con = input().split()
    if con not in dicts :
        dicts[con] = [team]
    else :
        dicts[con].append(team)
print(dicts)
while True :
    sets = set() 
    a = input().split()
    if a[0] == 'q' :
        break
    else :
        for l in a :
            for j in dicts :
                if l in dicts[j] :
                    sets.add(j)
        if len(sets) == len(a) :
            print('OK')
        else :
            print('Not OK')
# 1678834, 2022-11-12 09:37:12, PPP (100%)

n = int(input())
dicts = {}
for i in range(n) :
    team,con = input().split()
    if con not in dicts :
        dicts[con] = [team]
    else :
        dicts[con].append(team)
while True :
    sets = set() 
    a = input().split()
    if a[0] == 'q' :
        break
    else :
        for l in a :
            for j in dicts :
                if l in dicts[j] :
                    sets.add(j)
        if len(sets) == len(a) :
            print('OK')
        else :
            print('Not OK')

6530116821
# 1678616, 2022-11-12 09:25:51, xxx (0%)

n=int(input())
dic={}
country=set()
for i in range(n):
    team,coun=input().split()
    dic[team]=coun
    country.add(coun)
x=input().split()
while x!='q':
    check=[]
    for i in range(len(x)):
        if x[i] in dic:
            x[i]=dic[x[i]]
    for i in x:
        if i not in check:
            if i in country:
                check.append(i)
    if len(x)!=len(check):
        print('Not OK')
    if len(x)==len(check):
        print('OK')
    x=input().split()
# 1678687, 2022-11-12 09:29:33, xxx (0%)

n=int(input())
dic={}
country=set()
for i in range(n):
    team,coun=input().split()
    dic[team]=coun
    country.add(coun)
x=input().split()
while x!='q':
    check=[]
    for i in range(len(x)):
        if x[i] in dic:
            x[i]=dic[x[i]]
    for i in x:
        if i not in check:
            if i in country:
                check.append(i)
    if len(x)!=len(check):
        print('Not OK')
    if len(x)==len(check):
        print('OK')
    x=input().split()
# 1678751, 2022-11-12 09:32:35, PPP (100%)

n=int(input())
dic={}
country=set()
for i in range(n):
    team,coun=input().split()
    dic[team]=coun
    country.add(coun)
x=input().split()
while x!=['q']:
    check=[]
    for i in range(len(x)):
        if x[i] in dic:
            x[i]=dic[x[i]]
    for i in x:
        if i not in check:
            if i in country:
                check.append(i)
    if len(x)!=len(check):
        print('Not OK')
    if len(x)==len(check):
        print('OK')
    x=input().split()

6530128321
# 1678693, 2022-11-12 09:29:47, --- (0%)

nationTeam = {}
group = []
n = int(input())
for i in range(n):
    a,b = input().strip().split()
    nationTeam[a] = b

while True:
    x = input()
    if (x == "q"): break
    x = x.strip().split()
    group.append(x)
    
null = 0
for i in group:
    for j in i:
        if (j not in nationTeam):
            print("Not OK")
            null = 1
            break
    if (null == 1):
        break
    bb = []
    cc = []
    for j in i:
        print(j)
        if nationTeam[j] not in bb:
            bb.append(nationTeam[j])
        cc.append(nationTeam[j])
    if (bb != cc):
        print("Not OK")
    else:
        print("OK")
    
            
    

# 1678697, 2022-11-12 09:30:08, PP- (67%)

nationTeam = {}
group = []
n = int(input())
for i in range(n):
    a,b = input().strip().split()
    nationTeam[a] = b

while True:
    x = input()
    if (x == "q"): break
    x = x.strip().split()
    group.append(x)
    
null = 0
for i in group:
    for j in i:
        if (j not in nationTeam):
            print("Not OK")
            null = 1
            break
    if (null == 1):
        break
    bb = []
    cc = []
    for j in i:
        if nationTeam[j] not in bb:
            bb.append(nationTeam[j])
        cc.append(nationTeam[j])
    if (bb != cc):
        print("Not OK")
    else:
        print("OK")
    
            
    

# 1681512, 2022-11-12 11:28:07, PPP (100%)

nationTeam = {}
group = []
n = int(input())
for i in range(n):
    a,b = input().strip().split()
    nationTeam[a] = b

while True:
    x = input()
    if (x == "q"): break
    x = x.strip().split()
    group.append(x)


for i in group:
    null = 0
    
    for j in i:
        if (j not in nationTeam):
            print("Not OK")
            null = 1
            break
    if (null == 1):
        continue
    bb = []
    cc = []
    for j in i:
        if nationTeam[j] not in bb:
            bb.append(nationTeam[j])
        cc.append(nationTeam[j])
    if (bb != cc):
        print("Not OK")
    else:
        print("OK")

6530170621
# 1679442, 2022-11-12 10:11:10, --- (0%)

n=int(input())
country={}
for i in range(n):
    t,c=input().split()
    country[t]=c
print(country)
group=input()
output=[]
while group != 'q':
    group=group.split()
    check=[]
    for e in group:
        c=0
        if e in country:
            if country[e] not in check:
                check.append(country[e])
            else:
                c+=1
        else:
            c+=1
    if c>0:
        output.append('Not OK')
    else:
        output.append('OK')
    group=input()
for e in output:
    print(e)
# 1679545, 2022-11-12 10:16:10, xxx (0%)

country={}
for i in range(n):
    t,c=input().split()
    country[t]=c
#print(country)
group=input()
output=[]
while group != 'q':
    group=group.split()
    check=[]
    c=0
    for e in group:
        if e in country:
            if country[e] not in check:
                check.append(country[e])
            else:
                c+=1
        else:
            c+=1
    if c>0:
        output.append('Not OK')
    else:
        output.append('OK')
    group=input()
for e in output:
    print(e)
# 1680112, 2022-11-12 10:42:11, PPP (100%)

n=int(input())
a={}
for i in range(n):
    x,y=input().split()
    a[x]=y
#print(a)
q=input()
output=[]
while q!='q':
    check=[]
    q=q.split()
    c=0
    for i in range(len(q)):
        if q[i] in a:
            if a[q[i]] not in check:
                check.append(a[q[i]])
            else:
                c+=1
        else:
            c+=1
    #print(c)
    if c==0:
        output.append('OK')
    else:
        output.append('Not OK')
    q=input()
for e in output:
    print(e)

6530181521
# 1678501, 2022-11-12 09:17:59, PPP (100%)

team = {}
for i in range(int(input())) :
    t,c = input().strip().split()
    team[t] = c

while True :
    a = input().strip().split()
    if a == ['q'] :
        break
    s = set()
    for e in a :
        if e in team : s.add(team[e])
    if len(s) == len(a) :
        print('OK')
    else :
        print('Not OK')

# 1679775, 2022-11-12 10:27:13, PPP (100%)

team = {}
for i in range(int(input())):
    t,c = input().strip().split()
    team[t] = c
while True:
    a = input().strip().split()
    if a==['q']:
        break
    s = {team[e] for e in a if e in team}
    if len(s) == len(a): print('OK')
    else: print('Not OK')
# 1679937, 2022-11-12 10:33:46, PPP (100%)

team={t:l for i in range(int(input())) for t,l in [input().split()]}
while True:
    a=input().split()
    if a==['q']:break
    s={team[e] for e in a if e in team}
    if len(s)==len(a):print('OK')
    else:print('Not OK')

6530182121
# 1678631, 2022-11-12 09:26:30, xxx (0%)

#password : good_LUCK
#input ==> {team : ประเทศ}
teamlist = dict()
countrylist = dict()
for i in range (int(input())) :
    t,c = input().split()
    if t not in teamlist : teamlist[t] = dict()
    if c not in countrylist : countrylist[c] = set()
    teamlist[t] = c
    countrylist[c].add(t)

#print(teamlist)
x = input()
#ค้น แต่ละทีมใน teamlist
while x != 'q' :
    x = x.split() 
    for t in x : #แต่ละทีม
        if t in teamlist :
            c = teamlist[t] #ได้ประเทศมา
            a = countrylist[c] #ได้ทีมทั้งหมดมา
            if set(x).issubset(a) :
                print("OK")
            else :
                print("Not OK")
            
                        
            
            
    
    
                

# 1679185, 2022-11-12 09:56:58, --- (0%)

#password : good_LUCK
#input ==> {team : ประเทศ}
teamlist = dict()
countrylist = dict()
for i in range (int(input())) :
    t,c = input().split()
    if t not in teamlist : teamlist[t] = dict()
    if c not in countrylist : countrylist[c] = set()
    teamlist[t] = c
    countrylist[c].add(t)

#print(teamlist)
x = input()
#ค้น แต่ละทีมใน teamlist
question = []
while x != 'q' :
    x = x.split()
    question.append(x)
    x = input()

for m in question : #แต่ละทีม
    for t in m :
        if t in teamlist :
            c = teamlist[t] #ได้ประเทศมา
            a = countrylist[c] #ได้ทีมทั้งหมดมา
            if {t}.issubset(a) :
                b = True
            else :
                b = False
                print("Not OK")
                break
        else :
            print("Not OK")
            break
        
    if b == True : print("OK")


# 1679432, 2022-11-12 10:10:36, PPP (100%)

#password : good_LUCK
#input ==> {team : ประเทศ}
teamlist = dict()
countrylist = dict()
for i in range (int(input())) :
    t,c = input().split()
    if t not in teamlist : teamlist[t] = dict()
    if c not in countrylist : countrylist[c] = set()
    teamlist[t] = c
    countrylist[c].add(t)

#print(teamlist)
x = input()
#ค้น แต่ละทีมใน teamlist
question = []
while x != 'q' :
    x = x.split()
    question.append(x)
    x = input()

for m in question : #แต่ละทีม
    think = []
    for t in m : #แต่ละทีม []
        if t in teamlist :
            if teamlist[t] not in think :
                think.append(teamlist[t])
            else :
                print("Not OK")
                think = []
                break
        else :
            print("Not OK")
            think = []
            break
        
    if len(think) != 0 : print("OK")

            
            
        
        



6530199921
# 1678686, 2022-11-12 09:29:31, xxx (0%)

teams = {}
countries = {}
for i in range(int(input())) :
    team, country = input().strip().split()
    teams[team] = country
    if country not in countries : countries[country] = set()
    countries[country].add(team)
# club = {t: c for c, t in countries.items()}
while True :
    ans = {}
    group = input()
    if group == 'q' : break
    group = group.strip().split()
    for i in group :
        if i not in teams :
            print("Not OK")
            break
        else :
            ans.add(teams[i])
    if len(ans) != len(group) :
        print("Not OK")
    else :
        print("OK")
# 1678732, 2022-11-12 09:31:36, PP- (67%)

teams = {}
countries = {}
for i in range(int(input())) :
    team, country = input().strip().split()
    teams[team] = country
    if country not in countries : countries[country] = set()
    countries[country].add(team)
# club = {t: c for c, t in countries.items()}
while True :
    ans = set()
    group = input()
    if group == 'q' : break
    group = group.strip().split()
    for i in group :
        if i not in teams :
            print("Not OK")
            break
        else :
            ans.add(teams[i])
    if len(ans) != len(group) :
        print("Not OK")
    else :
        print("OK")
# 1678967, 2022-11-12 09:44:52, PPP (100%)

teams = {}
countries = {}
for i in range(int(input())) :
    team, country = input().strip().split()
    teams[team] = country
    if country not in countries : countries[country] = set()
    countries[country].add(team)
# club = {t: c for c, t in countries.items()}
while True :
    ans = set()
    group = input()
    c = True
    if group == 'q' : break
    group = group.strip().split()
    for i in group :
        if i not in teams :
            print("Not OK")
            c = False
            break
        else :
            ans.add(teams[i])
    if len(ans) != len(group) and c :
        print("Not OK")
    elif len(ans) == len(group) :
        print("OK")


6531313221
# 1678483, 2022-11-12 09:16:10, PPx (67%)

n = int(input())
countryOf = {}

for i in range(n):
    team, country = input().split()
    countryOf[team] = country

while True:
    s = input()
    if s == 'q':
        break
    teams = s.split()
    has = set()
    same = False
    for team in teams:
        country = countryOf[team]
        if country in has:
            same = True
            continue
        has.add(country)
    if same:
        print("Not OK")
    else:
        print("OK")

# 1678486, 2022-11-12 09:16:55, PPP (100%)

n = int(input())
countryOf = {}

for i in range(n):
    team, country = input().split()
    countryOf[team] = country

while True:
    s = input()
    if s == 'q':
        break
    teams = s.split()
    has = set()
    same = False
    for team in teams:
        if team in countryOf:
            country = countryOf[team]
        else:
            same = True
            continue
        if country in has:
            same = True
            continue
        has.add(country)
    if same:
        print("Not OK")
    else:
        print("OK")

# 1678494, 2022-11-12 09:17:28, PPP (100%)

n = int(input())
countryOf = {}

for i in range(n):
    team, country = input().split()
    countryOf[team] = country

while True:
    s = input()
    if s == 'q':
        break
    teams = s.split()
    has = set()
    same = False
    for team in teams:
        if team in countryOf:
            country = countryOf[team]
        else:
            same = True
            continue
        if country in has:
            same = True
            continue
        has.add(country)
    if same:
        print("Not OK")
    else:
        print("OK")


6531314921
# 1678512, 2022-11-12 09:19:15, xxx (0%)

a = int(input())
b = []
for i in range(a):
    c = input().split()
    b.append(c[1], c[0])
d = input()
while d != 'q':
    f = True
    e = []
    d = d.split()
    for i in d:
        for j in b:
            if i == j[0]:
                if j[0] in e:
                    f = False
                else:
                    e.append(j[1])
    if f == True:
        print('OK')
    else:
        print('Not OK')

# 1678517, 2022-11-12 09:19:39, xxx (0%)

a = int(input())
b = []
for i in range(a):
    c = input().split()
    b.append(c[1], c[0])
d = input()
while d != 'q':
    f = True
    e = []
    d = d.split()
    for i in d:
        for j in b:
            if i == j[0]:
                if j[0] in e:
                    f = False
                else:
                    e.append(j[1])
    d = input()
    if f == True:
        print('OK')
    else:
        print('Not OK')

# 1678681, 2022-11-12 09:29:18, PPP (100%)

a = int(input())
b = []
for i in range(a):
    c = input().split()
    b.append([c[1], c[0]])
d = input()
while d != 'q':
    f = True
    e = []
    d = d.split()
    for i in d:
        for j in b:

            if i == j[1]:
                if len(j) != 2:
                    f = False
                elif j[0] in e:
                    f = False
                else:
                    e.append(j[0])
    if f == True and len(d) == len(e):
        print('OK')
    else:
        print('Not OK')
    d = input()


6532043021
# 1678529, 2022-11-12 09:20:56, xxx (0%)

n = int(input())
mark = {}
mark2 = []
for i in range(n):
    name,country = input().split()
    mark[name] = country
    mark2.append(name)

while(1):
    ch = []
    ch2 = False
    s = input().split()
    if(s=='q'):
        break
    for e in s:
        if((not e in mark2) or mark[e] in ch):
            ch2 = True
            break
    if(ch2):
        print('Not OK')
    else:
        print('OK')


# 1678607, 2022-11-12 09:25:13, --x (0%)

n = int(input())
mark = {}
mark2 = []
for i in range(n):
    name,country = input().split()
    mark[name] = country
    mark2.append(name)

while(1):
    ch = []
    ch2 = False
    s = input().split()
    if(s[0]=='q'):
        break
    for e in s:
        if((not e in mark2) or mark[e] in ch):
            ch.append(mark[e])
            ch2 = True
            break
    if(ch2):
        print('Not OK')
    else:
        print('OK')


# 1678755, 2022-11-12 09:32:51, PPP (100%)

n = int(input())
mark = {}
mark2 = []
for i in range(n):
    name,country = input().split()
    mark[name] = country
    mark2.append(name)

while(1):
    ch = []
    ch2 = False
    s = input().split()
    if(s[0]=='q'):
        break
    for e in s:
        if((not e in mark2) or mark[e] in ch):
            ch2 = True
            break
        if e in mark:
            ch.append(mark[e])
        
    if(ch2):
        print('Not OK')
    else:
        print('OK')



6532100021
# 1678589, 2022-11-12 09:24:33, PP- (67%)

land = {}
n = int(input())
for i in range(n):
    team, city = input().split()
    land[team] = city
g = input().split()
while g[0] != "q":
    try:
        for i in g:
            check = False
            for j in g:
                if land[i] == land[j] and j != i:
                    check = True
                    break
        if check:
            print("Not OK")
        else:
            print("OK")
    except:
        print("Not OK")

    g = input().split()

# 1679065, 2022-11-12 09:50:19, PP- (67%)

land = {}
result = []
n = int(input())
for i in range(n):
    team, city = input().split()
    land[team] = city
g = input().split()
while g[0] != "q":
    try:
        for i in g:
            check = False
            for j in g:
                if land[i] == land[j] and j != i:
                    check = True
                    break
        if check:
            result.append("Not OK")
        else:
            result.append("OK")
    except:
        result.append("Not OK")

    g = input().split()
for i in result:
    print(i)

# 1679670, 2022-11-12 10:22:52, PPP (100%)

land = {}
result = []
n = int(input())
for i in range(n):
    team, city = input().split()
    land[team] = city
g = input().split()
while g[0] != "q":
    try:
        for i in g:
            check = False
            for j in g:
                if land[i] == land[j] and j != i:
                    check = True
                    break
            if check:
                break
        if check:
            result.append("Not OK")
        else:
            result.append("OK")
    except:
        result.append("Not OK")

    g = input().split()
for i in result:
    print(i)


6531017521
# 1679794, 2022-11-12 10:28:13, xxx (0%)

team = {}
for i in range(int(input())):
    name, nation = input().split()
    if name not in team.keys():
        team[name] = nation
teamname = []
for e in team.keys():
    teamname.append(e)
    
x = input().split()
while x != "qq":
    r = True
    c = []
    for i in range(len(x)):
        if x[i] in teamname:
            if team[x[i]] in c:
                print("Not OK")
                r = False
                break
                c.append(team[x[i]])
            else :
                print("Not OK")
                r = False 
                
        if r == True :
            print("OK")

    x = input().strip().split()


# 1679832, 2022-11-12 10:29:38, --- (0%)

team = {}
for i in range(int(input())):
    name, nation = input().split()
    if name not in team.keys():
        team[name] = nation
teamname = []
for e in team.keys():
    teamname.append(e)
    
x = input().split()
while x != ["q"]:
    r = True
    c = []
    for i in range(len(x)):
        if x[i] in teamname:
            if team[x[i]] not in c:
                print("Not OK")
                r = False
                break
                c.append(team[x[i]])
            else :
                print("Not OK")
                r = False 
                
        if r == True :
            print("OK")

    x = input().strip().split()


# 1679891, 2022-11-12 10:31:29, PPP (100%)

team = {}
for i in range(int(input())):
    name, nation = input().split()
    if name not in team.keys():
        team[name] = nation
teamname = []
for e in team.keys():
    teamname.append(e)
    
x = input().split()
while x != ["q"]:
    r = True
    c = []
    for i in range(len(x)):
        if x[i] in teamname:
            if team[x[i]] in c:
                print("Not OK")
                r = False
                break
            c.append(team[x[i]])
        else :
            print("Not OK")
            r = False 
                
    if r == True :
        print("OK")

    x = input().strip().split()



6531020321
# 1678956, 2022-11-12 09:44:18, PPx (67%)

x = {}
for i in range(int(input())):
    team, country = input().split()
    x[team] = country
s = input().split()
t = 'OK'
while s[0] != 'q':
    w = set()
    w.add(x[s[0]])
    for i in range(1,len(s)):
        if s[i] in x.keys():
            if x[s[i]] in w:
                t = 'Not OK'
                break
            else:
                w.add(x[s[i]])
        else:
            t = 'Not OK'
            break
        
    print(t)
    s = input().split()
# 1679278, 2022-11-12 10:02:01, PPx (67%)

x = {}
for i in range(int(input())):
    team, country = input().split()
    x[team] = country
s = input().split()

while s[0] != 'q':
    t = 'OK'
    w = set()
    w.add(x[s[0]])
    for i in range(1,len(s)):
        if s[i] in x.keys():
            if x[s[i]] in w:
                t = 'Not OK'
                break
            else:
                w.add(x[s[i]])
        elif s[i] not in x.keys():
            t = 'Not OK'
            break
    print(t)
    s = input().split()
# 1679972, 2022-11-12 10:35:38, PPP (100%)

x = {}
for i in range(int(input())):
    team, country = input().split()
    x[team] = country
s = input().split()
while s[0] != 'q':
    t = 'OK'
    w = set()
    if s[0] in x.keys():
        w.add(x[s[0]])
        for i in range(1,len(s)):
            if s[i] in x.keys():
                if x[s[i]] in w:
                    t = 'Not OK'
                    break
                else:
                    w.add(x[s[i]])
            elif s[i] not in x.keys():
                t = 'Not OK'
                break
    else:
        t = 'Not OK'
    print(t)
    s = input().split()

6531028421
# 1679395, 2022-11-12 10:08:17, xxx (0%)

n = int(input())
Team_dict = {}
for i in range(n):
    team = input().strip().split()
    Team_dict[team[0]] = team[1]
m = input().strip().split()
Tl = []
for d,v in Team_dict.items() :
    Tl.append(d)

while m != 'q' :
    check = []
    t = True
    for i in m :
        if i in Tl :
            if Team_dict[i] in check :
                print('Not OK')
                t = False 
                break
            check.append(Team_dict[i])
        else :
            print('Not OK')
    if t == True :
            print('OK')
    m = input().strip().split()
    
        
    

# 1679421, 2022-11-12 10:10:03, xxx (0%)

n = int(input())
Team_dict = {}
for i in range(n):
    team = input().strip().split()
    Team_dict[team[0]] = team[1]
m = input().strip().split()
Tl = []
for d,v in Team_dict.items() :
    Tl.append(d)

while m != 'q' :
    check = []
    t = True
    for i in m :
        if i in Tl :
            if Team_dict[i] in check :
                print('Not OK')
                t = False 
                break
            check.append(Team_dict[i])
        else :
            print('Not OK')
            t = False
    if t == True :
            print('OK')
    m = input().strip().split()
    
        
    

# 1679437, 2022-11-12 10:10:55, PPP (100%)

n = int(input())
Team_dict = {}
for i in range(n):
    team = input().strip().split()
    Team_dict[team[0]] = team[1]
m = input().strip().split()
Tl = []
for d,v in Team_dict.items() :
    Tl.append(d)

while m != ['q'] :
    check = []
    t = True
    for i in m :
        if i in Tl :
            if Team_dict[i] in check :
                print('Not OK')
                t = False 
                break
            check.append(Team_dict[i])
        else :
            print('Not OK')
            t = False
    if t == True :
            print('OK')
    m = input().strip().split()
    
        
    


6531106721
# 1679145, 2022-11-12 09:54:54, --- (0%)

n= int(input())
all={} #{ประเทศ:[ทีม1,t2]}
for i in range(n):
    team, country = input().split()
    team=team.strip(); country= country.strip()
    if team in all:
        all[team].append(country)
    elif country not in all:
        all[team]=[country]
def dupl(a):
    for z in range(len(a)-1):
        if ["omg"] in a:
            return ("NOT OK")
        else:
            if a[z] == a[z+1]:
                return ("NOT OK")
    return ("OK")
l= input().split()
while True:
    new=[]
    for x in l:
        if x not in all:
            new.append(["omg"])
        elif x in all:
            new.append(all[x])            
    newone=sorted(new)
    print(dupl(newone))
    l= input().split()
    if l == ["q"]:
        break
# 1679181, 2022-11-12 09:56:48, --- (0%)

n= int(input())
all={} #{ประเทศ:[ทีม1,t2]}
for i in range(n):
    team, country = input().split()
    team=team.strip(); country= country.strip()
    if team in all:
        all[team].append(country)
    elif country not in all:
        all[team]=[country]
def dupl(a):
    if ["omg"] in a:
          return ("NOT OK")
    else:
      for z in range(len(a)-1):
          if a[z] == a[z+1]:
              return ("NOT OK")
    return ("OK")
l= input().split()
while True:
    new=[]
    for x in l:
        if x not in all:
            new.append(["omg"])
        elif x in all:
            new.append(all[x])            
    newone=sorted(new)
    print(dupl(newone))
    l= input().split()
    if l == ["q"]:
        break
# 1679205, 2022-11-12 09:58:03, PPP (100%)

n= int(input())
all={} #{ประเทศ:[ทีม1,t2]}
for i in range(n):
    team, country = input().split()
    team=team.strip(); country= country.strip()
    if team in all:
        all[team].append(country)
    elif country not in all:
        all[team]=[country]
def dupl(a):
    if ["omg"] in a:
          return ("Not OK")
    else:
      for z in range(len(a)-1):
          if a[z] == a[z+1]:
              return ("Not OK")
    return ("OK")
l= input().split()
while True:
    new=[]
    for x in l:
        if x not in all:
            new.append(["omg"])
        elif x in all:
            new.append(all[x])            
    newone=sorted(new)
    print(dupl(newone))
    l= input().split()
    if l == ["q"]:
        break

6230089221
# 1678646, 2022-11-12 09:27:29, --- (0%)

n=int(input())
country={}
for i in range(n):
    s=input().split(" ")
    if s[1] in country:
        country[s[0]].append(s[1])
    else:
        country[s[0]]=s[1]
p=input().strip()
while p!="q":
    p=p.split(" ")
    c=True
    for i in range(len(p)):
        for j in range(i+1,len(p),1):
            if p[i] in country and p[j] in country:
                if country[p[i]]==country[p[j]]:
                    c=False
                    break
            else:
                c=False
    if c==True:
        print("OK")
    else:
        print("NOT OK")
    p=input().strip()
# 1678662, 2022-11-12 09:28:27, PPP (100%)

n=int(input())
country={}
for i in range(n):
    s=input().split(" ")
    if s[1] in country:
        country[s[0]].append(s[1])
    else:
        country[s[0]]=s[1]
p=input().strip()
while p!="q":
    p=p.split(" ")
    c=True
    for i in range(len(p)):
        for j in range(i+1,len(p),1):
            if p[i] in country and p[j] in country:
                if country[p[i]]==country[p[j]]:
                    c=False
                    break
            else:
                c=False
    if c==True:
        print("OK")
    else:
        print("Not OK")
    p=input().strip()

6230141121
# 1678867, 2022-11-12 09:38:51, --- (0%)

tn = {}
for i in range (int(input())) :
    t,n = input().split()
    tn[t] = n
g = input()
out = []
s = 0
while g != 'q' :
    a = g.split()
    for i in a :
        if i not in tn :
            s = 1
            break
        out.append(tn[i])
    out.sort()
    for i in range(len(out)):
        for k in range(i+1,len(out)):
            if out[i] == out[k] :
                s = 1
                break
    if s == 1:
        print('Not OK')
    else :
        print('OK')
    g = input()
# 1678942, 2022-11-12 09:43:45, PPP (100%)

tn = {}
for i in range (int(input())) :
    t,n = input().split()
    tn[t] = n
g = input()
out = []
s = 0
while g != 'q' :
    a = g.split()
    for i in a :
        if i not in tn :
            s = 1
            break
        out.append(tn[i])
    out.sort()
    for i in range(len(out)):
        for k in range(i+1,len(out)):
            if out[i] == out[k] :
                s = 1
                break
    if s == 1:
        print('Not OK')
    else :
        print('OK')
    g = input()
    out = []
    s = 0

6231720721
# 1679153, 2022-11-12 09:55:19, --- (0%)

ccd = {} #country:club
for team in range(int(input())):
    club,con = input().split()
    if club not in ccd: ccd[club]=''
    ccd[club]=con
A = True
final = []
print(ccd)
while True:
    x = [e.strip() for e in input().split()]
    print(x)
    if x[0] == 'q':
        break
    c = set()
    for team in x:
        
        if team not in ccd:
            break
        else:
            c.add(ccd[team])
    
    if len(c) == len(x):
        final.append('OK')
    else:
        final.append('Not OK')
    c = set()
for prin in final:
    print(prin)
    
            

        
        
        
    

# 1679168, 2022-11-12 09:56:09, PPP (100%)

ccd = {} #country:club
for team in range(int(input())):
    club,con = input().split()
    if club not in ccd: ccd[club]=''
    ccd[club]=con
A = True
final = []

while True:
    x = [e.strip() for e in input().split()]
    
    if x[0] == 'q':
        break
    c = set()
    for team in x:
        
        if team not in ccd:
            break
        else:
            c.add(ccd[team])
    
    if len(c) == len(x):
        final.append('OK')
    else:
        final.append('Not OK')
    c = set()
for prin in final:
    print(prin)
    
            

        
        
        
    


6431523621
# 1678520, 2022-11-12 09:20:02, --- (0%)

d = {}
for i in range(int(input())) :
    t,c = input().split()
    d[t] = c
while True :
    team = input().split()
    if len(team)==1 : break
    qq = True
    ct = []
    for i in team :
        if i not in d :
            print('Not OK')
            qq = False
            break
        else :
            ct.append(d[i])
if qq :
    if len(set(ct))==1 :
        print('OK')
    else :
        print('Not OK')
            


# 1678573, 2022-11-12 09:23:27, PPP (100%)

d = {}
for i in range(int(input())) :
    t,c = input().split()
    d[t] = c
while True :
    qq = True
    team = input().split()
    if len(team)==1 : break
    ct = []
    for i in team :
        if i not in d :
            print('Not OK')
            qq = False
            break
        else :
            ct.append(d[i])
    if qq :
        if len(set(ct))==len(team) :
            print('OK')
        else :
            print('Not OK')
            



6530006421
# 1678804, 2022-11-12 09:35:47, PP- (67%)

# Task Quiz_3_1
# This Code was written by Folkiesss Desu!!

table = dict()  # {country: {team}}
all_team = set()
ch = bool()

for i in range(int(input())):
    team, country = input().split()
    if country not in table:
        table[country] = set()
    table[country].add(team)
    all_team.add(team)

while True:
    line = input()

    if line == "q":
        break

    else:
        teams = line.split()
        for country in table:
            c = 0
            for team in teams:
                if team not in all_team:
                    ch == True
                if team in table[country]:
                    c += 1
            if c > 1:
                ch = True
                
        print("Not OK" if ch else "OK")
              
# 1679128, 2022-11-12 09:53:51, PPP (100%)

# Task Quiz_3_1
# This Code was written by Folkiesss Desu!!

table = dict()  # {country: {team}}
all_team = set()

for i in range(int(input())):
    team, country = input().split()
    if country not in table:
        table[country] = set()
    table[country].add(team)
    all_team.add(team)

while True:
    ch = False
    line = input()

    if line == "q":
        break

    else:
        teams = line.split()
        for country in table:
            c = 0
            for team in teams:
                if team in table[country]:
                    c += 1
                if c > 1:
                    ch = True
                    
                if team not in all_team:
                    ch = True

        print("Not OK" if ch else "OK")


6530018021
# 1678770, 2022-11-12 09:34:01, PP- (67%)

def check(dic,list):
  for i in list:
      for j in list:
          for k in dic:
              if i != j and i in dic[k] and j in dic[k]:
                  return 'Not OK'
  return 'OK'

n = int(input())
dicto = {}
for i in range(0,n):
    listo = input().split()
    if listo[1] in dicto:
        dicto[listo[1]].append(listo[0])
    else:
        dicto[listo[1]] = [listo[0]]

input3 = []
output = []
input2 = input().split()
input3.append(input2)
while 'q' not in input2:
    input2 = input().split()
    input3.append(input2)
input3.pop(-1)
for f in range(0,len(input3)):
    output.append(check(dicto,input3[f]))
for i in output:
    print(i)
# 1678862, 2022-11-12 09:38:40, PPP (100%)

def check(dic,list,checker):
  for i in list:
      for j in list:
          for k in dic:
              if i not in checker or j not in checker:
                  return 'Not OK'
              elif i != j and i in dic[k] and j in dic[k]:
                  return 'Not OK'
  return 'OK'

n = int(input())
dicto = {}
checker = []
for i in range(0,n):
    listo = input().split()
    checker.append(listo[0])
    if listo[1] in dicto:
        dicto[listo[1]].append(listo[0])
    else:
        dicto[listo[1]] = [listo[0]]

input3 = []
output = []

input2 = input().split()
input3.append(input2)
while 'q' not in input2:
    input2 = input().split()
    input3.append(input2)
input3.pop(-1)
for f in range(0,len(input3)):
    output.append(check(dicto,input3[f],checker))
for i in output:
    print(i)

6530019621
# 1678608, 2022-11-12 09:25:19, --- (0%)

n = int(input())
AllNation = dict()
AllTeam = []
for i in range(n):
    x = input().strip().split()
    Team = x[0].strip()
    Nation = x[1].strip()
    if Nation not in AllNation:
        AllNation[Nation] = [Team]
    else:
        AllNation[Nation].append(Team)
    if Team not in AllTeam:
        AllTeam.append(Team)
    
#print(AllNation)

def Find_Nation(Team):
    for Nation in AllNation:
        if Team in AllNation[Nation]:
            return Nation

Ans = []
x = input().strip().split()
while len(x) != 1:
    Country = []
    a = True
    for Team in x:
        Team = Team.strip()
        if Team not in AllTeam:
            a = False
        else:
            Nation = Find_Nation(Team)
            if Nation not in Country:
                Country.append(Nation)
            else:
                pass
    x = input().strip().split()
    if len(x) == len(Country) and a == True:
        Ans.append('OK')
    else:
        Ans.append('Not OK')
    
for ans in Ans:
    print(ans)
        
    
    

# 1678659, 2022-11-12 09:28:14, PPP (100%)

n = int(input())
AllNation = dict()
AllTeam = []
for i in range(n):
    x = input().strip().split()
    Team = x[0].strip()
    Nation = x[1].strip()
    if Nation not in AllNation:
        AllNation[Nation] = [Team]
    else:
        AllNation[Nation].append(Team)
    if Team not in AllTeam:
        AllTeam.append(Team)
    
#print(AllNation)

def Find_Nation(Team):
    for Nation in AllNation:
        if Team in AllNation[Nation]:
            return Nation

Ans = []
x = input().strip().split()
while len(x) != 1:
    Country = []
    a = True
    for Team in x:
        Team = Team.strip()
        if Team not in AllTeam:
            a = False
        else:
            Nation = Find_Nation(Team)
            if Nation not in Country:
                Country.append(Nation)
            else:
                pass
    
    if len(x) == len(Country) and a == True:
        Ans.append('OK')
    else:
        Ans.append('Not OK')
    x = input().strip().split()
    
for ans in Ans:
    print(ans)
        
    
    


6530024721
# 1678603, 2022-11-12 09:25:02, PP- (67%)

n = int(input())
d = {}
t = []
for i in range(n) :
    team,nat = input().split()
    t.append(team)
    if nat not in d :
        d[nat] = [team]
    else :    
        d[nat].append(team)
        
c = True
x = input().strip()
while x != 'q' :
    x = x.split()
    for i in range(len(x)-1) :
        for j in range(i+1,len(x)) :
            t1 = x[i]
            t2 = x[j]
            if t1 not in t :
                c = False
            if t2 not in t :
                c = False
            for e in d :
                if t1 in d[e] and t2 in d[e] :
                    c = False
                    break
            if not c :
                break
        if not c :
            break
    if c :
        print('OK')
    else :
        print('Not OK')
        
    x = input().strip()
# 1678772, 2022-11-12 09:34:04, PPP (100%)

n = int(input())
d = {}
t = []
pra = []
for i in range(n) :
    team,nat = input().split()
    t.append(team)
    if nat not in d :
        d[nat] = [team]
    else :    
        d[nat].append(team)
    if not nat in pra :
        pra.append(nat)    
c = True
x = input().strip()
while x != 'q' :
    x = x.split()
    c = True
    for i in range(len(x)-1) :
        for j in range(i+1,len(x)) :
            t1 = x[i]
            t2 = x[j]
            if t1 not in t :
                c = False
            if t2 not in t :
                c = False
            for e in pra :
                if t1 in d[e] and t2 in d[e] :
                    c = False
                    break
            if not c :
                break
        if not c :
            break
    if c :
        print('OK')
    else :
        print('Not OK')
        
    x = input().strip()        

6530026021
# 1678948, 2022-11-12 09:43:58, --- (0%)

n = int(input())
l = {}
for i in range(n) :
    x = input().strip()
    tn,c = x.split()
    l[tn] = c
x = input()
d = []
while x != 'q' :
    a = 'g'
    x = x.split()
    for i in range(len(x)) :
        if x[i] in l :
            d.append(l[x[i]])
        else :
            d.append('gg')
    for h in d :
        if h == 'gg' :
            a = 'n'
    d = sorted(d)
    for j in range(len(d)-1) :
        if d[j] == d[j+1] :
            a = 'n'
    
    if a == 'n' :
        print('Not OK')
    if a == 'g' :
        print('OK')
    x = input()
# 1679013, 2022-11-12 09:47:44, PPP (100%)

n = int(input())
l = {}
for i in range(n) :
    x = input().strip()
    tn,c = x.split()
    l[tn] = c
x = input()
ans = []
while x != 'q' :
    d = []
    a = 'g'
    x = x.split()
    for i in range(len(x)) :
        if x[i] in l :
            d.append(l[x[i]])
        else :
            d.append('gg')
    for h in d :
        if h == 'gg' :
            a = 'n'
    d = sorted(d)
    for j in range(len(d)-1) :
        if d[j] == d[j+1] :
            a = 'n'
    if a == 'n' :
        ans.append('Not OK')
    if a == 'g' :
        ans.append('OK')
    x = input()
for i in ans :
    print(i)

6530029921
# 1679155, 2022-11-12 09:55:25, --- (0%)

n = int(input())
country = dict()
for i in range(n):
    info = input().strip().split()
    if info[1] not in country:
        country[info[1]] = {info[0]}
    else:
        temp = country.get(info[1])
        temp.add(info[0])
        



print(country)
while True:
    names = input().strip().split()
    team = [i for i in names]
    if len(names) == 1:
        break
    counts = []
    for i in country:
        for j in names:
            if j in country[i]:
                counts.append(i)
  
    ch = []
    for i in counts:
        if counts.count(i) > 1:
           ch.append(False)
        else:
            ch.append(True)
    
    if len(team) != len(counts) or False in ch:
        print("Not OK")
    else:
        print("OK")
# 1679165, 2022-11-12 09:55:52, PPP (100%)

n = int(input())
country = dict()
for i in range(n):
    info = input().strip().split()
    if info[1] not in country:
        country[info[1]] = {info[0]}
    else:
        temp = country.get(info[1])
        temp.add(info[0])
        




while True:
    names = input().strip().split()
    team = [i for i in names]
    if len(names) == 1:
        break
    counts = []
    for i in country:
        for j in names:
            if j in country[i]:
                counts.append(i)
  
    ch = []
    for i in counts:
        if counts.count(i) > 1:
           ch.append(False)
        else:
            ch.append(True)
    
    if len(team) != len(counts) or False in ch:
        print("Not OK")
    else:
        print("OK")

6530033321
# 1679627, 2022-11-12 10:21:05, --- (0%)

d = {}
for i in range(int(input())):
    team, country = input().split()
    d[team] = country

while True:
    n = input().strip()
    if n == 'q':
        break
    else:
        t = n.split()
        l = []
        for i in t:
            if i in d:
                if i not in l:
                    l.append(i)
            else:
                print("Not OK")
                break
        if len(l) == len(t):
            print("OK")
        else:
            print("Not OK")
        
       


# 1679668, 2022-11-12 10:22:49, PPP (100%)

d = {}
for i in range(int(input())):
    team, country = input().split()
    d[team] = country

while True:
    n = input().strip()
    if n == 'q':
        break
    else:
        t = n.split()
        l = []
        for i in t:
            if i in d:
                if d[i] not in l:
                    l.append(d[i])
            else:
                break
        if len(l) == len(t):
            print("OK")
        else:
            print("Not OK")

6530037921
# 1678743, 2022-11-12 09:32:13, xxx (0%)

group = {}
allgroup = set()
for i in range(int(input())):
    t,c = input().split()
    if c not in group: group[c] = set()
    group[c].add(t)
    allgroup.add(t)
while True:
    x = input().split()
    count = 0
    if x == "q": break
    same = set()
    for i in x:
        same.add(i)
    for j in group:
        if len(group[j]&same) >1:
            count += 1
    if len(same&allgroup) != len(same):
        print("Not OK")
        pass
    if count >= 1:
        print("Not OK")
    else:
        print("OK")
# 1678790, 2022-11-12 09:35:01, PPP (100%)

group = {}
allgroup = set()
for i in range(int(input())):
    t,c = input().split()
    if c not in group: group[c] = set()
    group[c].add(t)
    allgroup.add(t)
while True:
    x = input().split()
    count = 0
    if x[0] == "q":
        break
    same = set()
    for i in x:
        same.add(i)
    for j in group:
        if len(group[j]&same) >1:
            count += 1
    if len(same&allgroup) != len(same):
        print("Not OK")
    elif count >= 1:
        print("Not OK")
    else:
        print("OK")
        

6530040721
# 1678709, 2022-11-12 09:30:33, --- (0%)

x = {}
for i in range(int(input())):
    z1,z2 = input().split()
    x[z1] = z2
z0 = input().split()
while z0 != ['q']:
    y = []
    c = 0
    for i in z0:
        if i not in x:
            print('Not OK')
            break
        if x[i] in y:
            print('Not OK')
            break
        y.append(x[i])
        c+=1
    if c == len(z0):
        print('ok')
    z0 = input().split()
# 1678723, 2022-11-12 09:31:09, PPP (100%)

x = {}
for i in range(int(input())):
    z1,z2 = input().split()
    x[z1] = z2
z0 = input().split()
while z0 != ['q']:
    y = []
    c = 0
    for i in z0:
        if i not in x:
            print('Not OK')
            break
        if x[i] in y:
            print('Not OK')
            break
        y.append(x[i])
        c+=1
    if c == len(z0):
        print('OK')
    z0 = input().split()

6530041321
# 1678597, 2022-11-12 09:24:47, -P- (33%)

n = int(input())
d = {}
for i in range(n):
    t, c = input().split()
    d[t] = c

team = input()
check = set()
while team != 'q':
    team = team.split()
    for e in team:
        if e in d:
            check.add(d[e])
    if len(team) == len(check):
        print('OK')
    else:
        print('Not OK')
    team = input()
# 1678638, 2022-11-12 09:27:03, PPP (100%)

n = int(input())
d = {}
for i in range(n):
    t, c = input().strip().split()
    d[t] = c

team = input().strip()
check = set()
while team != 'q':
    team = team.split()
    for e in team:
        if e in d:
            check.add(d[e])
    if len(team) == len(check):
        print('OK')
    else:
        print('Not OK')
    team = input().strip()
    check = set()

6530044221
# 1678604, 2022-11-12 09:25:06, --- (0%)

a = {}
team = []
for i in range(int(input())):
    s = input().split()
    a[s[0]] = [s[1]]
    team.append(s[0])

while True:
    c = input().split()
    if c[0] == "q":
        break
    q = []
    for i in range(len(c)) :
        if c[i] in team:
            if a[c[i]] not in q:
                q.append(a[c[i]])
            else :
                print("Not OK")
        else :
            print("Not OK")
            break
        if i == len(c)-1 :
            print("OK")

# 1678617, 2022-11-12 09:25:52, PPP (100%)

a = {}
team = []
for i in range(int(input())):
    s = input().split()
    a[s[0]] = [s[1]]
    team.append(s[0])

while True:
    c = input().split()
    if c[0] == "q":
        break
    q = []
    for i in range(len(c)) :
        if c[i] in team:
            if a[c[i]] not in q:
                q.append(a[c[i]])
            else :
                print("Not OK")
                break
        else :
            print("Not OK")
            break
        if i == len(c)-1 :
            print("OK")

6530048821
# 1679201, 2022-11-12 09:57:50, PP- (67%)

team = {} #{name: country}
for i in range(int(input())):
    inp = input().split()
    team[inp[0]] = inp[1]
lineup = input()
while lineup != 'q':
    lineup = lineup.split()
    el = True
    for i in lineup:
        if i not in team:
            el = False
    for t0 in lineup:
        if not el:
            el = False
        else:
            for t in lineup:
                for t1 in lineup:
                    if t == t1:
                        pass
                    else:
                        if team[t] == team[t1]:
                            el = False
                        else:
                            
                            if not el:
                                el = True
                            else:
                                el = False
                            
    if el:
        print('OK')
    else:
        print('Not OK')
    lineup = input()

# 1679298, 2022-11-12 10:02:44, PPP (100%)

team = {} #{name: country}
for i in range(int(input())):
    inp = input().split()
    team[inp[0]] = inp[1]
lineup = input()
while lineup != 'q':
    lineup = lineup.split()
    el = True
    for i in lineup:
        if i not in team:
            el = False
    for t0 in lineup:
        if not el:
            el = False
        else:
            for t in lineup:
                for t1 in lineup:
                    if t == t1:
                        pass
                    else:
                        if team[t] == team[t1]:
                            #print('here')
                            el = False
                        else:
                            if el:
                                el = True
                                #print(team[t],team[t1])
                            else:
                                el = False
                            
    if el:
        print('OK')
    else:
        print('Not OK')
    lineup = input()


6530057421
# 1679001, 2022-11-12 09:47:08, PPx (67%)

team = {}
for k in range(int(input())):
    t,c = input().split()
    team[t] = c
inrules = set()
while True:
    x = input()
    if x == 'q':break
    g = x.split()
    p = [team[e] for e in g]
    for i in p:
        inrules.add(i)
    if len(inrules) != len(p):
        print('Not OK')
    else:
        print('OK')
    inrules = set()
# 1680673, 2022-11-12 11:05:16, PPP (100%)

team = {}
for k in range(int(input())):
    t,c = input().split()
    team[t] = c
inrules = set()
while True:
    x = input()
    if x == 'q':break
    x = x.split()
    for e in x:
        if e in team:
            inrules.add(team[e])
    if len(inrules) == len(x):
        print('OK')
    else:
        print('Not OK')
    inrules = set()

6530059721
# 1678534, 2022-11-12 09:21:11, PP- (67%)

#good_LUCK
fb = {}

n = int(input().strip())
for i in range(n):
    team,land = input().strip().split()
    fb[team] = land
    #ไม่ได้เช็คกรณีที่กรอกteamซ้ำ
   
skip = False
group = input().strip().split()
while group[0]!="q":
    check = set()
    for t in group:
        if t not in fb:
            skip = True
            break
        else:
            check.add(fb[t])
    if not skip and len(check)==len(group):
        print("OK")
    else: 
        print("Not OK")
    group = input().strip().split()

# 1678586, 2022-11-12 09:24:18, PPP (100%)

#good_LUCK
fb = {}

n = int(input().strip())
for i in range(n):
    team,land = input().strip().split()
    fb[team] = land
    #ไม่ได้เช็คกรณีที่กรอกteamซ้ำ
   
group = input().strip().split()
while group[0]!="q":
    skip = False
    check = set()
    for t in group:
        if t not in fb:
            skip = True
            break
        else:
            check.add(fb[t])
    if not skip and len(check)==len(group):
        print("OK")
    else: 
        print("Not OK")
    group = input().strip().split()


6530069021
# 1679221, 2022-11-12 09:59:02, PPx (67%)

team = {}
for i in range (int(input())):
    x,y = input().split()
    team[x]=y
x = input()
while x != 'q': 
    t = x.split()
    s =set()
    for i in t:
        s.add(team[i])
    if len(t) > len(s):
        print('Not OK')
    else:
        print('OK')
        
    
    x = input()
        
    
        


# 1679540, 2022-11-12 10:15:53, PPP (100%)

team = {}
for i in range (int(input())):
    x,y = input().split()
    team[x]=y
x = input()
while x != 'q': 
    t = x.split()
    s =set()    
    for i in t:
        if i not in team:
            pass
        else :
            s.add(team[i])
    if len(t) > len(s):
        print('Not OK')
    else:
        print('OK')
        
    
    x = input()



6530070521
# 1679024, 2022-11-12 09:48:06, xxx (0%)

#fighting...last quiz laew
#pass for quiz: good_LUCK 11:12
n = int(input())
countryteam = {}
for i in range(n):
    x = input().split()
    countryteam[x[0]] = x[1]


group = input().split(" ")
countryingroup = []
groupcon = set()
Ans = []
while group != 'q':
    for k in range(len(group)):
        if group[k] not in countryteam:
            Ans.append("Not OK")
        elif group[k] in countryteam:
            countryingroup.append(countryteam[group[k]])
    for j in range(len(countryingroup)):
        groupcon.add(countryingroup[j])
    if len(countryingroup) == len(groupcon):
        Ans.append("OK")
    else: Ans.append("Not OK")
    if "Not OK" in Ans:
        print("Not OK")
    else: print("OK")
    
    group = input().split(" ")


# 1679079, 2022-11-12 09:51:24, PPP (100%)

#fighting...last quiz laew
#pass for quiz: good_LUCK 11:12
n = int(input())
countryteam = {}
for i in range(n):
    x = input().split()
    countryteam[x[0]] = x[1]


group = input().split(" ")

while group != ['q']:
    countryingroup = []
    groupcon = set()
    Ans = []
    for k in range(len(group)):
        if group[k] not in countryteam:
            Ans.append("Not OK")
        elif group[k] in countryteam:
            countryingroup.append(countryteam[group[k]])
    for j in range(len(countryingroup)):
        groupcon.add(countryingroup[j])
    if len(countryingroup) == len(groupcon):
        Ans.append("OK")
    else: Ans.append("Not OK")
    if "Not OK" in Ans:
        print("Not OK")
    else: print("OK")
    
    group = input().split(" ")


6530079221
# 1679146, 2022-11-12 09:54:56, --- (0%)

n=int(input())
data={}
for i in range(n):
    team=input().split()
    data[team[0]]=team[1]
print(data)
 
name=input()
line=[]
line1=[]
line2=[]
while name != 'q':
    name=name.split()
    result=True
    for i in range(len(name)):
        if  name[i] not in data:
            line1.append('x')
            
        else:
            line1.append(data[name[i]])
            
    print(line1)
    if  len(set(line1)) == len(line1):
        if 'x' in line1:
            line.append('Not OK')
        else:
            line.append('OK')
    else:
        line.append('Not OK')       
    line1=[]   
    name=input()   
for i in line:
    print(i)

# 1679187, 2022-11-12 09:57:01, PPP (100%)

n=int(input())
data={}
for i in range(n):
    team=input().split()
    data[team[0]]=team[1]

name=input()
line=[]
line1=[]
line2=[]
while name != 'q':
    name=name.split()
    result=True
    for i in range(len(name)):
        if  name[i] not in data:
            line1.append('x')
            
        else:
            line1.append(data[name[i]])
            
    
    if  len(set(line1)) == len(line1):
        if 'x' in line1:
            line.append('Not OK')
        else:
            line.append('OK')
    else:
        line.append('Not OK')       
    line1=[]   
    name=input()   
for i in line:
    print(i)


6530082021
# 1678621, 2022-11-12 09:26:04, xxx (0%)

n = int(input())
country = {}
for i in range(n):
    k = fn.readline().strip().split()
    if k[1] not in country:
        country[k[1]] = {k[0]}
    else:
        country[k[1]].add(k[0])
p = input().split()
out = []
while p[0] != 'q':
    check = []
    for e in country:
        for g in p:
            if g in country[e]:
                check.append(e)
    if len(check) != len(p):
        print('Not OK')
    else:
        found = False
        for i in range(len(check)):
            for j in range(i+1,len(check)):
                if check[i] == check[j]:
                    found = True
                    print('Not OK')
                    break
        if not found:
            print('OK')
    p = input().split()
# 1678624, 2022-11-12 09:26:12, PPP (100%)

n = int(input())
country = {}
for i in range(n):
    k = input().split()
    if k[1] not in country:
        country[k[1]] = {k[0]}
    else:
        country[k[1]].add(k[0])
p = input().split()
out = []
while p[0] != 'q':
    check = []
    for e in country:
        for g in p:
            if g in country[e]:
                check.append(e)
    if len(check) != len(p):
        print('Not OK')
    else:
        found = False
        for i in range(len(check)):
            for j in range(i+1,len(check)):
                if check[i] == check[j]:
                    found = True
                    print('Not OK')
                    break
        if not found:
            print('OK')
    p = input().split()

6530087221
# 1678703, 2022-11-12 09:30:19, --- (0%)

n = int(input())
dict = {}
for i in range(n):
    x = input().split()
    if x == ['q'] :
        break
    else :
        dict[x[0]] = x[1]

k = 0
while k == 0 :
    check = 0
    temp = []
    group = input().split()
    
    if group == ['q'] :
        k += 1
    else :
        for i in group :
            if i not in dict :
                check += 1
            elif dict[i] not in temp :
                temp += [dict[i]]
            elif dict[i] in temp :
                check += 1
                
        if check == 0 :
            print('OK')
        if check != 0 :
            print('NOT OK')
    

# 1678733, 2022-11-12 09:31:37, PPP (100%)

n = int(input())
dict = {}
for i in range(n):
    x = input().split()
    if x == ['q'] :
        break
    else :
        dict[x[0]] = x[1]

k = 0
while k == 0 :
    check = 0
    temp = []
    group = input().split()
    
    if group == ['q'] :
        k += 1
    else :
        for i in group :
            if i not in dict :
                check += 1
            elif dict[i] not in temp :
                temp += [dict[i]]
            elif dict[i] in temp :
                check += 1
                
        if check == 0 :
            print('OK')
        if check != 0 :
            print('Not OK')
    


6530088921
# 1678886, 2022-11-12 09:40:08, --- (0%)

n = int(input())
mdc = {}
for i in range (n):
    team , c = input().split()
    if c in mdc:
        mdc[team]+=[c]
    else:
        mdc[team]=[c]
    w=i+1
while True:
    i = input()
    cou = [] ; result = True ; ans = []
    if i == 'q' : break
    comp = i.split()
    for k in comp:
        if k in mdc:
            for u in mdc[k]:
                if u in cou:
                    result = False ; break
                else :
                    cou += [u]
        else :
            result = False ; break
    if result == True : ans += ['OK']
    elif result == False : ans += ['Not OK']
for i in ans : print(i)
# 1678894, 2022-11-12 09:40:55, PPP (100%)

n = int(input())
mdc = {}
for i in range (n):
    team , c = input().split()
    if c in mdc:
        mdc[team]+=[c]
    else:
        mdc[team]=[c]
    w=i+1
while True:
    i = input()
    cou = [] ; result = True ;
    if i == 'q' : break
    comp = i.split()
    for k in comp:
        if k in mdc:
            for u in mdc[k]:
                if u in cou:
                    result = False ; break
                else :
                    cou += [u]
        else :
            result = False ; break
    if result == True : print('OK')
    elif result == False : print('Not OK')

6530092321
# 1679604, 2022-11-12 10:19:58, PPP (100%)

teams = {}
for i in range(int(input())):
    temp = input().split()
    teams.update({temp[0]: temp[1]})

temp = input()
while temp != 'q':
    temp = temp.split()
    temp_country = []
    flag = True
    for i in temp:
        if i not in teams:
            print('Not OK')
            flag = False
            break
        temp_country.append(teams[i])
    if flag:
        if len(temp_country) != len(set(temp_country)):
            print('Not OK')
        else:
            print('OK')
    temp = input()
# 1679606, 2022-11-12 10:20:05, PPP (100%)

teams = {}
for i in range(int(input())):
    temp = input().split()
    teams.update({temp[0]: temp[1]})

temp = input()
while temp != 'q':
    temp = temp.split()
    temp_country = []
    flag = True
    for i in temp:
        if i not in teams:
            print('Not OK')
            flag = False
            break
        temp_country.append(teams[i])
    if flag:
        if len(temp_country) != len(set(temp_country)):
            print('Not OK')
        else:
            print('OK')
    temp = input()

6530094621
# 1678888, 2022-11-12 09:40:17, xxx (0%)

def check(d,l) :
    ans = {}
    for c in l :
        #print(d[c])
        if c not in d :
            #print(c)
            return 'Not OK'
        if d[c] not in ans :
            ans[d[c]] = c
        elif d[c] in ans :
            return 'Not OK'
    return 'OK'   
            

all_team = {}
for i in range(int(input())) :
    team, country = input().split()
    all_team[team] = country
print(all_team)
q = input().split()
while q != 'q' :
    print(check(all_team,q,))
    q = input().split()
# 1678930, 2022-11-12 09:43:12, PPP (100%)

def check(d,l) :
    ans = {}
    for c in l :
        #print(d[c])
        if c not in d :
            #print(c)
            return 'Not OK'
        if d[c] not in ans :
            ans[d[c]] = c
        elif d[c] in ans :
            return 'Not OK'
    return 'OK'   
            

all_team = {}
for i in range(int(input())) :
    team, country = input().split()
    all_team[team] = country
#print(all_team)
q = input()
while q != 'q' :
    data = q.split()
    print(check(all_team,data))
    q = input()

6530101321
# 1678702, 2022-11-12 09:30:19, -P- (33%)

data = {}


for i in range(int(input())) :
    team, coun = input().split()
    data[team] = coun

grp = input().split()
while grp[0] != "q" :
    dcoun = []
    stop = False
    for t in grp :
        if t in data :
            if data[t] not in dcoun :
                dcoun.append(data[t])
        else :
            print("Not OK")
            stop = True
    if len(dcoun) >= 4 and stop == False :
        print("OK")
    elif stop == False :
        print("Not OK")
    grp = input().split()
# 1678757, 2022-11-12 09:33:01, PPP (100%)

data = {}


for i in range(int(input())) :
    team, coun = input().split()
    data[team] = coun

grp = input().split()
while grp[0] != "q" :
    dcoun = []
    stop = False
    for t in grp :
        if t in data :
            if data[t] not in dcoun :
                dcoun.append(data[t])
            else :
                print("Not OK")
                stop = True
        else :
            print("Not OK")
            stop = True
    if stop == False : print("OK")
    grp = input().split()

6530115121
# 1678639, 2022-11-12 09:27:05, --- (0%)

N=int(input())
Nation={}
for i in range(N):
    Team=input().strip().split()
    Nation[Team[0]]=Team[1]
T=input().strip().split()
while T[0]!="q" :
    a =False
    Check=set()
    for i in range(len(T)):
        if T[i] in Nation:
            Check.add(Nation[T[i]])
        else:
            print("Not OK")
            a=True
            break
    if a == False:
        if len(Check) < 4 :
            print("Not OK")
        if len(Check) == 4:
            print("OK")  
    T=input().strip().split()


# 1678654, 2022-11-12 09:28:00, PPP (100%)

N=int(input())
Nation={}
for i in range(N):
    Team=input().strip().split()
    Nation[Team[0]]=Team[1]
T=input().strip().split()
while T[0]!="q" :
    a =False
    Check=set()
    for i in range(len(T)):
        if T[i] in Nation:
            Check.add(Nation[T[i]])
        else:
            print("Not OK")
            a=True
            break
    if a == False:
        if len(Check) < len(T) :
            print("Not OK")
        if len(Check) == len(T):
            print("OK")  
    T=input().strip().split()



6530132821
# 1679846, 2022-11-12 10:30:11, PPx (67%)

n = int(input())
where = {}
for i in range(n):
    team,country = input().split()
    if country not in where:
        where[country] = []
    where[country].append(team)

teams = {}
for k in where:
    for i in range(len(where[k])):
        teams[where[k][i]]= k

allteam = set()
for k in teams:
    allteam.add(k)

allcountry = set()
for k in where:
    allcountry.add(k)

x = input()
newgroup = []
check = []
while x != "q":
    group = x.split()
    for k in group:
        check.append(k)
    checkteam = set(check)
    for k in group:
        newgroup.append(teams[k])
    groupstage = set(newgroup)
    if len(allcountry&groupstage) == len(checkteam):
        print("OK")
    else :
        print("Not OK")
    x = input()
    groupstage = set()
    checkteam = set()
    newgroup = []
    check = []





# 1679951, 2022-11-12 10:34:51, PPP (100%)

n = int(input())
where = {}
for i in range(n):
    team,country = input().split()
    if country not in where:
        where[country] = []
    where[country].append(team)

teams = {}
for k in where:
    for i in range(len(where[k])):
        teams[where[k][i]]= k

allteam = set()
for k in teams:
    allteam.add(k)

allcountry = set()
for k in where:
    allcountry.add(k)

x = input()
newgroup = []
check = []
while x != "q":
    group = x.split()
    checkinput = set(group)
    if len(checkinput&allteam) != len(checkinput):
        print("Not OK")
        x = input()
    else:
        for k in group:
            check.append(k)
        checkteam = set(check)
        for k in group:
            newgroup.append(teams[k])
        groupstage = set(newgroup)
        if len(allcountry&groupstage) == len(checkteam):
            print("OK")
        else :
            print("Not OK")
        x = input()
        groupstage = set()
        checkteam = set()
        newgroup = []
        check = []






6530135721
# 1678656, 2022-11-12 09:28:07, --x (0%)

t = {}
x = int(input())
for i in range(x):
    te, co = input().split()
    if te not in t: t[te] = co
while True:
    g = input().split()
    if g[0] == 'q': break
    isok = set()
    for i in g:
        isok.add(t[i])
    if(len(isok) == 4): print('OK')
    else: print('Not OK')
        
    
    

# 1678718, 2022-11-12 09:30:52, PPP (100%)

t = {}
x = int(input())
for i in range(x):
    te, co = input().split()
    if te not in t: t[te] = co
while True:
    g = input().split()
    if g[0] == 'q': break
    isok = set()
    for i in g:
        if i in t: isok.add(t[i])
    if(len(isok) == len(g)): print('OK')
    else: print('Not OK')
        
    
    


6530143721
# 1678700, 2022-11-12 09:30:16, PP- (67%)

n = int(input())
country = {}
prathed = []
for i in range(n):
    t,c = input().strip().split()
    if c not in country:
        country[c] = {t}
    else:
        country[c].add(t)
x = input().strip().split()
while x[0] != 'q':
    t = {}
    for i in country:
        for j in country[i]:
            if j in x:
                if i not in t:
                    t[i] = [j]
                else:
                    t[i].append(j)
    ok = True
    
    for i in t:
        if len(t[i]) != 1:
            ok = False
            
    if ok:
        print('OK')
    else:
        print('Not OK')
    
    x = input().strip().split()
    

# 1678833, 2022-11-12 09:37:07, PPP (100%)

n = int(input())
country = {}
prathed = []
for i in range(n):
    t,c = input().strip().split()
    if c not in country:
        country[c] = {t}
    else:
        country[c].add(t)
x = input().strip().split()
while x[0] != 'q':
    t = {}
    o = []
    for i in country:
        for j in country[i]:
            if j in x:
                if i not in t:
                    t[i] = [j]
                else:
                    t[i].append(j)
    ok = True
    allteams = []
    for o in country.values():
        for i in o:
            allteams.append(i)
    for i in t:
        if len(t[i]) != 1:
            ok = False
    for i in x:
            if i not in allteams:
                ok = False
                
       
    if ok:
        print('OK')
    else:
        print('Not OK')
    x = input().strip().split()
    






'''n = int(input())
country = {}
prathed = []
for i in range(n):
    t,c = input().strip().split()
    if c not in country:
        country[c] = {t}
    else:
        country[c].add(t)
x = input().strip().split()
while x[0] != 'q':
    t = {}
    for i in country:
        for j in country[i]:
            if j in x:
                if i not in t:
                    t[i] = [j]
                else:
                    t[i].append(j)
    ok = True
    
    for i in t:
        if len(t[i]) != 1:
            ok = False
            
    if ok:
        print('OK')
    else:
        print('Not OK')
    
    x = input().strip().split()'''

6530156921
# 1679410, 2022-11-12 10:09:16, --- (0%)

n=int(input())
all={}
for i in range(n):
    team,coun=input().split()
    if coun in all:
        all[team]+=coun
    else:
        all[team]=coun
# e={}
# for i in all:
#     u=all[i]
#     e[u]=i
k=[]
print(all)
teams=input().split()
while teams!='q' :
    for i in range(len(teams)):
        
        for j in range(1,len(teams)):
            if i!=j:
                
                if teams[j] not in all or teams[i] not in all:
                    d='Not OK'
                    break
                elif all[teams[i]]==all[teams[j]]:
                    d='Not OK'
                    break
                else:
                    d='OK'
        
        if d=='Not OK':
            break
    if d=='Not OK':
        k.append(d)
    else:
        k.append(d)
    
    teams=input().split()
    
    if teams ==['q']:
        break
print('\n'.join(k))
    
            
            
        



# 1679417, 2022-11-12 10:09:40, PPP (100%)

n=int(input())
all={}
for i in range(n):
    team,coun=input().split()
    if coun in all:
        all[team]+=coun
    else:
        all[team]=coun
# e={}
# for i in all:
#     u=all[i]
#     e[u]=i
k=[]

teams=input().split()
while teams!='q' :
    for i in range(len(teams)):
        
        for j in range(1,len(teams)):
            if i!=j:
                
                if teams[j] not in all or teams[i] not in all:
                    d='Not OK'
                    break
                elif all[teams[i]]==all[teams[j]]:
                    d='Not OK'
                    break
                else:
                    d='OK'
        
        if d=='Not OK':
            break
    if d=='Not OK':
        k.append(d)
    else:
        k.append(d)
    
    teams=input().split()
    
    if teams ==['q']:
        break
print('\n'.join(k))
    
            
            
        




6530162621
# 1678518, 2022-11-12 09:19:51, TTT (0%)

# 2565_1_Quiz_3_1.py

teams = {}

for i in range(int(input())):
    teamName, country = input().split()
    teams[teamName] = country
    
ln = input()
ans = []
while ln != 'q':
    for i in ln.split():
        if teams[i] in ans or i not in teams:
            ans.append('Not OK')
        else:
            ans.append('OK')
            
print(*ans,sep='\n')

# 1678600, 2022-11-12 09:24:59, PPP (100%)

# 2565_1_Quiz_3_1.py

teams = {}

for i in range(int(input())):
    teamName, country = input().split()
    teams[teamName] = country
    
ln = input()
ans = []
while ln != 'q':
    valid = True
    temp = []
    for i in ln.split():
        if i not in teams or teams[i] in temp:
            valid = False
        else:
            temp.append(teams[i])
    if valid:
        ans.append('OK')
    else:
        ans.append('Not OK')
    ln = input()
            
print(*ans,sep='\n')


6530165521
# 1678602, 2022-11-12 09:25:02, PP- (67%)

n = int(input())
team = {}
for i in range(n):
    name, coun = input().split()
    if coun not in team:
        team[coun] = [name]
    else:
        team[coun].append(name)

al = []
gr = input()
while gr != 'q':
    gr = gr.split()
    ans = []
    for e in gr:
        for f in team:
            if e in team[f]:
                ans.append(f)
    al.append(ans)
    gr = input()

for e in al:
    if len(e) != len(set(e)):
        print('Not OK')
    else:
        print('OK')
# 1678706, 2022-11-12 09:30:27, PPP (100%)

n = int(input())
team = {}
for i in range(n):
    name, coun = input().split()
    if coun not in team:
        team[coun] = [name]
    else:
        team[coun].append(name)

al = []
le = []
gr = input()
while gr != 'q':
    gr = gr.split()
    x = len(gr)
    le.append(x)
    ans = []
    for e in gr:
        for f in team:
            if e in team[f]:
                ans.append(f)
    al.append(ans)
    gr = input()

for i in range(len(le)):
    al[i] = set(al[i])
    if len(al[i]) != le[i]:
        print('Not OK')
    else:
        print('OK')

6530166121
# 1678954, 2022-11-12 09:44:12, --- (0%)

country = {}
for i in range(int(input())):
    n, c = [e.strip() for e in input().split()]
    country[n] = c
print(country) ##

choice = input()
while choice != 'q':
    choice = choice.split()
    used = []
    ok = True
    for e in choice:
        if e not in country:
            ok = False
            break
        if country[e] not in used:
            used.append(country[e])
        else :
            ok = False
            break
    if ok:
        print('OK')
    else:
        print('Not OK')
    choice = input()
        
    

# 1678957, 2022-11-12 09:44:18, PPP (100%)

country = {}
for i in range(int(input())):
    n, c = [e.strip() for e in input().split()]
    country[n] = c

choice = input()
while choice != 'q':
    choice = choice.split()
    used = []
    ok = True
    for e in choice:
        if e not in country:
            ok = False
            break
        if country[e] not in used:
            used.append(country[e])
        else :
            ok = False
            break
    if ok:
        print('OK')
    else:
        print('Not OK')
    choice = input()

6530171221
# 1678653, 2022-11-12 09:27:51, --- (0%)

nation = dict()
for i in range(int(input())):
    team,country = input().split()
    nation[team] = [country]
while True:
    x = input()
    if x == 'q': break
    i = ''
    group = x.split()
    lg = len(group)
    c = set()
    for j in group:
        if j in nation :
            c.union(set(nation[j]))
        else: print('Not OK')
        break
    if lg == len(c): print('OK')
    else:
        print('Not OK')

# 1678783, 2022-11-12 09:34:43, PPP (100%)

nation = dict()
for i in range(int(input())):
    team,country = input().split()
    nation[team] = [country]
final = []
while True:
    x = input()
    if x == 'q': break
    i = ''
    group = x.split()
    lg = len(group)
    c = set()
    for j in group:
        if j in nation :
            c.add(str(nation[j]))
        else:
            pass
            
    if lg == len(c): final.append('OK')
    else:
        final.append('Not OK')
for l in final :
    print(l)

6530174121
# 1678536, 2022-11-12 09:21:12, PPP (100%)

num = int(input())
country_dict = {}
for i in range(num):
    team,country = input().split()
    if country not in country_dict:
        country_dict[team] = country
group = input()
while group != "q":
    group = group.split()
    country_set = set()
    for e in group:
        if e not in country_dict:
            pass
        else:
            country_set.add(country_dict[e])
    if len(sorted(country_set)) == len(group):
        print("OK")
    else:
        print("Not OK")
    group = input()
# 1680627, 2022-11-12 11:03:52, PPP (100%)

num = int(input())
country_dict = {}
for i in range(num):
    team,country = input().split()
    if country not in country_dict:
        country_dict[team] = country
group = input()
while group != "q":
    group = group.split()
    country_set = set()
    for e in group:
        if e not in country_dict:
            pass
        else:
            country_set.add(country_dict[e])
    if len(sorted(country_set)) == len(group):
        print("OK")
    else:
        print("Not OK")
    group = input()

6530177021
# 1678722, 2022-11-12 09:31:07, --- (0%)

q = int(input())
nt = {}
for q1 in range(q):
    t , n = input().strip().split()
    if n not in nt:
        nt[n] = [t]
    elif n in nt:
        nt[n] += [t]
print(nt)

while True:
    gn = []
    x = input().strip()
    if x == 'q': break
    x = x.split()
    o = 'OK'
    for i in x:
        for na in nt:
            if i in nt[na] :#and na not in groupnation:
                a = na
                break
        if a not in gn:
            gn+= [a]
        elif a in gn:
            o = 'Not OK'
            break
    print(o)
    
# 1678728, 2022-11-12 09:31:25, PPP (100%)

q = int(input())
nt = {}
for q1 in range(q):
    t , n = input().strip().split()
    if n not in nt:
        nt[n] = [t]
    elif n in nt:
        nt[n] += [t]

while True:
    gn = []
    x = input().strip()
    if x == 'q': break
    x = x.split()
    o = 'OK'
    for i in x:
        for na in nt:
            if i in nt[na] :#and na not in groupnation:
                a = na
                break
        if a not in gn:
            gn+= [a]
        elif a in gn:
            o = 'Not OK'
            break
    print(o)

6530185021
# 1679057, 2022-11-12 09:49:51, --- (0%)

group_stage = {}
found = False
n = int(input())
for i in range(n):
    team, country = input().split()
    team = team.strip()
    country = country.strip()
    if team not in group_stage:
        group_stage[team] = country
while True:
    a = input().strip()
    if a == "q":
        break
    check_team = a.split()
    check_country = []
    for e in check_team:
        if e in group_stage.keys() and group_stage[e] not in check_country:
            check_country.append(group_stage[e])
        else:
            found = True
            print("Not OK")
if not found:
    print("OK")
# 1679539, 2022-11-12 10:15:49, PPP (100%)

group_stage = {}
n = int(input())
for i in range(n):
    team, country = input().split()
    team = team.strip()
    country = country.strip()
    if team not in group_stage:
        group_stage[team] = country
while True:
    a = input().strip()
    if a == "q":
        break
    check_team = a.split()
    check_country = []
    for e in check_team:
        if e in group_stage.keys() and group_stage[e] not in check_country:
            check_country.append(group_stage[e])
    if len(check_country) != len(check_team):
        print("Not OK")
    elif len(check_country) == len(check_team):
        print("OK")
    else:
        print("Not OK")

6530198221
# 1680504, 2022-11-12 10:59:06, PP- (67%)

n = input()
x = {}
for i in range(int(n)) :
    t, c = input().split()
    x[t] = c
y = input()
o = []
p = []
while y != 'q' :
    z = y.split()
    for l in range(len(z)) :
        if z[l] in x.keys() :
                o.append(x[z[l]])
        else :
            p.append('Not OK')
    if len(o) == len(set(o)) :
        p.append('OK')
    else :
        p.append('Not OK')
       
    o = []   
    y = input()
    
for e in p :
    print(e)


# 1681046, 2022-11-12 11:17:25, PPP (100%)

n = input()
x = {}
for i in range(int(n)) :
    t, c = input().split()
    x[t] = c
y = input()
o = []
p = []

while y != 'q' :
    z = y.split()
    for l in z :
        if l in x.keys() :
            o.append(x[l])
        else :
            o.append('1')
    if '1' in o :
        p.append('Not OK')
    elif  len(o) == len(set(o)) :
        p.append('OK')
    else :
        p.append('Not OK')
       
    o = []   
    y = input()
    
for e in p :
    print(e)


6530202021
# 1679309, 2022-11-12 10:03:25, PP- (67%)

allcon={}
allteam={}
teams=[]
for i in range(int(input())):
               team,contry=input().split()
               if contry not in allcon:
                   allcon[contry]=team
               if team not in allteam:
                   allteam[team]=contry
               teams.append(team)
k=0
a=True
b=True
while True:
    x=input()
    if x=='q':
        break
    x=x.split()
    for e in x:
        if e not in teams :
            print('Not OK')
            b=False
            break
    
    if b==True:
        for i in x:
            for j in x:
                if i!=j:
                    if allteam[i]==allteam[j]:
                        a=False  
               
        if  a==False:
            print('Not OK')
            a=True
        
        elif a==True:
            print('OK')
# 1679352, 2022-11-12 10:05:58, PPP (100%)

allcon={}
allteam={}
teams=[]
for i in range(int(input())):
               team,contry=input().split()
               if contry not in allcon:
                   allcon[contry]=team
               if team not in allteam:
                   allteam[team]=contry
               teams.append(team)
k=0
a=True
b=True
while True:
    x=input()
    if x=='q':
        break
    x=x.split()
    for e in x:
        if e not in teams :
            print('Not OK')
            b=False
            
    
    if b==True:
        for i in x:
            for j in x:
                if i!=j:
                    if allteam[i]==allteam[j]:
                        a=False  
               
        if  a==False:
            print('Not OK')
            a=True
        
        elif a==True:
            print('OK')
    b=True

6530204321
# 1678778, 2022-11-12 09:34:21, --- (0%)

d={}
for i in range(int(input())):
    a=input().split()
    team,co = a
    if co not in d:
        d[co] = [team]
    else:
        d[co].append(team)
while True:
    x=[]
    a=input().split()
    if a[0] == 'q':
        break
    for i in d:
        for j in a:
            if j in d[i]:
                x.append(i)
    print(x)
    for i in x:
        g=False
        if len(x) != len(a):
            print('Not OK')
            g=True
            break
    if g==True:
        continue
    for i in d:
        t=False
        if x.count(i) > 1:
            print('Not OK')
            t=True
            break
    if t != True: print('OK')
        
        

# 1678808, 2022-11-12 09:36:05, PPP (100%)

d={}
for i in range(int(input())):
    a=input().split()
    team,co = a
    if co not in d:
        d[co] = [team]
    else:
        d[co].append(team)
ans=[]
while True:
    x=[]
    a=input().split()
    if a[0] == 'q':
        break
    for i in d:
        for j in a:
            if j in d[i]:
                x.append(i)
    for i in x:
        g=False
        if len(x) != len(a):
            ans.append('Not OK')
            g=True
            break
    if g==True:
        continue
    for i in d:
        t=False
        if x.count(i) > 1:
            ans.append('Not OK')
            t=True
            break
    if t != True: ans.append('OK')
for i in ans:
    print(i)
        
        


6531302321
# 1678914, 2022-11-12 09:42:09, PP- (67%)

x = {}
n =-1
for i in range(int(input())):
    a,b = input().split()
    x[a] = b
y = []
while True:
    k = input()
    if k == "q":
        break
    y.append(k.split())

for i in y:
    z = []
    for e in i:
        if e in x:
            z.append(x[e])
        else:
            n = 0

    if len(z) == len(set(z)) and n!= 0:
        print("OK")
    else:
        print("Not OK")

    





# 1680626, 2022-11-12 11:03:52, PPP (100%)

x = {}
n =-1
for i in range(int(input())):
    a,b = input().split()
    x[a] = b
y = []
while True:
    k = input()
    if k == "q":
        break
    y.append(k.split())

for i in y:
    z = []
    n = -1
    for e in i:
        if e in x:
            z.append(x[e])
        else:
            n = 0
       

    if len(z) == len(set(z)) and n!= 0:
        print("OK")
    else:
        print("Not OK")

    






6531308121
# 1678560, 2022-11-12 09:22:51, xxx (0%)

n = int(input())
all = {}
for i in range(n) :
    team,con = input().split()
    if con not in all :
        all[con] = set(team)
    else :
        all[con].add(team)
while True :
    x = input().split()
    if x == 'q' :
        break
    group = []
    for t in x :
        check = True
        for c in all :
            if t in group :
                break
            if t in all[c] :
                group.append(t)
                check = False
    if check == True :
        print('Not OK')
    else :
        print('OK')
    group = []
# 1678825, 2022-11-12 09:36:46, PPP (100%)

n = int(input())
all = {}
for i in range(n) :
    team,con = input().split()
    if con not in all :
        all[con] = {team}
    else :
        all[con].add(team)
while True :
    x = input().split()
    if x == ['q'] :
        break
    group = []
    for team in x :
        check = False
        for contry in all :
            if team in all[contry] :
                if contry in group :
                    break
                else :
                    group.append(contry)
                    check = True
        if check == False :
            break
    if check == False :
        print('Not OK')
    else :
        print('OK')
    group = []

6531309821
# 1678786, 2022-11-12 09:34:50, PPP (100%)

n = int(input())

team_country = {}
for i in range(n):
    team, country = input().split()
    team_country[team] = country
    

group = input().split()
while group[0] != "q":
    group_country = []
    for team in group:
        if team not in team_country:
            group_country.append("Not OK")
        else:
            group_country.append(team_country[team])
    if "Not OK" in group_country:
        print("Not OK")
    else:
        if len(group_country) != len(set(group_country)):
            print("Not OK")
        else:
            print("OK")
    
    group = input().split()
# 1679947, 2022-11-12 10:34:14, PPP (100%)

n = int(input())

team_country = {}
for i in range(n):
    team, country = input().split()
    team_country[team] = country
    

group = input().split()
while group[0] != "q":
    group_country = []
    for team in group:
        if team not in team_country:
            group_country.append("Not OK")
            break
        else:
            group_country.append(team_country[team])
    if "Not OK" in group_country:
        print("Not OK")
    else:
        if len(group_country) != len(set(group_country)):
            print("Not OK")
        else:
            print("OK")
    
    group = input().split()

6531311021
# 1678717, 2022-11-12 09:30:48, --- (0%)

cou = {}
for i in range(int(input())):
    t, c = input().split()
    cou[t] = c
print(cou)
while True:
    gp = input().split()   
    if gp == ['q']:
        break
    for e in gp:
        if e not in cou:
            cou[e] = ''
    chk = []
    boo = True
    for e in gp:
        chk.append(cou[e])
    for e in chk:
        if (chk.count(e)>1) or (e == ''):
            print('Not OK')
            boo = False
            break
    if boo:
        print('OK')
# 1678752, 2022-11-12 09:32:39, PPP (100%)

cou = {}
for i in range(int(input())):
    t, c = input().split()
    cou[t] = c
# print(cou)
while True:
    gp = input().split()   
    if gp == ['q']:
        break
    for e in gp:
        if e not in cou:
            cou[e] = ''
    chk = []
    boo = True
    for e in gp:
        chk.append(cou[e])
    for e in chk:
        if (chk.count(e)>1) or (e == ''):
            print('Not OK')
            boo = False
            break
    if boo:
        print('OK')

6531318421
# 1678802, 2022-11-12 09:35:28, --- (0%)

teams = {}
country = {}
for i in range(int(input())):

    team, country = input().split()
    teams[team] = country
    # country[country] = team
# print(teams)
while True:
    s = input().split()
    found = True
    isOk = True
    check = {}
    if s[0] == 'q':
        break
    for t in s:
        if t not in teams:
            found = False
            break
        elif teams[t] not in check:
            check[teams[t]] = 0
        check[teams[t]] += 1

    for c, v in check.items():
        if v > 1:
            isOk = False
    if not found:
        print('Not Ok')

    elif isOk:
        print('OK')
    else:
        print('Not Ok')

# 1678809, 2022-11-12 09:36:06, PPP (100%)

teams = {}
country = {}
for i in range(int(input())):

    team, country = input().split()
    teams[team] = country
    # country[country] = team
# print(teams)
while True:
    s = input().split()
    found = True
    isOk = True
    check = {}
    if s[0] == 'q':
        break
    for t in s:
        if t not in teams:
            found = False
            break
        elif teams[t] not in check:
            check[teams[t]] = 0
        check[teams[t]] += 1

    for c, v in check.items():
        if v > 1:
            isOk = False
    if not found:
        print('Not OK')

    elif isOk:
        print('OK')
    else:
        print('Not OK')


6531319021
# 1679007, 2022-11-12 09:47:32, PPx (67%)

n = int(input())
book = {}
for i in range(n):
    a,b = input().split()
    book[a] = b

now = input().split()
while now[0] != 'q':
    result = True
    for i in now[1:]:
        if i not in book :
            result = False
            break
        if book[i] == book[now[0]]:
            result = False
            break

    if result == False:
        print('Not OK')
    else:
        print('OK')
    now = input().split()
    
# 1680582, 2022-11-12 11:02:29, PPP (100%)

n = int(input())
book = {}
for i in range(n):
    a,b = input().split()
    book[a] = b

now = input().split()
while now[0] != 'q':
    k = {}
    result = True
    for i in now:
        if i not in book :
            result = False
            break
        else:
            k[book[i]] = '0'

    if result == False:
        print('Not OK')
    elif len(now) == len(k):
        print('OK')
    else:
        print('Not OK')
    now = input().split()

6531321221
# 1678629, 2022-11-12 09:26:28, --P (33%)

a = {}
for i in range(int(input())):
    team , cou = input().split()
    a[team] = cou
b = input().split()
while b[0] !='q':
    result = {}
    l = 0
    for i in range(len(b)):
        if b[i] not in a:
            l = 1
            break
        if a[b[i]] not in result:
            result[a[b[i]]] = 1
        else:
            result[a[b[i]]]+=1
    if l:
        print('Not OK')
    elif len(set(result.values())) != 1:
        print('Not OK')
    else:
        print('OK')
    b = input().split()
# print(a)
    
# 1679544, 2022-11-12 10:16:06, PPP (100%)

a = {}
for i in range(int(input())):
    team , cou = input().split()
    a[team] = cou
b = input().split()
while b[0] !='q':
    result = {}
    l = 0
    cnt = 0
    for i in range(len(b)):
        if b[i] not in a:
            l = 1
            break
        if a[b[i]] not in result:
            result[a[b[i]]] = 1
        else:
            result[a[b[i]]]+=1
    if l:
        print('Not OK')
        b = input().split()
        continue
    for r in result.values():
        if r != 1:
            print('Not OK')
            b = input().split()
            break
        else:
            cnt+=1
    if cnt == len(result.values()):
        print('OK')
        b = input().split()
# print(a)
    

6531323521
# 1678694, 2022-11-12 09:29:55, PP- (67%)

n = int(input())
nation = {}
team = []
for i in range(n) :
    n = input().split()
    team.append(n[0])
    if n[1] not in nation :
        nation[n[1]] = [n[0]]
    else :
        nation[n[1]].append(n[0])
group = []
n = input()
while n!= "q" :
    n = n.split()
    group.append(n)
    n = input()
for i in group :
    country = []
    for j in i:
        if j not in team :
            print("Not OK")
            break
        else :
            for k in nation :
                if j in nation[k] :
                    country.append(k)
    if j not in team :
        break
    for i in range(len(country)) :
        if country.count(country[i]) >1 :
            print("Not OK")
            break
        
        elif i == len(country) -1 :
            print("OK")




# 1681374, 2022-11-12 11:25:29, PPP (100%)

n = int(input())
nation = {}
team = []
for i in range(n) :
    n = input().split()
    team.append(n[0])
    if n[1] not in nation :
        nation[n[1]] = [n[0]]
    else :
        nation[n[1]].append(n[0])
group = []
n = input()
while n!= "q" :
    n = n.split()
    group.append(n)
    n = input()
for i in group :
    country = []
    x = 0
    for j in i:
        if j not in team :
            print("Not OK")
            x =1
            break
        else :
            for k in nation :
                if j in nation[k] :
                    country.append(k)
    if x == 0 : 
        for i in range(len(country)) :
            if country.count(country[i]) >1 :
                print("Not OK")
                break
            
            elif i == len(country) -1 :
                print("OK")

6531326421
# 1678577, 2022-11-12 09:23:33, --- (0%)

c_team = {}
count = {}
a = {}
for _ in range(int(input())) :
    team,country = input().split()
    if country not in c_team :
        c_team[team] = country
        count[country] = 0
    else :
        c_team[country].append(team)
a = count.copy()
x = input().split()
while x[0] != 'q' :
    check = True
    for e in x :
        for num in count.values() :
            if num > 1 :
                print('Not OK')
                count = a
                check = False
                break
        if not check :
            break
        if check :
            if e in c_team :
                count[c_team[e]] += 1
            else :
                print('Not OK')
                count = a
                check = False
                break
    if check :
        print('OK')
    x = input().split()


# 1678773, 2022-11-12 09:34:04, PPP (100%)

c_team = {}
count = {}
for _ in range(int(input())) :
    team,country = input().split()
    if country not in c_team :
        c_team[team] = country
        count[country] = 0
    else :
        c_team[country].append(team)
x = input().split()
while x[0] != 'q' :
    for e in count :
        count[e] = 0
    check = True
    check1 = True
    for e in x :
        if e in c_team :
            count[c_team[e]] += 1
        else :
            print('Not OK')
            check1 = False
            check2 = False
            break
    if check1 :
        for num in count.values() :
            if num > 1 :
                print('Not OK')
                check2 = False
                break
            check2 = True
    if check2 :
        print('OK')
    x = input().split()



6531329321
# 1678524, 2022-11-12 09:20:13, --- (0%)

country ={}
for i in range(int(input())):
    t,c = input().split()
    country[t] = c
t = input()
while t != 'q':
    countries = set()
    for e in t.split():
        if e not in country:
            break
        else:
            countries.add(country[e])
    if len(countries) != len(t):
        print('Not OK')
    else: print('OK')
    t = input()
# 1678599, 2022-11-12 09:24:54, PPP (100%)

country ={}
for i in range(int(input())):
    t,c = input().split()
    country[t] = c
t = input()
while t != 'q':
    countries = set()
    for e in t.split():
        if e not in country:
            break
        else:
            countries.add(country[e])
    if len(countries) != len(t.split()):
        print('Not OK')
    else: print('OK')
    t = input()

6531330921
# 1678507, 2022-11-12 09:18:36, xxx (0%)

n = int(input())
team = {}
for i in range(n):
    name,nation = input().split()
    team[name] = nation

grouping = input()
groups = []
while grouping != "q":
    group = set()
    grouping = grouping.split()
    group.add(len(grouping))
    for e in grouping:
        if e in team:
            group.add(team[e])
    groups.append(group)
    grouping = input()

for e in group:
    if len(e) == e[0]+1:
        print("OK")
    else:
        print("Not OK")
# 1678584, 2022-11-12 09:24:02, PPP (100%)

n = int(input())
team = {}
for i in range(n):
    name,nation = input().split()
    team[name] = nation

grouping = input()
groups = []
groups_len = []

while grouping != "q":
    group = set()
    grouping = grouping.split()
    groups_len.append(len(grouping))
    for e in grouping:
        if e in team:
            group.add(team[e])
    groups.append(group)
    grouping = input()

for i in range(len(groups)):
    if len(groups[i]) == groups_len[i]:
        print("OK")
    else:
        print("Not OK")

6531332121
# 1678633, 2022-11-12 09:26:51, --- (0%)

teams = {}
n = int(input())
for i in range(n):
    team, country = input().split()
    teams[team] = country
print(teams)
while 1:
    status = 'OK'
    s_input = input()
    if s_input == 'q':
        quit()
    group = s_input.split()
    countries_in_group = []
    for team in group:
        if team not in teams:
            print('Not OK')
            status = 'Not OK'
            break
        else:
            # if teams[team] not in countries_in_group:
            #     countries_in_group.append(teams[team])
            # else:
            #     print('Not OK')
            #     status = 'Not OK'
            #     break
            if teams[team] in countries_in_group:
                print('Not OK')
                status = 'Not OK'
                break
            else:
                countries_in_group.append(teams[team])

    if status == 'OK':
        print('OK')

# 1678647, 2022-11-12 09:27:31, PPP (100%)

teams = {}
n = int(input())
for i in range(n):
    team, country = input().split()
    teams[team] = country
# print(teams)
while 1:
    status = 'OK'
    s_input = input()
    if s_input == 'q':
        quit()
    group = s_input.split()
    countries_in_group = []
    for team in group:
        if team not in teams:
            print('Not OK')
            status = 'Not OK'
            break
        else:
            # if teams[team] not in countries_in_group:
            #     countries_in_group.append(teams[team])
            # else:
            #     print('Not OK')
            #     status = 'Not OK'
            #     break
            if teams[team] in countries_in_group:
                print('Not OK')
                status = 'Not OK'
                break
            else:
                countries_in_group.append(teams[team])

    if status == 'OK':
        print('OK')


6531333821
# 1678514, 2022-11-12 09:19:22, PPP (100%)

times = int(input())
teamDict = {}
for i in range(times):
    team, country = input().split()
    teamDict[team] = country

data = input()
while (data != 'q'):
    teams = data.split()
    countrySet = set()
    for t in teams:
        if(t not in teamDict):
            break
        countrySet.add(teamDict[t])
    if(len(countrySet) < len(teams)):
        print("Not OK")
    else:
        print("OK")
    data = input()
# 1679620, 2022-11-12 10:20:37, PPP (100%)

teamDict = {}
for i in range(int(input())):
    team, country = input().split()
    teamDict[team] = country

data = input()
while (data != 'q'):
    teams = data.split()
    countrySet = set()
    for t in teams:
        if(t not in teamDict):
            break
        countrySet.add(teamDict[t])
    if(len(countrySet) < len(teams)):
        print("Not OK")
    else:
        print("OK")
    data = input()

6531334421
# 1679096, 2022-11-12 09:52:21, --- (0%)

con = {} #[team:contry]
for i in range(int(input())):
    t = input().split()
    con[t[0]] = t[1]
print(con)
running = 1
while running:
    team = input()
    count = {}
    if team == 'q': 
        running = 0
        break
    else:
        team = team.split()
        OK = 1
        for i in team:
            if i not in con.keys():
                OK = 0
                break
            else:
                if con[i] not in count:
                    count[con[i]] = 1
                else:
                    count[con[i]] += 1
        for i in count.values():
            if i > 1 :
                OK = 0
                break
        if OK:
            print('OK')
        else:
            print('Not OK')
# 1679114, 2022-11-12 09:53:14, PPP (100%)

con = {} #[team:contry]
for i in range(int(input())):
    t = input().split()
    con[t[0]] = t[1]
running = 1
while running:
    team = input()
    count = {}
    if team == 'q': 
        running = 0
        break
    else:
        team = team.split()
        OK = 1
        for i in team:
            if i not in con.keys():
                OK = 0
                break
            else:
                if con[i] not in count:
                    count[con[i]] = 1
                else:
                    count[con[i]] += 1
        for i in count.values():
            if i > 1 :
                OK = 0
                break
        if OK:
            print('OK')
        else:
            print('Not OK')

6531340121
# 1678510, 2022-11-12 09:18:54, --- (0%)

n = int(input())
d = {}
for i in range(n):
    team, coun = input().split()
    d[team] = coun
a = input()
while a != 'q':
    teams = [e for e in a.split()]
    l = []
    for i in range(len(teams)):
        if teams[i] not in d:
            print("NOT OK")
            break
        elif d[teams[i]] not in l:
            l.append(d[teams[i]])
        else:
            print("NOT OK")
            break
    if len(l) == len(teams):
        print("OK")
    a = input()
# 1678537, 2022-11-12 09:21:13, PPP (100%)

n = int(input())
d = {}
for i in range(n):
    team, coun = input().split()
    d[team] = coun
a = input()
while a != 'q':
    teams = [e for e in a.split()]
    l = []
    for i in range(len(teams)):
        if teams[i] not in d:
            print("Not OK")
            break
        elif d[teams[i]] not in l:
            l.append(d[teams[i]])
        else:
            print("Not OK")
            break
    if len(l) == len(teams):
        print("OK")
    a = input()

6532040021
# 1678648, 2022-11-12 09:27:34, --- (0%)

n = int(input())
ctry = {}
for i in range(n):
    name, coun = input().split()
    ctry[name] = coun

while True:
    t = []
    s = input()
    if s == 'q': break
    lst = s.split()
    sk = False
    for i in lst:
        print(t)
        if i not in ctry or ctry[i] in t:
            sk = True
            print('Not OK')
            break
        t.append(ctry[i])
    if sk: continue
    print('OK')
# 1678655, 2022-11-12 09:28:01, PPP (100%)

n = int(input())
ctry = {}
for i in range(n):
    name, coun = input().split()
    ctry[name] = coun

while True:
    t = []
    s = input()
    if s == 'q': break
    lst = s.split()
    sk = False
    for i in lst:
        
        if i not in ctry or ctry[i] in t:
            sk = True
            print('Not OK')
            break
        t.append(ctry[i])
    if sk: continue
    print('OK')

6532084721
# 1678736, 2022-11-12 09:31:44, --- (0%)

n = int(input())

d = {}
for i in range(n):
    tmp = input().split()
    d[tmp[0]] = tmp[1]

print(d)
while(True):
    tmp = input().split()
    if tmp[0] == 'q': break
    ans = []
    ch = 0
    for i in tmp:
        if i not in d or d[i] in ans:
            ch = 1
        else:
            ans.append(d[i])
    if ch==1:
        print('Not OK')
    else:
        print('OK')
# 1678745, 2022-11-12 09:32:16, PPP (100%)

n = int(input())

d = {}
for i in range(n):
    tmp = input().split()
    d[tmp[0]] = tmp[1]

while(True):
    tmp = input().split()
    if tmp[0] == 'q': break
    ans = []
    ch = 0
    for i in tmp:
        if i not in d or d[i] in ans:
            ch = 1
        else:
            ans.append(d[i])
    if ch==1:
        print('Not OK')
    else:
        print('OK')

6532092721
# 1678641, 2022-11-12 09:27:11, --- (0%)

n = int(input())
dic = {}
for i in range(n) :
    inp = input().split()
    dic[inp[0]] = inp[1]

inp = input().split()
while inp[0] != "q" :
    flag = True
    cur1 = []
    for p in inp:
        if p not in dic or dic[p] in cur1 :
            flag = False
            break
        cur1.append(dic[p])
                
    if (flag) :
        print("OK")
    else :
        print("Not OK")


    inp = input().split()
print(dic)
# 1678645, 2022-11-12 09:27:28, PPP (100%)

n = int(input())
dic = {}
for i in range(n) :
    inp = input().split()
    dic[inp[0]] = inp[1]

inp = input().split()
while inp[0] != "q" :
    flag = True
    cur1 = []
    for p in inp:
        if p not in dic or dic[p] in cur1 :
            flag = False
            break
        cur1.append(dic[p])
                
    if (flag) :
        print("OK")
    else :
        print("Not OK")


    inp = input().split()

6532106921
# 1678572, 2022-11-12 09:23:23, PP- (67%)

n=int(input())
deck=dict()
for i in range(n):
    name,nation=input().split()
    if(name not in deck): deck[name]=nation

x=[x for x in input().split()]
while(x[0]!='q'):
    ch=dict(); mark=0
    #print('Here',x)
    for j in range(len(x)):
        #print(x[j],deck[x[j]])
        if(x[j] not in deck): print('NOT OK'); mark=1; break
        if(deck[ x[j] ] not in ch): ch[ deck[x[j]] ]=1
        else: print("Not OK"); mark=1
    if(not mark): print('OK')
    x=[x for x in input().split()]
    

# 1678595, 2022-11-12 09:24:45, PPP (100%)

n=int(input())
deck=dict()
for i in range(n):
    name,nation=input().split()
    if(name not in deck): deck[name]=nation

x=[x for x in input().split()]
while(x[0]!='q'):
    ch=dict(); mark=0
    #print('Here',x)
    for j in range(len(x)):
        #print(x[j],deck[x[j]])
        if(x[j] not in deck): print('Not OK'); mark=1; break
        if(deck[ x[j] ] not in ch): ch[ deck[x[j]] ]=1
        else: print("Not OK"); mark=1
    if(not mark): print('OK')
    x=[x for x in input().split()]
    


6532141821
# 1678587, 2022-11-12 09:24:29, PP- (67%)

n = int(input())
teamdata = {}
for i in range(n) :
    teamname, nation = input().strip().split()
    teamdata[teamname] = nation
while True :
    x = input().strip()
    if x == "q" :
        break
    checklist = x.split()
    newteamdata = {}
    for team in checklist :
        if team not in teamdata :
            print("Not OK")
            break
        newteamdata[teamdata[team]] = team
    if len(checklist) == len(newteamdata) :
        print("OK")
    else :
        print("Not OK")
# 1678619, 2022-11-12 09:26:02, PPP (100%)

n = int(input())
teamdata = {}
for i in range(n) :
    teamname, nation = input().strip().split()
    teamdata[teamname] = nation
while True :
    x = input().strip()
    anew = False
    if x == "q" :
        break
    checklist = x.split()
    newteamdata = {}
    for team in checklist :
        if team not in teamdata :
            print("Not OK")
            anew = True
            break
        newteamdata[teamdata[team]] = team
    if anew :
        continue
    if len(checklist) == len(newteamdata) :
        print("OK")
    else :
        print("Not OK")

6532143021
# 1678497, 2022-11-12 09:17:39, --- (0%)

n = int(input())

team = {}
for i in range(n):
    x = input().split()
    team[x[0]] = x[1]
    
print(team)
x = input().split()
while x[0] != 'q':
    s = set()
    chk = 0
    for i in x:
        if i in team:
            s.add(team[i])
        else:
            chk = 1
            break
            
    if chk == 1 or len(s) != len(x):
        print('Not OK')
    else:
        print('OK')
    
    
    x = input().split()
# 1678505, 2022-11-12 09:18:16, PPP (100%)

n = int(input())

team = {}
for i in range(n):
    x = input().split()
    team[x[0]] = x[1]
    
# print(team)
x = input().split()
while x[0] != 'q':
    s = set()
    chk = 0
    for i in x:
        if i in team:
            s.add(team[i])
        else:
            chk = 1
            break
            
    if chk == 1 or len(s) != len(x):
        print('Not OK')
    else:
        print('OK')
    
    
    x = input().split()

6532182521
# 1678493, 2022-11-12 09:17:23, PPP (100%)

nt = int(input())

teamN = {}
for i in range(nt):
    inp = input().split()
    teamN[inp[0]] = inp[1]

inp = input()
while inp != 'q':
    inp = inp.split()
    nation = set()
    ok = True

    for team in inp:
        if team not in teamN or teamN[team] in nation:
            ok = False
            break
        nation.add(teamN[team])

    if ok:
        print('OK')
    else:
        print('Not OK')

    inp = input()

# 1679594, 2022-11-12 10:19:16, PPP (100%)

nt = int(input())

teamN = {}
for i in range(nt):
    inp = input().split()
    teamN[inp[0]] = inp[1]

inp = input()
while inp != 'q':
    inp = inp.split()
    nation = set()
    for team in inp:
        if team in teamN:
            nation.add(teamN[team])

    if len(nation) == len(inp):
        print('OK')
    else:
        print('Not OK')

    inp = input()


6531701021
# 1678903, 2022-11-12 09:41:32, PP- (67%)

a=int(input())
b={}
team=[]
for i in range(a):
    c=input().split()
    b[c[0]]=c[1]
ch='a'
while ch != 'q':
    d=input().split()
    team+=[d]
    ch=d[0]
team.pop(-1)
for j in range(len(team)):
    check=[]
    br=0
    for k in range(len(team[j])):
        if team[j][k] in b:
            check+=[b[team[j][k]]]
        else:
            print('Not OK')
            br=1
            break
    if br == 1:
            break
    else:
        for l in range(len(check)):
            if check.count(check[l]) > 1:
                print('Not OK')
                br=1
                break
        if br == 0:
            print('OK')
# 1679080, 2022-11-12 09:51:25, PPP (100%)

a=int(input())
b={}
team=[]
for i in range(a):
    c=input().split()
    b[c[0]]=c[1]
ch='a'
while ch != 'q':
    d=input().split()
    team+=[d]
    ch=d[0]
team.pop(-1)
for j in range(len(team)):
    check=[]
    br=0
    for k in range(len(team[j])):
        if team[j][k] in b:
            check+=[b[team[j][k]]]
        else:
            print('Not OK')
            br=1
            break
    else:
        if br == 1:
            break
        else:
            for l in range(len(check)):
                if check.count(check[l]) > 1:
                    print('Not OK')
                    br=1
                    break
            if br == 0:
                print('OK')

6531802821
# 1680788, 2022-11-12 11:09:13, --- (0%)

n = int(input())
d = {}
for i in range(n) :
    t = input().split()
    if t[1] not in d :
        d[t[1]] = t[0]
    else :
        d[t[1]] += ", "
        d[t[1]] += t[0]
for i in d :
    d[i] = d[i].split(", ")

dp = []
for e in d :
    dp += d[e]

re = []
g = input().split()
while g[0] != "q" :
    l = []
    for i in range(len(g)-1) :
        for k in range(i+1,len(g)) :
            l.append([g[i], g[k]])
    for e in d :
        for p in l :
            if p[0] not in dp :
                re.append("Not OK")
            elif p[1] not in dp :
                re.append("Not OK")
            else :
                if (p[0] in d[e]) and (p[1] in d[e]) :
                    re.append("Not OK")
                else :
                    re.append("Not OK")
    if "Not OK" in re :
        print("Not OK")
    else :
        print("OK")
    g = input().split()
    re = []
# 1680844, 2022-11-12 11:11:15, PPP (100%)

n = int(input())
d = {}
for i in range(n) :
    t = input().split()
    if t[1] not in d :
        d[t[1]] = t[0]
    else :
        d[t[1]] += ", "
        d[t[1]] += t[0]
for i in d :
    d[i] = d[i].split(", ")

dp = []
for e in d :
    dp += d[e]

re = []
g = input().split()
while g[0] != "q" :
    l = []
    for i in range(len(g)-1) :
        for k in range(i+1,len(g)) :
            l.append([g[i], g[k]])
    for e in d :
        for p in l :
            if p[0] not in dp :
                re.append("Not OK")
            elif p[1] not in dp :
                re.append("Not OK")
            else :
                if (p[0] in d[e]) and (p[1] in d[e]) :
                    re.append("Not OK")
                else :
                    re.append("OK")
    if "Not OK" in re :
        print("Not OK")
    else :
        print("OK")
    g = input().split()
    re = []

6531808621
# 1678714, 2022-11-12 09:30:41, xxx (0%)

team = dict()
n = int(input())
for i in range(n):
    teamname = input().split()
    team[teamname[0]] = teamname[1]
print(team)
cha = input().split()
while cha != 'q':
    match = []
    for i in range(len(cha)):
        if cha[i] not in team.keys():
            print('Not OK')
        else:
            match.append(team[cha[i]])
            setmatch = set(match)
    if len(setmatch) < len(match) :
        print('Not OK')
    else:
        print('OK')
    
    
    
    
    cha = input().split()
# 1679041, 2022-11-12 09:49:02, PPP (100%)

team = dict()
n = int(input())
for i in range(n):
    teamname = input().split()
    team[teamname[0]] = teamname[1]
cha = input().split()
while cha != ['q']:
    #print(cha)
    match = []
    num = 0
    for i in range(len(cha)):
        #print( cha[i] )
        if cha[i] not in team.keys():
            num += 1
            print('Not OK')
            
        else:
            match.append(team[cha[i]])
            setmatch = set(match)    
    if len(setmatch) < len(match) and num == 0:
            print('Not OK')
    else:
        if num == 0:
            print('OK')
    num = 0
    cha = input().split()
pass


6330175621
# 1679552, 2022-11-12 10:16:27, --- (0%)

n1 = int(input())
d= {}
l = []
out = []
check1 = True
check2 = False
for i in range(n1):
    t,nation = input().split()
    d[t] = nation
n2 = input()
while n2 != 'q':
    gro = n2.split()
    for e in gro:
        if e not in d:
            gro.remove(e)
            check1 = False
            break
    for i in range(len(gro)):
        for j in range(i+1,len(gro)):
            if d[gro[i]] == d[gro[j]]:
                check2 = False
                break
            else:
                check2 = True
    if check1 == True and check2 == True:
        out.append('OK')
    elif check2 == True:
        out.append('Not OK')

        
    n2 = input()
    
for e in out:
    print(e)
# 1680206, 2022-11-12 10:46:47, PPP (100%)

n1 = int(input())
d= {}
l = []
out = []
res = []
check = False
for i in range(n1):
    t,nation = input().split()
    d[t] = nation
n2 = input()
while n2 != 'q':
    gro = n2.split()
    for e in gro:
        if e not in d:
            gro.remove(e)
            check = True
            break
    if check != True:
        for i in range(len(gro)):
            for j in range(i+1,len(gro)):
                if d[gro[i]] == d[gro[j]]:
                    res.append([gro[i],gro[j]])
    if len(res) == 0 and check == False:
        out.append('OK')
    else:
        out.append('Not OK')
        
    res = []
    check = False
    n2 = input()
    
for e in out:
    print(e)

6230063921
# 1678615, 2022-11-12 09:25:50, PPP (100%)

d = {}

for i in range(int(input())):
    t, n = input().split()
    if n not in d.keys():
        d[t] = n

while True:
    n = input()
    if n == 'q':
        break
    n = n.split()
    ans = []
    y = True
    for i in n:
        if i not in d.keys():
            print('Not OK')
            y = False
            break
        ans.append(d[i])
    x = set(ans)
    if y == True:
        if len(x) == len(ans):
            print('OK')
        else:
            print('Not OK')

6230071921
# 1678582, 2022-11-12 09:23:46, PPP (100%)

n=int(input())
ball={}
for i in range(n):
    a,b=input().strip().split()
    if a not in ball:
        ball[a]=[b]
    else:
        ball[a].append(b)
c=input().strip().split()
ans=[]
while c[0] != 'q':
    for j in c:
        if j in ball:
            ans.append(ball[j])
        else:
            pass
    ans.sort()
    if len(ans) != len(c):
        print('Not OK')
    else:
        count=0
        for k in range(len(ans)-1):
            if ans[k]==ans[k+1]:
                count+=1
        if count !=0:
            print('Not OK')
        else:
            print('OK')
    ans=[]
    c=input().strip().split()


6230083421
# 1678670, 2022-11-12 09:28:42, PPP (100%)

typ = {}
for i in range(int(input())):
    n,t = input().split()
    typ[n] = t
x = input().split()
check = []
while x[0] != 'q':
    check.append(x)
    x = input().split()   
for c in check:
    o = set() 
    for ch in c:
        if ch in typ:
            o.add(typ.get(ch,'None'))
    if len(o) == len(c):
        print('OK')
    else:
        print('Not OK')
    


6230098921
# 1678601, 2022-11-12 09:24:59, PPP (100%)

n = int(input())
team = {}
for i in range(n) :
    club,national = input().strip().split()
    team[club] = national
b = input().strip()
result = []
while b != 'q' :
    group = b.split()
    for e in group :
        if e not in team :
            print('Not OK')
        elif team[e] not in result :
            result.append(team[e])
        elif team[e] in result :
            print('Not OK')
            break
        if len(result) == len(group) :
            print('OK')
            break
    result = []
    b = input().strip()

6231110921
# 1678881, 2022-11-12 09:39:37, PPP (100%)

x = {}
for i in range(int(input())):
    team,country = input().strip().split(' ')
    x[team] = country
group = input().strip().split(' ')
ans= []
while group != ['q']:
    out = []
    for g in range(len(group)):
        for h in range(1,len(group)):
            if group[g] not in x or group[h] not in x:
                out+=['Not OK']
            elif group[g] in x and group[h] in x:
                if group[g] != group[h]:
                    if x[group[g]] == x[group[h]]:
                        out+=['Not OK']
                    else:
                        out+=['OK']
    if 'Not OK' in out:
        ans+=['Not OK']
    else:
        ans+=['OK']
    group = input().strip().split(' ')
for q in ans:
    print(q)



6231121821
# 1679017, 2022-11-12 09:47:56, PPP (100%)

n = int(input())
team = {}
country = {}
for i in range(n):
    x = input().split()
    t,c = x[0],x[1]
    team[t] = c
    if c not in country: country[c] = []
    country[c].append(t)
group = []
y = input()
while y != 'q':
    group.append(y.split())
    y = input()
t = list(team)
for i in range(len(group)):
    found = False
    for j in range(len(group[i])):
        if group[i][j] not in t :
            found = True
            break
        for k in range(j+1,len(group[i])):
            if group[i][k] not in t :
                found = True
                break
            if team[group[i][j]] == team[group[i][k]]:
                found = True
                break
        if found:
            break
    if found:
        print('Not OK')
    else:
        print('OK')

6231122421
# 1678561, 2022-11-12 09:22:54, PPP (100%)

n = int(input())
team = {}
for i in range(n):
    s = input().split()
    team[s[0]] = s[1]

c = input().split()
while c != ['q']:
    checker = set()
    for e in c:
        if e in team:
            checker.add(team[e])
    if len(checker) == len(c):
        print('OK')
    else:print('Not OK')
    c = input().split()

6231129921
# 1678842, 2022-11-12 09:37:31, PPP (100%)

n = int(input())
c = 1
country = {} # {country: {team1,team2}   }
t = set()
while c <= n:
    team,coun = input().split()
    t.add(team)
    if coun not in country:
        country[coun] = {team}
    else:
        country[coun].add(team)
    c += 1
    
    
#print(country)
    
y = input().split()
while y[0] != 'q':
    group = set(y)
    b = group & t
    if len(b) == len(group): 
        for v in country.values():
            a = v & group
            if len(a) > 1:
                ans = 'Not OK'
                break
            else:
                ans = 'OK'
    else:
        ans = 'Not OK'
    print(ans)
    y = input().split()






6231422721
# 1678934, 2022-11-12 09:43:22, PPP (100%)

nation = dict()
for i in range (int(input())) :
    a = input().strip().split()
    if a[1] not in nation :
        nation[a[1]] = {a[0]}
    else :
        nation[a[1]].add(a[0])

while True :
    a = input().strip().split()
    check = True
    result = []
    if a == ["q"] :
        break
    for i in a :
        count = 0
        for e in nation :
            if i in nation[e] :
                result.append(e)
    if len(result) != len(a) :
        check = False

    f = [result[0]]

    for j in result[1:] :
        if j in f :
            check = False
        f.append(j)
    if check == False :
        print("Not OK")
    else :
        print("OK")
        

    

6231425621
# 1678598, 2022-11-12 09:24:49, PPP (100%)

n = int(input())
team ={}
country = {}
for i in range(n):
    t, c = input().split()
    team[t] = c
x = input()
while x!= 'q':
    x = x.split()
    m = len(x)
    check1 = set()
    check2 = []
    for t in x:
        if t in team:
            check1.add(team[t])
            check2.append(team[t])
        else:
            check1.add(' ')
            check2.append(' ')
            
    if len(check2) == len(check1) and ' ' not in check1 and ' ' not in check2:
        print('OK')
    else:
        print('Not OK')
        
    
    x = input()

6230187021
# 1679253, 2022-11-12 10:01:05, PPP (100%)

x=int(input())
sec={}
for i in range(x):
    y=input().split()
    if y[1] not in sec:
        sec[y[1]]=[y[0]]
    else:
        sec[y[1]]+=[y[0]]
t=input()
result=[]
while t!='q':
    t=t.strip().split()
    check=[]
    for k in t:
        for j in sec:
            if k in sec[j]:
                check+=[j]
    a={}
    for j in check:
        if j not in a:
            a[j]=1
        else:
            a[j]+=1
    almost=[]
    for k in a:
        if a[k]>1:
            almost+=[2
]
    if len(a)!=len(t):
        almost+=[2]
    result+=[almost]
    t=input()
for k in result:
    if k==[]:
        print('OK')
    else:
        print('Not OK')

6230259621
# 1678827, 2022-11-12 09:36:49, PPP (100%)

g={}
for i in range(int(input())):
    team,con=input().split()
    if con in g:
        g[team]+=con
    else:
        g[team]=con
group=input().split()
sol=[]
while group[0]!='q':
    con2=set()
    for e in group:
        if e in g.keys():
            con2.add(g[e])
    if len(con2)<len(group):
        sol+=['Not OK']
    else:
        sol+=['OK']
    group=input().split()
for t in sol:
    print(t)

6230322421
# 1679365, 2022-11-12 10:06:29, PPP (100%)

main = dict()
mains = []
for i in range(0,int(input())):
    team , nation = input().split()
    if team not in main:
        main[team] = nation
        mains.append(team)


while True :
    
    status = 0
    g = []
    g_set = set()
    q = input()
    if q == 'q': break
    d = q.split()
    
    for e in d:
        if e in mains:
            g.append(main[e])
        else:
            status = -1    
    g_set = set(g)
    
    if status == -1:
        print('Not OK')
    else:

        if len(g) != len(g_set):
            print('Not OK')
        else:
            print('OK')

6331119721
# 1678908, 2022-11-12 09:41:52, PPP (100%)

a = int(input())
b = {}
for i in range(a):
    c,d = input().split()
    if c not in b:
        b[c] = d
    else:
        pass

e = input().split()
f = []
while e[0] != 'q':
    for i in range(len(e)):
        if e[i] in b and b[e[i]] not in f:
            f.append(b[e[i]])
        else:
            pass
        
    if len(f) == len(e):
        print('OK')
    else:
        print('Not OK')
    e = input().split()
    f = []

6431416121
# 1679356, 2022-11-12 10:06:17, PPP (100%)

p = {}
    
for e in range(int(input())) :
    r = input().split()
    p[r[0]] = r[1]
k = []
for j in p :
    k.append(j)

while True :
    x = True
    l = []
    u = input().split()
    if u == ['q'] :
        break
    for y in u :
        if y not in k :
            print('Not OK')
            x = False
            break
        if p[y] in l :
            print('Not OK')
        else :
            l.append(p[y])
            x = False
    
    if len(l) == len(u) :
        print('OK')
        
        


6431120321
# 1678865, 2022-11-12 09:38:48, PPP (100%)

#good_LUCK
def check(u):
    U = u.split()
    s = set()
    for i in U:
        if i in x:
            s.add(x[i])
    if len(s) != len(U):
        p= 'Not OK'
    else:
        p = 'OK'
    return p

n = int(input())
c = 0
x = {}

while c != n :
   Y , y = input().split()
   x[Y] = y
   c += 1
o = input()

while o != 'q' :
    print(check(o))
    o = input()

    
    
   



6431133521
# 1680255, 2022-11-12 10:49:33, PPP (100%)

n = input()
nt = {}
for i in range(int(n)):
    t = input().split()
    nt[t[0]] = t[1]
g = []
G = input()
while G != "q":
    g += [G.split()]
    G = input()

for i in g:
    c = []
    for j in i:
        if j in nt:
            c += [nt[j]]
        else:
            break
    c = set(c)
    
    if len(c) == len(i):
        print("OK")
    else:
        print("Not OK")
        

6431510421
# 1679126, 2022-11-12 09:53:45, PPP (100%)

d = {}
for i in range(int(input())):
    x = input().split()
    d[x[0]] = x[1]
#{'Liverpool': 'England', 'ManCity': 'England'}
x = input()
ans = []
while True:
    if x == 'q':
        break
    x = x.split()
    d2 = []
    d3 = []
    d4 = 0
    for i in range(len(x)):
        if x[i] in d:
            d2.append(d[x[i]])
            d3.append(x[i])
        elif x[i] not in d:
            d2.append(x[i])
            d3.append(x[i])
    d2.sort()
    for i in range(len(d2)-1):
        if d2[i] in d3:
            ans.append('Not OK')
            break
        elif d2[i] == d2[i+1]:
            ans.append('Not OK')
            break
        d4 += 1
    if d4 == len(d2)-1:
        ans.append('OK')
    x = input()

for e in ans:
    print(e)

6430206521
# 1680282, 2022-11-12 10:50:32, PPP (100%)

n=int(input())
d1={}
d2={}
for i in range(n):
    team,ct = input().split()
    if ct not in d1: d1[ct] = []
    d1[ct].append(team)
    d2[team] = ct
while True:
    d3={}
    x = input().split()
    if x[0] == 'q':
        break
    for t in x:
        if t not in d2:
            d3[t] = 999
            break
        if d2[t] in d3:
            d3[d2[t]] +=999
        else:
            d3[d2[t]] = 1
    k = 0
    for sc in d3.values():
        if sc > 1:
            k+=999
    if k == 0:
        print('OK')
    else:
        print('Not OK')

6430224821
# 1678898, 2022-11-12 09:41:09, PPP (100%)

n = int(input())
country = {}
for i in range(n):
    x = input().split()
    x1 = x[0]
    x2 = x[1]
    if x2 in country:
        country[x2].add(x1)
    if x2 not in country:
        country[x2] = {x1}
output = []
while True:
    d = set()
    b = True
    y = input().split()
    if y[0] == 'q':
        break
    for e in y:
        for r in country:
            if e in country[r]:
                d.add(r)
    if len(d) != len(y):
        b = False
    if b == False :
        output.append('Not OK')
    else :
        output.append('OK')
        
for q in output:
    print(q)
    


6430328421
# 1679225, 2022-11-12 09:59:19, PPP (100%)

x = {}    # {team: nation}
for i in range(int(input())):
    t, n = input().split()
    x[t]=n
  
b=[]   
while True:
    a = input().split()
    if a[0] == 'q': break
    b.append(a)

for e in b:
    c=[]
    for i in range (len(e)):
        if e[i] in x:
            c.append(x[e[i]])
        else:
            c.append('')
    if '' in c:
        print('Not OK')
    elif len(c) == len(set(c)):
        print('OK')
    else:
        print('Not OK')

6432032021
# 1678933, 2022-11-12 09:43:19, PPP (100%)

al = {}
for i in range(int(input())):
    n,e = input().split()
    if e not in al:
        al[n] = e

n = input()
while n != 'q':
    check = set()
    n= n.split()
    c = 0
    for i in n:
        if i in al:
            check.add(al[i])
            c += 1
        else:
            print('Not OK')
            break
    if c ==  len(n)  :
        if len(check) == len(n):
            print('OK')
        else:
            print('Not OK')
    n = input()
        
       
       
        


6530005821
# 1678946, 2022-11-12 09:43:51, PPP (100%)

n = int(input())
d ={}
final=[]
teams=set()
for i in range(n):
    team,nation = input().split()
    d[team]=nation
x = input()
while x!= 'q':
    final.append(x)
    x = input()

def check(t):
    t=t.split()
    g = set()
    for e in t:
        if e in d:
            if d[e] not in g:
                g.add(d[e])
            else:
                return 'Not OK'       
        else:
            return 'Not OK'
    return 'OK'
for e in final:
    print(check(e))




6530007021
# 1678576, 2022-11-12 09:23:32, PPP (100%)

n = int(input())
natio = dict()
for i in range(n):
    team,na = input().split()
    natio[team] = na
n = input().split()
while n[0] != 'q':
    me = True
    N = []
    for i in n:
        if i in natio:
            if natio[i] not in N:
                N.append(natio[i])
            else:
                me = False
        else :
            me = False
    if me:
        print('OK')
    else:
        print('Not OK')
    n = input().split()

6530010921
# 1678848, 2022-11-12 09:37:45, PPP (100%)

#good_LUCK
countrys = {}
countryl = []
teams = {}
teaml = set()
for i in range(int(input())):
    t,c = input().split()
    if c not in countrys:
        countrys[c] = {t}
        countryl.append(c)
    else:
        countrys[c].add(t)
    teams[t] = c
    teaml.add(t)
a = input()
while a != 'q':
    countryc = []
    A = a.split()
    for i in A:
        if i not in teaml:
            print('Not OK')
            break
        if teams[i] not in countryc:
            countryc.append(teams[i])
        else:
            print('Not OK')
            break
        if len(countryc) == len(A):
            print('OK')
    a = input()

6530012121
# 1678571, 2022-11-12 09:23:17, PPP (100%)

n = int(input())
nation = {}
for i in range(n):
    team,chat = input().strip().split()
    nation[team]=chat
wn = input().strip().split()
while wn != ['q']:
    check =[];inv =True
    for i in wn:
        if i in nation.keys():
            check.append(nation[i])
        else:
            print('Not OK')
            inv = False
            break
    if inv ==True:
        checkset = set(check)
        if len(checkset) == len(check):
            print("OK")
        else:
            print("Not OK")
    wn = input().strip().split()



6530014421
# 1678642, 2022-11-12 09:27:17, PPP (100%)

n=int(input())
ft={}
for i in range(n):
    t,c=input().strip().split()
    if c in ft:
        ft[c].add(t)
    else:
        ft[c]={t,}
while True:
    gr=input().strip().split()
    c=set()
    r=True
    if gr==['q']:
        break
    for e in gr:
        nc=len(c)
        for j in ft:
            if e in ft[j]:
                c.add(j)
                break
        if len(c)==nc:
            r=False
            break
    if not r:
        print('Not OK')
    else:
        print('OK')


6530015021
# 1678539, 2022-11-12 09:21:26, PPP (100%)

def teamLeague(d,team):
    for key in d:
        if team in d[key]:
            return key
    return "Not found"
    
    
n = int(input())
national = {}
for i in range(n):
    team,country = input().strip().split()
    if country not in national:
        national[country] = []
    national[country].append(team)

out = []
while True:
    x = input().strip()
    if x == 'q':break
    group = x.split()
    c = [teamLeague(national,t) for t in group]
    if len(set(c)) != len(c) or 'Not found' in c:
        out.append('Not OK')
    else: out.append('OK')

print('\n'.join(out))


6530017321
# 1678749, 2022-11-12 09:32:24, PPP (100%)

d={}
for i in range(int(input())):
    t, c=input().split()
    if t not in d:
        d[t]=c

while True:
    x=input()
    if x == 'q':
        break
    s = x.split()
    c=set()
    OK=True

    for i in s:
        if i not in d:
            Ok=False
            break
        c.add(d[i])
    if OK and len(c)==len(s):
        print('OK')
    else:
        print('Not OK')
        


6530020121
# 1678988, 2022-11-12 09:46:36, PPP (100%)

def xinput():
    return data.pop(0)

def dup_check(e):
    a = []
    for k in e:
        if k in nat.keys():
            a.append(nat[k])
    b = set(a)
    if len(b) != len(e):
        return 'Not OK'
    else:
        return 'OK'

data = [
    '10',
'Liverpool England',
'ManCity England',
'Bayern Germany',
'Dortmund Germany',
'Barcelona Spain',
'Milan Italy',
'PSG France',
'Ajax Holland',
'Real Spain',
'Celtic Scotland',
'Liverpool Dortmund Milan Ajax',
'Liverpool Barcelona PSG Real',
'ManCity Milan PSG Ajax Celtic',
'ManCity Ajax SamyanFC Real Bayern',
'q'
    ]

x = int(input())
nat = {}
for i in range(x):
    club,coun = input().split(' ')
    if coun not in nat:
        nat[club] = coun
    else:
        nat[club].append(coun)
checking = input()
while checking != 'q':
    temp = checking.split(' ')
    print(dup_check(temp))
    checking = input()
    


6530021821
# 1679167, 2022-11-12 09:56:09, PPP (100%)

t = []
c = []
lst = []
d = {}
check = [] #[['Liverpool', 'Dortmund', 'Milan', 'Ajax']]
ans = []

n = int(input())
for i in range(n):
    team , cou = input().split()
    t.append(team)
    c.append(cou)
    lst.append([team , cou])

for i in c:
    d[i] = []

for i in t:
    for j in lst:
        if i in j:
            d[j[1]] += [i]
            

while True :
    a = [e for e in input().split()]
    if a == ['q']:
        break
    check.append(a)

for i in check:
    con = True
    b = []
    for j in i:
        if j not in t:
            ans.append('Not OK')
            con = False
        
        else:
            for k , v in d.items():
                if j in v:
                   b.append(k)
    if con:               
        b_s = set(b)
        b_s = list(b_s)
        if len(b_s) == len(i):
            ans.append('OK')
        if len(b_s) != len(i):
            ans.append('Not OK')
            
for i in ans:
    print(i)
            
            
            
            
            
    

6530023021
# 1678627, 2022-11-12 09:26:24, PPP (100%)

n = int(input())
ddd = {}
for i in range(n):
    team,cou = input().strip().split()
    if cou not in ddd:
        ddd[team] = cou
x = input().strip()
while x != 'q':
    a = x.split()
    rrr = set()
    for i in range(len(a)):
        if a[i] in ddd:
            rrr.add(ddd[a[i]])
    if len(rrr) == len(a):
        print('OK')
    else:
        print('Not OK')
    x = input().strip()

6530027621
# 1679052, 2022-11-12 09:49:42, PPP (100%)

cdic ={}
tdic = {}
for i in range(int(input())):
    t,c = input().split()
    if c not in cdic:
        cdic[c] = [t]
    else:
        cdic[c].append(t)
    if t not in tdic:
        tdic[t] = c

anslist =[]
ans = []
ansf =[]
while True:
    x = input().split()
    if len(x) == 1:
       break
    for e in x:
        if e in tdic:
            anslist.append(tdic[e])
        else:
            anslist.append(e)
    for t in anslist:
        if t in cdic:
            if t not in ans:
                ans.append(t)
            else:
                ansf.append('Not OK')
                break
        else:
            ansf.append('Not OK')
            break
    if len(anslist) == len(ans):
        ansf.append('OK')
    anslist = []
    ans = []
    
for ad in ansf:
    print(ad)

6530028221
# 1678563, 2022-11-12 09:23:02, PPP (100%)

d={}
for i in range(int(input())) :
    k,v=[str(e) for e in input().split()]
    d[k]=v
def check(a) :
    c=set()
    for k in a :
        if k not in d :
            return False
        c.add(d[k])
    if len(c)== len(a) :
        return True
    else :
        return False
x=str(input())
while x!='q' :
    a=x.split()
    if check(a) :
        print('OK')
    else :
        print('Not OK')
    x=str(input())




6531403021
# 1678570, 2022-11-12 09:23:16, PPP (100%)

n = int(input())
t = dict()
for i in range (n) :
    s = input().split()
    t[s[0]] = s[1]
r = list()
s = input()
while s!='q' :
    s = s.split()
    k = list()
    c = True
    for i in s :
        if not i in t :
            c = False
        elif not t[i] in k :
            k.append(t[i])
        else :
            c = False
    if c :
        r.append("OK")
    else :
        r.append("Not OK")
    s = input()
    
for i in r :
    print(i)


6531405321
# 1679496, 2022-11-12 10:13:23, PPP (100%)

n = int(input())
data = {}
for i in range(n) :
    team,country = input().split()
    data[team] = country

text = []
m = input().split()
while m != ['q'] :
    text += [m]
    m = input().split()

number = {}
check = []
for k in text :
    for l in range(len(k)) :
        check.append(k[l])
        for o in data :
            if k[l] == o :
                #print(data[o])
                if o in number :
                    number[data[o]] += 1
                else :
                    number[data[o]] = 1
    #print(number)
    #print(len(number))
    #print(check)
    if len(check) == len(number) :
        print('OK')
    else :
        print('Not OK')
    number = {}
    check = []
    
        
    

6531409921
# 1678811, 2022-11-12 09:36:12, PPP (100%)

n = int(input())
d = {}
for i in range(n):
    t,c = input().strip().split()
    if c not in d:
        d[c] = set()
    d[c].add(t)
while True:
    com = {}
    show = []
    x = input().strip()
    if x == 'q':
        break
    x = x.split()
    for t in x:
        for c in d:
            if t in d[c]:
                if c not in com:
                    com[c] = []
                com[c].append(t)
    for c in com:
        if len(com[c]) > 1 or len(com) != len(x):
            show.append('bad')
            break
    if 'bad' in show:
        print('Not OK')
    elif show == []:
        print('OK')

6530032721
# 1678720, 2022-11-12 09:30:58, PPP (100%)

n = int(input())
teams = {}
for i in range(n) :
    t,c = input().strip().split()
    if t not in teams :
        teams[t] = c
        
s = input().strip()
out = ''
while s != 'q' :
    team = s.split()
    country = []
    for e in team :
        if e in teams :
            country.append(teams[e])
        else :
            country = []
            break
    if len(country) == len(set(country)) and country != [] :
        out += 'OK' + '\n'
    else :
        out += 'Not OK' + '\n'
    s = input().strip()
print(out)


6530035621
# 1678853, 2022-11-12 09:38:12, PPP (100%)

n = int(input())
a = {}
for i in range(n):
    t,c = input().split()
    if c not in a:
        a[t]= c
    else:
        a[t] = c

found = False
while True:
    y = input().split()
    if y[0] == "q":
        break
    b = set()
    for e in y:
        if e in a:
            b.add(a[e])
    if len(b) != len(y):
            print("Not OK")
    else:
            print("OK")
#         else:
#             print("Not OK")
        
    
        
    
    
    
    



6530036221
# 1678796, 2022-11-12 09:35:08, PPP (100%)

country = {}
for k in range(int(input())):
    n, c = input().split()
    country[n] = c

x = input()
while x != "q":
    check = []
    t = x.split()
    ans = []
    for e in t:
        if e in country:
            check.append(country[e])
        else :
            ans.append("Not OK")
    for e in check:
        n = check.count(e)
        if n >1 : ans.append("Not OK")
        else : ans.append("OK")

    if "Not OK" in ans:
        print("Not OK")
    else:
        print("OK")
    x= input()

6530038521
# 1679302, 2022-11-12 10:02:59, PPP (100%)

team = dict()
for i in range(int(input())):
    club, nation = input().split(); team[club] = nation

x = input(); lst = []
while x != 'q':
    result = 'T'
    x = x.split()
    for i in range(len(x)):
        if x[i] not in team:
            result = 'F'
        else:
            for j in range(i+1,len(x)):
                if x[j] not in team:
                    result = 'F'
                elif team[x[i]] == team[x[j]]:
                        result = 'F'
    lst.append(result)
    x = input()
for e in lst:
    if e == 'T':
        print('OK')
    else:
        print('Not OK')


6530045921
# 1678829, 2022-11-12 09:36:56, PPP (100%)

n = int(input())
d = {}
for i in range (n) :
    team,cou = input().split()
    if cou not in d :
        d[cou] = [team]
    else :
        d[cou].append(team)
x = input()        

def check(order) :
    ans = set()
    for i in range (len(order)) :
        for e in d :
            if order[i] in d[e] :
                ans.add(e)
    if len(ans) == len(order) :
        return 'OK'
    else :
        return 'Not OK'
    
    return ans


ans = []
c = []
while x != 'q' :
    order = x.split()
    ans.append(check(order))
    x = input()
for i in range (len(ans)) :
    print(ans[i])

6530049421
# 1678530, 2022-11-12 09:20:57, PPP (100%)

# Quiz 3 1  Group Stage

team_nation = dict()
for _ in range(int(input())):
    team, nation = input().split()
    team_nation[team] = nation
    
    
x = input().split()
while x[0] != "q":
    nations = list()
    replicate = False
    for team in x:
        if team not in team_nation:
            replicate = True
        elif team_nation[team] in nations:
            replicate = True
        else:
            nations.append(team_nation[team])
    if replicate == True:
        print("Not OK")
    else:
        print("OK")
    x = input().split()
            
    


6530053921
# 1678637, 2022-11-12 09:27:02, PPP (100%)

n = int(input())
d = {}
for i in range(n) :
    k, v = input().split()
    d[k] = v
while True :
    L = []
    a = input()
    if a == 'q' :
        break
    l = a.split()
    s = 'OK'
    for k in l :
        if k not in d.keys() :
            s = 'Not OK'
            break
        if d[k] not in L :
            L.append(d[k])
        else :
            s = 'Not OK'
            break
    print(s)


6530058021
# 1679274, 2022-11-12 10:01:53, PPP (100%)

check = 'OK'
n = int(input())
p= {}
for i in range(n):
    x, y = input().split()
    p[x] = y
z = input().split()
t = set()
while z[0] != 'q':
    for o in z:
        if o not in p:
            check = 'Not OK'
            break
        else:
            t.add(p[o])
    if len(t) != len(z):
        check = 'Not OK'
    else:
        check = 'OK'
    t = set()
    print(check)
    z = input().split()

6530060221
# 1679055, 2022-11-12 09:49:47, PPP (100%)

x = int(input())
nation_blank= {}
nation_team  = {}
team_nation = {}

for i in range(x):
    data = input().split()
    team_nation[data[0]] = data[1]
    if data[1] not in nation_team:
        nation_team[data[1]] = []

data = input()

while data != 'q':
    a = True
    data = data.split()
    for i in data:
        if i not  in team_nation:
            a = False
        else:
            nation_team[team_nation[i]].append(i)
            for i in nation_team:
                if len(nation_team[i]) > 1:
                    a = False
    
    if a ==False:
        print ("Not OK")
    else:
        print ("OK")
    for i in nation_team:
        nation_team[i] = []
    data  = input()

     


    
        
     




6530066021
# 1679112, 2022-11-12 09:53:09, PPP (100%)

x = int(input())
g = {}
for i in range(x):
    t , c = input().strip().split()
    if c not in g:
        g[c] = [t]
    else:
        g[c] += [t]

y = input()
while len(y) != 1 and y != 'q':
    y = y.split()
    c = []
    d = []
    for i in range(len(y)):
        c += [1]
    for i in g:
        for j in y:
            if j in g[i]:
                d.append(1)
                break
    if d != c:
        print('Not OK')
    else:
        print('OK')
                
    y = input().strip()

6530067721
# 1678788, 2022-11-12 09:34:55, PPP (100%)

tem = {}
coun = []
for i in range(int(input())):
    team,ct = input().split()
    if team not in tem:
        tem[team] = ct
        coun.append(team)

while True:
    t = input().split()
    if t[0] == "q":break
    a = []
    out = {}
    for i in t:
        if i in coun:
            a.append(tem[i])
    k = set(a)
    if len(t) == len(k):
        print("OK")
    else:
        print("Not OK")
        
    

6530071121
# 1678568, 2022-11-12 09:23:14, PPP (100%)

n = int(input())
country = {} # = {team: country}
for i in range(n):
    team, ct = input().split()
    country[team] = ct
x = input().split()
while x[0] != "q":
    ans = []
    check = set()
    out = False
    for e in x:
        if e in country:
            ans.append(country[e])
            check.add(country[e])
        else :
            print("Not OK")
            out = True
            break
    if out == False:
        out2 = False
        for e in sorted(check):
            c = ans.count(e)
            if c > 1 :
                print("Not OK")
                out2 = True
                break
            c = 0
        if out2 == False:
            print("OK")
    x = input().split()

6530072821
# 1678526, 2022-11-12 09:20:37, PPP (100%)

team = {}
for i in range(int(input().strip())):
    one,coun = input().strip().split()
    team[one]=coun
check = input().strip()
while check != "q":
    checking = check.split()
    rule = True
    counList = set()
    for one in checking:
        if one not in team:
            rule = False
            break
        counList.add(team[one])
    if len(counList) != len(checking):
        rule = False
    if rule:
        print("OK")
    else:
        print("Not OK")
    
    check = input().strip()


6530075721
# 1678533, 2022-11-12 09:21:10, PPP (100%)

country = {}
for i in range(int(input())) :
    t,c = input().split()
    country[t] = c
while True :
    x = input().split()
    if len(x) == 1 :
        break
    s = set()
    for i in x :
        if i not in country :
            break
        s.add(country[i])
    if len(s) != len(x) :
        print('Not OK')
    else :
        print('OK')

6530077021
# 1678729, 2022-11-12 09:31:26, PPP (100%)

team = {}
t = set()
for i in range(int(input())):
    n,c = input().strip().split()
    if c not in team:
        team[c] = set()
    team[c].add(n)
    t.add(n)
while True:
    x = input().strip()
    if x == 'q':break
    c = True
    ans = set()
    for n in x.split():
        if n not in t:
            c = False
            break
        else:
            for m in team:
                if n in team[m]:
                    if m in ans:
                        c = False
                    else:
                        ans.add(m)
    if c :
        print('OK')
    else:
        print('Not OK')

6530078621
# 1678896, 2022-11-12 09:41:06, PPP (100%)

def scan(a,c):
    count=[]
    for j in range(len(a)):
        b=len(count)
        for i in c:
            if a[j] in c[i]: count.append(i)
        if len(count)==b: return 'Not OK'
    if len(count)==len(set(count)): return 'OK'
    return 'Not OK'

a=int(input())
country={}
for i in range(a):
    t,c=input().strip().split()
    if c not in country: country[c]=set()
    country[c].add(t)
a=input()
while a!='q':
    a=a.strip().split()
    print(scan(a,country))
    a=input()

6530084321
# 1678592, 2022-11-12 09:24:43, PPP (100%)

d = {}
for i in range(int(input())) :
    club,league = input().split()
    d[club.lower()] = league.lower()
group = input().lower()
out = []
while group != 'q' :
    group = group.split()
    check = []
    not_ok = False
    for e in group :
        if e in d :
            check.append(d[e])
        else :
            not_ok = True
    sc = set(check)
    if not_ok :
        out += ['Not OK']
    elif len(sc) == len(check) :
        out += ['OK']
    else :
        out += ['Not OK']
    group = input().lower()
print('\n'.join(out))

6530102021
# 1678902, 2022-11-12 09:41:18, PPP (100%)

a = int(input())
t = 0
team1 = []
country = []
co = {}
same = []
while t < a:
    team, cun = input().split()
    team1.append(team)
    country.append(cun)
    co[team] = cun
    t += 1

a = input()
while a != 'q':
    a = a.split()
    for i in a:
        if i in co:
            if co[i] in country:
                if co[i] not in same:
                    same.append(co[i])
                else:
                    print('Not OK')
            
            else:
                print('Not OK')
        else:
            print('Not OK')
        
    b = set(same)
    if len(b) == len(a):
        print('OK')
    same = []
    a = input()

            

    



6530103621
# 1679686, 2022-11-12 10:23:19, PPP (100%)

d = {}
for i in range(int(input())):
    team,nation = input().split()
    d[team] = nation

while True:
    a = input()
    if a == 'q' : break
    a = a.split()
    l = []
    for i in range(len(a)):
        for j in range(i+1,len(a)):
            if a[i] in d and a[j] in d:
                if d[a[i]] != d[a[j]]:
                    l.append(0)
                else:
                    l.append(1)
                    
            else:
                l.append(1)
    if 1 in l:
        print("Not OK")
    else:
        print("OK")


6530107121
# 1679136, 2022-11-12 09:54:15, PPP (100%)

n = int(input())
countrys = {}
for i in range(n):
    team,country = input().split()
    if country in countrys:
        countrys[country].add(team)
    else:
        countrys[country] = {team}
t = input()
g = set()
for e in countrys.values():
    g = g|e
while t != 'q':
    t = set(t.split())
    p = False
    for e in countrys.values():
        if len(t&e) == 2:
            p = True
        if not(t<=g):
            p = True
        
    if not(p):
        print('OK')
    else:
        print('Not OK')
    t = input()



6530109421
# 1678877, 2022-11-12 09:39:28, PPP (100%)

n = int(input())
d = {}
for i in range(n):
    t, c = input().split()
    if c not in d:
        d[c] = [t]
    else:
        d[c].append(t)

while True:
    g = input().split()
    if len(g) == 1: break
    x = []
    for i in g:
        for j in d:
            if i in d[j]:
                x.append(j)
                break
    more = False
    for k in x:
        if x.count(k) > 1:
            more = True
            break
    if more == False and len(x) == len(g):
        print('OK')
    else:
        print('Not OK')

6530111621
# 1679222, 2022-11-12 09:59:06, PPP (100%)

n = int(input())
d = {} #t,c
di = {} #c,t
for i in range(n):
    t,c = input().split()
    t = t.strip() ; c = c.strip()
    if t not in d:d[t] = c
    if c not in di: di[c] = set()
    di[c].add(t)
x = input().strip()
while x != "q":
    tt = x.split()
    f = set()
    for t in tt:
        if t in d:
            f.add(d[t])
    if len(f) != len(tt):
        print("Not OK")
    else:
        print("OK")        
    x = input().strip()

6530112221
# 1678588, 2022-11-12 09:24:31, PPP (100%)

#good_LUCK
teams = {}
for i in range(int(input())):
    team, country = input().split()
    if team not in teams:
        teams[team] = country

inp = input().split()
while len(inp) != 1:
    OK = True
    countries = set()
    for team in inp:
        if team not in teams:
            print('Not OK')
            OK = False
            break
        
        if teams[team] not in countries:
            countries.add(teams[team])
            
        else:
            print('Not OK')
            OK = False
            break
    if OK:
        print('OK')
        
    inp = input().split()
        
    
        


6530113921
# 1678665, 2022-11-12 09:28:33, PPP (100%)

n = int(input())
d = {}
for i in range(n):
    t = input().split()
    d[t[0]] = t[1]
l = []
i = input()
while i != 'q':
    l.append(i.split())
    i = input()

for i in range(len(l)):
    for j in l[i]:
        if j not in d:
            l[i] = False
            break
    if l[i] != False:
        s = [d[e] for e in l[i]]
        s = set(s)
        if len(s) < len(l[i]):
            l[i] = False
        else:
            l[i] = True
    if l[i]:
        print('OK')
    else:
        print('Not OK')

6530117421
# 1678547, 2022-11-12 09:22:00, PPP (100%)

dic = {}
for i in range(int(input())):
    t,c = [e.strip() for e in input().split()]
    dic[t] = c
inp = str(input())
while inp != "q":
    text = "OK"
    check = set()
    for i in inp.split():
        i.strip()
        if i not in dic:
            text = "Not OK"
            break
        elif dic[i] not in check: check.add(dic[i])
        else:
            text = "Not OK"
            break
    print(text)
    inp = str(input())


6530118021
# 1678836, 2022-11-12 09:37:17, PPP (100%)

n = int(input())
city = {}
for i in range(n):
    team,c = input().split()
    city[team] = c
m = input()
check = []
out = []
while m != 'q':
    group = m.split()
    j = True
    for e in group:
        if e not in city:
            out.append('Not OK')
            j = False
            break
        else:
            check.append(city[e])
    x = set(check)
    if len(x) == len(check) and j:
        out.append('OK')
    elif j:
        out.append('Not OK')
    check = []
    m = input()
for e in out:
    print(e)

6530123121
# 1680334, 2022-11-12 10:52:41, PPP (100%)

n = int(input())
con = {} #{team:contry}
team = {}
for i in range (n):
    t , c = input().split()
    con[t] = c
    if c not in team:
        team[c] = set()
    team[c].add(t)
while True :
    ip = input()
    if ip == 'q':
        break
    teams = ip.split()
    con_t = []
    set_t = set()
    said = True
    for k in teams:
        if k in con:
            con_t.append(con[k])
            set_t.add(con[k])
        else :
             said = False
    if said == True:
        if len(set_t) != len(con_t):
            print ('Not OK')
        else:
            print('OK')
    else:
        print ('Not OK')



6530126021
# 1678542, 2022-11-12 09:21:40, PPP (100%)

con={}
for i in range(int(input())):
    name,cony = input().split()
    con[name] = cony
x = input()
while x != 'q':
    x = x.split()
    y = set()
    for i in x:
        if i not in con:
            pass
        else:
            y.add(con[i])
    if len(y) != len(x):
        print('Not OK')
    else:
        print('OK')
    x = input()   
    


6530131121
# 1678668, 2022-11-12 09:28:40, PPP (100%)

d={}
for i in range(int(input())):
    k = input().split()
    if k[0] not in d:
        d[k[0]] = set()
    d[k[0]].add(k[1])
x=input()
match=[]
while x != 'q':
    match.append(x.split())
    x=input()
for e in match:
    nat=[]
    for i in range(len(e)):
        if e[i] in d:
            if d[e[i]] in nat:
                print("Not OK")
            elif d[e[i]] not in nat:
                nat.append(d[e[i]])
        else: print("Not OK")
    if len(e) == len(nat):
        print("OK")

6530137021
# 1679856, 2022-11-12 10:30:27, PPP (100%)

team = {}
for i in range(int(input())):
    t,c = input().split()
    team[t] = {c}
x = input().split()
ans = set()  
while x[0] != 'q':
    for e in x:
        if e not in team:
            break
        ans = ans | team[e]
    if len(ans) == len(x):
        print('OK')
    else:
        print('Not OK')
    x = input().split() 
    ans = set()  
    
       
                        
    
        
    
    
        

    
        



6530139221
# 1679092, 2022-11-12 09:51:49, PPP (100%)

n = int(input())
Football_Team_Dict = {}
for i in range(n):
    Team, Country = input().split()
    #print(Team, Country)
    if Team not in Football_Team_Dict:
        Football_Team_Dict[Team] = Country
    else:
        Football_Team_Dict[Team] = Country

#print(Football_Team_Dict)
Result = {}
Group = input()
i = 1
while Group != 'q' and Group != 'Q':
    Group = Group.split()
    LIST = list([])
    for team in Group:
        
        if team not in Football_Team_Dict:
            Result[i] = "Not OK"
            break
        else:
            if Football_Team_Dict[team] not in LIST:
                LIST.append(Football_Team_Dict[team])
            else:
                LIST.append(Football_Team_Dict[team])
                Result[i] = "Not OK"
                break
        Result[i] = "OK"
        
    i += 1
    Group = input()

for j in Result.keys():
    print(Result[j])

6530149521
# 1678673, 2022-11-12 09:28:48, PPP (100%)

n = int(input())
team = dict()
team1 = dict()
o = []
for i in range (n) :
    n = input().split()
    if n[1] not in team :
        team[n[1]] = [n[0]]
        team1[n[1]] = 0
        o.append(n[0])
    else :
        team[n[1]].append(n[0])
        o.append(n[0])
ans = []
while True :
    k = team1.copy()
    n = input().strip()
    if n == 'q' :
        break
    n = n.split()
    for x in n :
        for y in team :
            if x in team[y] :
                k[y] += 1
    ch = 'OK'
    for x in k :
        if k[x] > 1 :
            ch = 'Not OK'
    for x in n :
        if x not in o :
            ch = 'Not OK'
    ans.append(ch)
for x in ans:
    print(x)

6530151721
# 1678715, 2022-11-12 09:30:45, PPP (100%)

a={}
f={}
for i in range(int(input())):
    t,c=input().split()
    if c not in a:
        a[c]=[]
    a[c].append(t)
    if t not in f:
        f[t]=[]
    f[t].append(c)
        
x=1
while x!='q':
    x=input().split()
    if x[0]=='q':
        break
    team=set()
    b=len(x)
    for i in x:
        if i in f:
            k=set()
            k.add(f[i][0])
            team=team|k
        else:
            break
    if b==len(team):
        print('OK')
    else:
        print('Not OK')


6530154621
# 1678611, 2022-11-12 09:25:25, PPP (100%)

g = {}
for i in range(int(input())):
    team, nation =input().split()
    if team not in g: g[team] = set()
    g[team].add( nation )
    
while True:
    a = set()
    k = input().split()
    if k[0] =='q': break
    for e in k:
        if e in g: a |= g[e]
        else: break
    if len(a) == len(k): print('OK')
    else: print('Not OK')

6530160321
# 1679003, 2022-11-12 09:47:22, PPP (100%)

d_team = {}
d_country = {}
n = int(input())
for i in range(n) :
    data = input().split()
    name_team = data[0]
    name_country = data[1]
    d_team[name_team] = name_country
    
    if name_country not in d_country :
        d_country[name_country] = [name_team]
    elif name_country in d_country :
        d_country[name_country].append(name_team)
while True :
    name_ = input()
    if name_ == "q" :
        break
    name_t = name_.split()
    check = []
    for i in name_t :
        if i in d_team :
            check.append(d_team[i])
        else :
            check.append("Hotdog")
    a = len(check)
    b = len(set(check))
  
    if "Hotdog" in check :
        print("Not OK")
    else :
        if a == b :
            print("OK")
        else :
            print("Not OK")
    
        
   


6530163221
# 1678661, 2022-11-12 09:28:18, PPP (100%)

n = int(input())
x = 'a'
check = {}
ans = set()
number = 0

while n > 0:
    [a,b] = [e for e in input().split()]
    check[a] = b
    n = n - 1
    
while x != 'q':
    x = [e for e in input().split()]
    
    if x == ['q']:
        break
    
    for i in x:
        if i in check:
            ans = ans.union([check[i]])
        
        number += 1
    
    if len(ans) == number:
        print('OK')
    else:
        print('Not OK')
        
    ans = set()
    number = 0

6530167821
# 1678623, 2022-11-12 09:26:10, PPP (100%)

teams = {}
for i in range(int(input())):
    team, country= input().split()
    teams[team]= country
x = input()

while x!='q':
    tmp = []
    all_teams= x.split()
    for team in all_teams:
        if (team in teams):
            #print(team)
            if (teams[team] not in tmp):
                #print(teams[team])
                tmp.append(teams[team])
            else:
                tmp = ['Not OK']
                break
        else:
            tmp = ['Not OK']
            break
    if len(tmp)==1: 
        print(''.join(tmp))
    else:
        print('OK')
    x = input()

6530168421
# 1679243, 2022-11-12 10:00:30, PPP (100%)

team = {}
for i in range(int(input())):
    n, c = input().split()
    if c not in team:
        team[n] = c
group = []
while True:
    x = input()
    if x == 'q': break
    group.append(x.split())
for g in group:
    dub = set()
    for e in g:
        c = 0
        if e in team:
            if team[e] not in dub:
                dub.add(team[e])
            else:
                print('Not OK')
                c = 1
                break
        else:
            print('Not OK') ; c = 1
            break
    if c == 0:
        print('OK')

6530172921
# 1679118, 2022-11-12 09:53:30, PPP (100%)

n = int(input())
ref = {}
team_ref = []
for i in range(n):
    team,country = [e.strip() for e in input().split()]
    ref[team] = country
x = input().strip()
while x!= "q":
    team_ref.append([e.strip() for e in x.split()])
    x = input().strip()
for competitor in team_ref:
    ref_country = set()
    OK = True
    for t in competitor:
        if t in ref:
            if ref[t] not in ref_country:
                ref_country.add(ref[t])
            else:
                OK = False
        else:
            OK = False
    if OK:
        print("OK")
    else:
        print("Not OK")
    
    

6530173521
# 1679059, 2022-11-12 09:50:00, PPP (100%)

data ={}
for i in range(int(input())):
    team, nation = input().split()
    if team not in data:
        data[team] = nation
group = input().split()
def check(teams):
    for i in range(len(teams)):
        k = True
        for e in teams[i+1:]:
            if e not in data or teams[i] not in data:
                k = False
                return k
            elif data[teams[i]] == data[e]:
                k = False
                return k
    return k
while group[0] != 'q':
    if check(group) == True:
        print('OK')
    if check(group) == False:
        print('Not OK')
    group = input().split()


6530175821
# 1678594, 2022-11-12 09:24:45, PPP (100%)

data = dict()
for i in range(int(input())) :
    x = input().strip().split()
    data[x[0]] = x[1]
while True :
    x = input().strip().split()
    if len(x) == 1 :
        break
    nation = list()
    for i in x :
        if i not in data :
            print("Not OK")
            break
        elif data[i] not in nation :
            nation.append(data[i])
        elif data[i] in nation :
            print("Not OK")
            break
    if len(nation) == len(x) :
        print("OK")


6530176421
# 1680806, 2022-11-12 11:09:52, PPP (100%)

K = {}
for i in range(int(input())):
    team,country = input().split()
    if team not in K:
        K[team] = ''
    K[team] = country
x = input()
while x != 'q':
    output = 'OK'
    teams = x.split()  # teams = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']

    H = {}
    for team in teams:
        if team in K:
            for e in K:
                if team == e:
                    if K[e] not in H:
                        H[K[e]] = 0
                    H[K[e]] += 1
                    break
        else:
            output = 'Not OK'
    for e in H:
        if H[e] > 1:
            output = 'Not OK'
            break
    print(output)   
    x = input()

6530178721
# 1678651, 2022-11-12 09:27:45, PPP (100%)

n = int(input())
data = {}
for i in range(n):
    team, country = input().split()
    data[team] = country
x = input()
while x != 'q':
    x = x.split()
    countryt = set()
    for i in x:
        if i not in data:
            print('Not OK')
            break
        else:
            countryt.add(data[i])
    if len(x) == len(countryt):
        print('OK')
    else:
        if i in data:
            print('Not OK')
    x = input()
    if x == 'q':
        break


6530183821
# 1678699, 2022-11-12 09:30:15, PPP (100%)

n=int(input())
d={}
for i in range(n):
    x=input().strip().split()
    d[x[0]]=x[1]
cu=[]
while True:
    l=[]
    
    x=input().strip().split()
    if x[0]=='q':
        break
    else:
        for e in x:
            if e in d:
                l.append(d[e])
            else:
                l.append('No')
    cu.append(l)
    

for e in cu:
    if len(set(e))!=len(e):
        print('Not OK')
    elif 'No' in e:
        print('Not OK')
    else:
        print("OK")

6530186721
# 1678741, 2022-11-12 09:32:09, PPP (100%)

data = {}
teams = []
for i in range(int(input())) :
    team,state = input().split()
    if state not in data :
        data[state] = [team]
    else :
        data[state].append(team)
    teams.append(team)
team = input().split()
while team[0] != 'q' :
    change = []
    found = {}
    nodata = False
    repeat = False
    for i in team :
        if i not in teams :
            nodata = True
            continue
        change.append([key for key,value in data.items() if i in value][0])
    for i in change :
        if i not in found :
            found[i] = 1
        else :
            found[i] += 1
            repeat = True
    if nodata == False and repeat == False :
        print('OK')
    else :
        print('Not OK')
    team = input().split()


6530187321
# 1678657, 2022-11-12 09:28:08, PPP (100%)

n = int(input())
nation = {}
for i in range(n):
    team, country = input().split()
    if country in nation:
        nation[country].append(team)
    else:
        nation[country] = [team]
x = input().split()
while x[0] != 'q':
    d = []
    t = True
    for e in x:
        c = 0
        for i in nation:
            if e in nation[i] and i not in d:
                d.append(i); c += 1; break
            elif e in nation[i] and i in d:
                t = False ; break
        if c == 0: t = False
        if t == False: break
    if t == True: print('OK')
    else: print('Not OK')
    x = input().split()


6530188021
# 1678565, 2022-11-12 09:23:09, PPP (100%)

n = int(input())
d = {}
l = []
for i in range(n):
    x = input().split()
    d[x[0]] =x[1]
    l += [x[0]]
x = input()

while x != 'q':
    gg = []
    s = 0
    h = x.split()
    for i in h:
        if i in d:
            if d[i] in gg:
                s += 1
            else:
                gg += [d[i]]
        else:
            s += 1
    if s != 0 :
        print('Not OK')
    else:
        print('OK')
    x = input()


6530189621
# 1678545, 2022-11-12 09:21:55, PPP (100%)

a={}
for i in range(int(input())):
    name,cou=input().split()
    a[name]=cou
b=[]
d=[]
while True:
    x=input().split()
    if x[0]=='q':break
    b=[i for i in x]
    c=set()
    for i in b:
        if i in a:
            c.add(a[i])
        
    if len(c)!=len(b):
        d+=['Not OK']
    else:
        d+=['OK']
print(('\n').join(d))

    
    



6530196021
# 1678878, 2022-11-12 09:39:30, PPP (100%)

n1 = int(input())
d1 = {}
for i in range(n1):
    team, country = input().split() ; team = team.strip() ; country = country.strip()
    d1[team] = country

check = input()
ans = []

while check != 'q':
    l1 = []
    check = check.split()
    for e in check:
        if e not in d1:
            ans.append('Not OK')
            l1 = []
            break
        else:
           l1.append(d1[e])
    if l1 != []:
        s1 = set(l1)
        if len(l1) == len(s1):
            ans.append('OK')
        else:
            ans.append('Not OK')
    check = input()
for w in ans:
    print(w)

6530197621
# 1678506, 2022-11-12 09:18:33, PPP (100%)

n = int(input())

team = {}
for i in range(n):
    x = input().split()
    name, nation = x[0], x[1]
    team[name] = nation

x = input()
ans = []
while x != "q":
    group = x.split()
    nation_g = set()
    rule = True
    for t in group:
        if t not in team:
            rule = False
            break
        nation_g = nation_g.union({team[t]})
    if rule != False and len(nation_g) < len(group):
        rule = False
    if rule:
        print("OK")
    else:
        print("Not OK")
    x = input()

6530201421
# 1678593, 2022-11-12 09:24:43, PPP (100%)

All_Data={}
N=int(input())
for i in range(N):
    team,ct=input().split()
    if ct not in All_Data:
        All_Data[team]=ct


results=set()
want=input().strip()
while want!="q":
    Checker=True
    want=want.split()
    for team in want:
        if team not in All_Data or ({All_Data[team]}.issubset(results)): 
            Checker=False
        elif not ({All_Data[team]}.issubset(results)):
            results.add(All_Data[team])
    if Checker:
        print("OK")
    else:
        print("Not OK")
    results=set()
    want=input().strip()

6530203721
# 1678986, 2022-11-12 09:46:30, PPP (100%)

countrys = {}
teams = {}
chte = []
for i in range(int(input())):
    team, country = input().split()
    if team not in teams:
        teams[team] = []
    teams[team].append(country)
    chte.append(team)

ch = input()
out = []
while ch != 'q':
    data = ch.split()
    pre = []
    for i in data:
        if i in chte and teams[i] not in pre:
            pre.append(teams[i])
        else:
            pre.append(['Not OK'])
    if ['Not OK'] not in pre:
        out.append('OK')
    else:
        out.append('Not OK')
    ch = input().strip()
for e in out:
    print(e)


6530206621
# 1678632, 2022-11-12 09:26:38, PPP (100%)

n = int(input())
teams = {}
for i in range(n):
    team,coun = input().strip().split()
    teams[team] = [coun]
# print(teams)
        
t = ""
while t != ["q"]:
    t = input().split()
    valid = True
    country = []
    for team in t:
        if team in teams:
            country.append(teams[team])
        else:
            valid = False
    country.sort()
    for i in range(len(country)-1):
        if country[i] == country[i+1]:
            valid = False
#     print(t)
    if valid == True and t != ["q"]:
        print("OK")
    elif t != ["q"]:
        print("Not OK")




6530207221
# 1678606, 2022-11-12 09:25:10, PPP (100%)

n = int(input())
teams = {}
for i in range(n):
    country,team = input().split()
    if country not in teams :
        teams[country]= team
    else :
        teams[country] = team
#print(teams)
a = True
while a :
    check = set()
    x = input()
    if x == 'q' :
        a = False
    else :
        l = x.split()
        #print(l)
        for ch in l :
            if ch in teams:
                check.add(teams[ch])
            else :
                pass
        #print(check)
        if len(l) != len(check):
            print('Not OK')
        else :
            print('OK')




6530209521
# 1678522, 2022-11-12 09:20:08, PPP (100%)

dic = {}
for i in range(int(input())) :
    team,country = input().split()
    dic[team] = country
while True :
    x = input().split()
    if len(x) == 1 : break
    l = []
    for u in x :
        if u in dic :
            l.append(dic[u])
    if (len(x) != len(l)) or (len(l) != len(set(l))) :
        print('Not OK')
    else :
        print('OK')

6530210021
# 1678882, 2022-11-12 09:39:42, PPP (100%)

n = int(input())
d = {} # {team:nation}
for i in range(n):
    team,nation = input().split()
    d[team] = nation

x = input()
ls,ans = [],[]
while x != 'q':
    x = x.split()
    check = 0
    count = 0
    for team in x:
        if team in d:
            ls.append(d[team])
        else:
            ans.append('Not OK')
            check = 1
            break
    if check == 0: 
        for e in ls:
            if ls.count(e) != 1:
                ans.append('Not OK')
                break
            else:
                count += 1
                if count == len(ls):
                    ans.append('OK')
                    break
    ls = []
    x = input()


for e in ans:
    print(e)

6530212321
# 1678564, 2022-11-12 09:23:06, PPP (100%)

leauge = {}
for i in range(int(input())) :
    team,nation = input().split(' ')
    if nation not in leauge :
        leauge[team] = nation


g = []
group = input().split(' ')
while group[0] != 'q' :
    best = True
    for t in group :
        if t not in leauge :
            print('Not OK')
            best = False
            break
        elif leauge[t] not in g :
            g.append(leauge[t])
        else :
            print('Not OK')
            best = False
            break
    if best :
        print('OK')
    g = []
    group = input().split(' ')

6530213021
# 1678849, 2022-11-12 09:37:55, PPP (100%)

info = {} #{team:coun, ...}
for i in range(int(input())):
    team, coun = input().strip().split()
    info[team] = coun

no_dupc = set()
all_c = []
x = input() #Liverpool Dortmund Milan Ajax

while x != 'q':
    truth = True
    
    for teams in x.split():
        
        if teams not in info: #check if teams is in info
            truth = False
        else:
            no_dupc.add(info[teams]) #no dupe coun
            all_c.append(info[team]) #coun all (has dupe)
        

    if truth == False:
        print("Not OK")
    elif len(no_dupc) == len(all_c):
        print("OK")
    else:
        print("Not OK")

    
    x = input()
    no_dupc = set()
    all_c = []

6531303021
# 1678549, 2022-11-12 09:22:12, PPP (100%)

world = {}
team = {}
for i in range(int(input())):
    k,t = input().split()
    if t not in world:world[t] = []
    world[t].append(k)
    team[k] = t

while True:
    x = input()
    if x == 'q':break
    a = []
    ni = True
    for i in x.split():
        if i not in team:ni = False;break
        a.append(team[i])
    if len(a) != len(set(a)):ni = False
    if ni: print('OK')
    else: print('Not OK')

6531304621
# 1678726, 2022-11-12 09:31:17, PPP (100%)

n = int(input())
d = {}
sname = set()
for i in range(n):
    name, c = input().split()
    sname.add(name)
    if c in d:
        d[c].add(name)
    else:
        d[c] = {name}

inp = input()
output = []
while inp != 'q':
    lname = inp.split()
    if set(lname) & sname == set(lname):
        found = True
        for c in d:
            if not len(set(lname) & d[c]) in {0, 1}:
                found = False
        if found == False:
            output.append('Not OK')
        else:
            output.append('OK')
    else:
        output.append('Not OK')
    inp = input()

for e in output:
    print(e)


6531305221
# 1678544, 2022-11-12 09:21:49, PPP (100%)

n = int(input())
fbt = {}
for i in range(n):
    x = input().split()
    fbt.update({x[0]: x[1]})
result = []
while True:
    y = input()
    z = y.split()
    if y == 'q':
        break
    fbcheck = []
    bool = True
    for i in z:
        if i not in fbt:
            bool = False
            break
        elif fbt[i] not in fbcheck:
            fbcheck.append(fbt[i])
        elif fbt[i] in fbcheck:
            bool = False
            break

    if bool:
        result.append('OK')
    else:
        result.append('Not OK')

for i in result:
    print(i)

6531306921
# 1678541, 2022-11-12 09:21:38, PPP (100%)

a=int(input())
td={}
for i in range(a):
    team,ct=input().split()
    td[team]=ct
x=input().split()
while x != ['q'] :
    z="OK"
    for i in x:
        if i not in td:
            z="Not OK"
    if z=="OK":
        y=[td[i] for i in x]
        y.sort()
        for i in range(len(y)-1):
            if y[i]==y[i+1]:
                z="Not OK"
    print(z)
    x=input().split()

6531307521
# 1678760, 2022-11-12 09:33:19, PPP (100%)

each_team = {}
allteam = []
co = set()
for i in range(int(input())) :
    team,country = input().split()
    each_team[team] = country
    allteam.append(team)
comp = input()
while comp != "q" :
    check = True
    lcomp = comp.strip().split()
    for e in lcomp :
        if e not in allteam :
            check = False
        elif e in each_team :
            co.add(each_team[e])
    if len(co) != len(lcomp) :
        check = False
    if check :
        print("OK")
    else :
        print("Not OK")
    comp = input()
    check = True   
    co = set()

6531310321
# 1678950, 2022-11-12 09:44:03, PPP (100%)

x=int(input())
team={}
for i in range(x):
    y=input().split()
    if y[1] not in team:
        team[y[1]]=[y[0]]
    else:
        team[y[1]].append(y[0])
y=input().split()
ret=[]
while True:
    ok=0
    if len(y)==1: break
    for i in team:
        chck=0
        for j in y:
            if j in team[i]:
                chck+=1
            if chck>1:
                ok+=1
    skip=0
    for j in y:
        chck2=0
        for i in team:
            if j in team[i]:
                chck2+=1
        if chck2==0:
            ret.append('Not OK')
            skip+=1
    if skip!=0:
        y=input().split()
        continue
    if ok != 0:
        ret.append('Not OK')
    else:
        ret.append('OK')
    y=input().split()
for i in ret:
    print(i)

6531312621
# 1678612, 2022-11-12 09:25:25, PPP (100%)

team_country = {}
for i in range(int(input().strip())):
    s = input().strip().split()
    team_country[s[0]] = s[1]

s = input().strip().split()
while s[0] != 'q':
    country = {}
    end = False
    for e in s:
        if e not in team_country:
            print('Not OK')
            end = True
            break
        else:
            country[team_country[e]] = 1
            
    if not end:
        if len(s) == len(country):
            print('OK')
        else:
            print('Not OK')
    s = input().strip().split()

6531315521
# 1678614, 2022-11-12 09:25:43, PPP (100%)

# input : team country

d = {} # {team:country , ...}
for i in range(int(input())):
    t,c = [e.strip() for e in input().split()]
    d[t] = c

while True:
    x = input()
    if x == 'q': break
    x = x.split()
    check = []
    ok = False
    for e in x:
        if e not in d:
            ok = False
            break
        else:
            if d[e] in check:
                ok = False
                break
            else:
                check.append(d[e])
                ok = True
    if ok:
        print('OK')
    else:
        print('Not OK')
        

    


6531316121
# 1678683, 2022-11-12 09:29:28, PPP (100%)

n = int(input())
d = {}
for i in range(n):
     team,coun = input().split()
     d[team] = coun

s = input()
while s != "q":
     l = s.split()
     
     checkd = {}
     c = len(l)
     k = 0
     for e in l:
          if (e not in d):
               print("Not OK")
               break
          elif d[e] in checkd:
               print("Not OK")
               break
          else:
               checkd[d[e]] = 1     
               k += 1
     if c == k:
          print("OK")
     s = input()


6531317821
# 1678630, 2022-11-12 09:26:28, PPP (100%)

country,answer,name = {},[],[]
for n in range(int(input())):
    team,coun = input().split()
    name.append(team)
    if coun not in country:
        country[coun] = [team]
    else:
        country[coun].append(team)
t = input().split()
while t[0] != "q":
    check = False
    g = []
    for team in t:
        for group,teams in country.items():
            if team in name and team in teams and group not in g:
                g.append(group)
            elif team in name and team in teams and group in g:
                answer.append("Not OK")
                check = True
                break   
            elif team not in name:
                answer.append("Not OK")
                check = True
                break
    if not check: 
        answer.append("OK")
    t = input().split()
for e in answer:
    print(e)

6531320621
# 1678658, 2022-11-12 09:28:12, PPP (100%)

n = int(input())
team_coun = dict()
for i in range(n):
    team,coun = input().split()
    team_coun[team] = coun
# print(team_coun)
group = list()
while True:
    g = input().split()
    if g[0] == 'q':
        break
    group.append(g)
# print(group)
for i in range(len(group)):
    check = True
    couns = list()
    for j in range(len(group[i])):
        try:
            if team_coun[group[i][j]] not in couns:
                couns.append(team_coun[group[i][j]])
                # print(couns)
            else:
                print('Not OK')
                check = False
                break
        except:
            print('Not OK')
            check = False
            break
    if check:
        print('OK')

6531322921
# 1678538, 2022-11-12 09:21:16, PPP (100%)

n = int(input())
country = {}
for m in range(n):
    team = input().split()
    country[team[0]] = team[1]
while True:
    x = input()
    if x == 'q':
        break
    group = x.split()
    try:
        check = set([country[g] for g in group])
        if len(check) == len(group):
            print("OK")
        else:
            print("Not OK")
    except:
        print("Not OK")

6531324121
# 1678558, 2022-11-12 09:22:47, PPP (100%)

n = int(input())
teams, country2team, team2country = set(), {}, {}

for _ in range(n):
    team, country = input().split()
    if country not in country2team: country2team[country] = set()
    country2team[country].add(team)
    team2country[team] = country
    teams.add(team)

ans = []
while True:
    s = input()
    if s == "q": break

    queries = s.split()
    countries = set()
    ok = True

    for t in queries:
        if t not in teams: ok = False; break
        home = team2country[t]
        countries.add(home)

    if len(countries) != len(queries): ok = False
    ans.append(ok)

for a in ans:
    if a: print("OK")
    else: print("Not OK")

6531327021
# 1678792, 2022-11-12 09:35:06, PPP (100%)

def check_team(a) :
    s = set()
    for t in a :
        for coun in d :
            if t in d[coun] :
                s.add(coun)
    if len(a) == len(s) :
        return 'OK'
    else :
        return 'Not OK'
    
d = {}
for i in range(int(input())) :
    team, country = input().split()
    if country not in d :
        d[country] = [team]
    else :
        d[country].append(team)

result = []
teams = input().split()
while teams != ['q'] :
    r = check_team(teams)
    result.append(r)
    teams = input().split()

for k in result :
    print(k)

6531331521
# 1678672, 2022-11-12 09:28:45, PPP (100%)

n = int(input())
y = {}
for i in range(n):
    team, country = input().split()
    y[team] = country
x = input().split()
while x[0] != 'q':
    g = set()
    for e in x:
        if e in y:
            g = g | {y[e]}
        else:
            pass
    if len(g) == len(x):
        print('OK')
    else:
        print('Not OK')
    x = input().split()

6531335021
# 1678613, 2022-11-12 09:25:37, PPP (100%)

n = int(input())
Dteam = {}
lstteam = []
for i in range(n) :
    team,city = input().split()
    Dteam[team] = city
    lstteam.append(team)

inp = input()
while inp != "q" :
    temp = []
    check = True
    inp = inp.split()
    for t in inp :
        if t in lstteam :
            if Dteam[t] not in temp :
                temp.append(Dteam[t])
            else :
                print("Not OK")
                check = False
                break
        else :
            print("Not OK")
            check = False
            break
    if check == True :
        print("OK")
    inp = input()





6531339621
# 1678492, 2022-11-12 09:17:21, PPP (100%)

teams = {}  # key is teamName, value is nation

N = int(input())
for i in range(N):
    inStr = input().split()
    teams[inStr[0]] = inStr[1]

q = input()
while(q != 'q'):
    ok = True
    inList = q.split()
    s = set()
    for t in inList:
        if(teams.get(t) == None or teams.get(t) in s):
            ok = False
            break
        else:
            s.add(teams.get(t))
    if(ok):
        print("OK")
    else:
        print("Not OK")
    q = input()


6531341821
# 1678583, 2022-11-12 09:23:49, PPP (100%)

s=int(input())
nation={}
for i in range(s):
    b=input().split()
    nation[b[0]]=b[1]
while True:
    b=input().split()
    if len(b)==1:
        break
    check=[]
    No=0
    for i in b:
        if  i not in nation :
            No=1
        elif nation[i] in check:
            No=1
        else:
            check.append(nation[i])
    if No==1:
        print('Not OK')
    else:
        print('OK')
        


6531342421
# 1678684, 2022-11-12 09:29:30, PPP (100%)

a={}
n = int(input())
for i in range(n):
    x = input().split()
    a[x[0]] = x[1]
    
while(True):
    b={}
    ch=0
    q = input().split()
    if q[0] == 'q':
        break
    for i in q:
        if i not in a:
            print('Not OK')
            ch=1
        if ch == 1:
            break
        if a[i] not in b:
            b[a[i]] = 0
        else:
            print('Not OK')
            ch=1
    if ch==0:
        print('OK')

6531343021
# 1678511, 2022-11-12 09:19:07, PPP (100%)

n = int(input())
teams = dict()
for i in range(n):
    team, nation = input().strip().split()
    teams[team] = nation

while True:
    ok = True
    s = input().strip()
    if s == 'q': break
    s = s.split()
    nations = []
    for team in s:
        if team not in teams:
            ok = False
        elif teams[team] not in nations:
            nations.append(teams[team])
        else:
            ok = False
    if ok:
        print('OK')
    else:
        print('Not OK')

6531344721
# 1678784, 2022-11-12 09:34:48, PPP (100%)

n = int(input())
d = {}
d1 = {}
for i in range(n):
    t, c = input().split()
    d1[t] = c
    if c not in d:
        d[c] = []
    d[c].append(t)

m = input()
while m != "q":
    m1 = m.split()
    d2 = set()
    for e in m1:
        if e not in d1:
            d2 = set()
            break
        elif e in d1:
            d2.add(d1[e])
    if len(d2) != len(m1):
        print("Not OK")
    elif len(d2) == len(m1):
        print("OK")
    m = input()

6531345321
# 1678508, 2022-11-12 09:18:40, PPP (100%)

country = dict()
team = dict()
for i in range(int(input())):
    x = input().split()
    country[x[1]] = x[0]
    team[x[0]] = x[1]


x = input().split()
while x[0] != 'q' :
    temp = set()
    ch = True
    for e in x :
        if e in team :
            temp.add(team[e])
        else :
            ch = False
    if len(temp) == len(x) and ch:
        print("OK")
    else :
        print("Not OK")
    x = input().split()

6531346021
# 1678764, 2022-11-12 09:33:36, PPP (100%)

n=int(input())
d={}
dc={}
for i in range(n):
    l=input().split()
    d[l[0]]=l[1]
    dc[l[1]]=0
while True:
    l=input()
    if l=='q':
        break
    l=l.split()
    ch=True
    dc1=dc.copy()
    for j in l:
        if j not in d:
            print('Not OK')
            ch=False
            break
        
        ct=d[j]
        if dc1[ct]>0:
            print('Not OK')
            ch=False
            break
        dc1[ct]+=1
        #print(ct,dc1[ct])
    if ch:
        print('OK')
    
    

6531347621
# 1678610, 2022-11-12 09:25:25, PPP (100%)

n = int(input())
teamcountry = {} # {liverpool:england}
for xxx in range(n):
    name, country = input().strip().split()
    teamcountry[name] = country

while True:
    stillvalid = True
    checklist = []
    inp = input().strip().split()
    if inp[0] == 'q':break
    for team in inp:
        if team in teamcountry:
            checklist.append(teamcountry[team])
        else:
            print('Not OK')
            stillvalid = False
            break
    if stillvalid:
        countryinset = set()
        for e in checklist:
            if e in countryinset:
                print('Not OK')
                stillvalid = False
                break
            else:
                countryinset.add(e)
        if stillvalid:
            print("OK")




6532011921
# 1678496, 2022-11-12 09:17:37, PPP (100%)

n = int(input())
countries = {}
for _ in range(n):
    team, country = [x.strip() for x in input().split()]
    countries[team] = country

while True:
    s = input()
    if s == 'q':
        break
    l = [x.strip() for x in s.split()]
    found = set()
    ok = True
    for x in l:
        if not x in countries or countries[x] in found:
            ok = False
            break
        found.add(countries[x])
    if ok:
        print('OK')
    else:
        print('Not OK')

6532026321
# 1678500, 2022-11-12 09:17:58, PPP (100%)

d = {}
n = int(input())
for i in range(n):
  c = input().split()
  d[c[0]] = c[1]

s = input().split()
while s[0] != 'q':
  a = []
  for i in s:
    if i not in d.keys():
      print("Not OK")
      break
    if d[i] in a:
      print("Not OK")
      break
    a.append(d[i])
  else:
    print("OK")
  s = input().split()

6532027021
# 1678482, 2022-11-12 09:16:03, PPP (100%)

n = int(input())

teamCountry = {}
for i in range(n) :
    team, country = input().split()
    teamCountry[team] = country

while True :
    teams = input()
    if teams == 'q' :
        break

    teams = teams.split()
    cnt = {}
    notOk = False
    for t in teams :
        if t in teamCountry and teamCountry[t] not in cnt :
            cnt[teamCountry[t]] = 1
        else :
            notOk = True
    
    if notOk == True :
        print('Not OK')
    else :
        print('OK')

6532035021
# 1678521, 2022-11-12 09:20:05, PPP (100%)

d = dict()

n = int(input())
for i in range(n):
    team, nation = input().split()
    d[team] = nation

while True:
    line = input().split()
    if line[0] == 'q':
        break
    try:
        line = [d[x] for x in line]
    except:
        print('Not OK')
        continue
    if len(set(line)) != len(line):
        print('Not OK')
        continue
    print('OK')

6532054921
# 1678515, 2022-11-12 09:19:27, PPP (100%)

n = int(input())
dic = {}
for i in range(n) :
    get_input  = input().split()
    dic[get_input[0]] = get_input[1]
while True :
    get_input = input()
    if get_input == 'q' :
        exit()
    get_input = get_input.split()
    li = []
    not_ok = False
    for i in get_input :
        if(i not in dic) :
            print("Not OK")
            not_ok = True
            break
        if dic[i] in li :
            print("Not OK")
            not_ok = True
            break
        li.append(dic[i])
    if not not_ok :
        print("OK")

6532068721
# 1678553, 2022-11-12 09:22:23, PPP (100%)

n = int(input())

team_to_country = {}

for i in range(n):
    team, country = input().split(" ")
    team_to_country[team] = country

def validate(teams):
    seen = set()
    for team in teams:
        if team not in team_to_country.keys():
            return False

        country = team_to_country[team]
        if country in seen:
            return False
        seen.add(country)

    return True

while True:
    token = input()

    if token == "q":
        break

    teams = token.split(" ")

    if validate(teams):
        print("OK")
    else:
        print("Not OK")


6532082421
# 1678513, 2022-11-12 09:19:19, PPP (100%)

n = int(input())
teams = dict()
for i in range(n):
    n,c = input().split()
    teams[n] = c
lst = input()
while(lst != 'q'):
    team = lst.split()
    group = set()
    valid = True
    for e in team:
        if(not e in teams):
            valid = False
            print("Not OK")
            break
        if(teams[e] in group):
            valid = False
            print("Not OK")
            break
        group.add(teams[e])
    if(valid):
        print('OK')
    lst = input()

6532114921
# 1678535, 2022-11-12 09:21:11, PPP (100%)

team = dict()
for i in range(int(input())):
    name ,country = input().split()
    team[name] = country

while True:
    group = input().split()
    if group == ['q']: break

    ck = True
    for i in range(len(group)):
        for j in range(i+1 ,len(group)):
            if group[i] not in team or group[j] not in team:
                ck = False
                continue
            if team[group[i]] == team[group[j]]:
                ck = False

    if ck: print('OK')
    else: print('Not OK')

6532118421
# 1678495, 2022-11-12 09:17:32, PPP (100%)

n = int(input())
team = dict()

for i in range(n) :
    x = input().strip().split()
    team[x[0]] = x[1]

x = input()
while x!='q' :
    x = x.strip().split()
    o = set()
    check = "OK"
    for v in x :
        if v not in team or team[v] in o :
            check = "Not OK"
            break
        else : o.add(team[v])
    print(check)
    x = input()

6532120621
# 1678490, 2022-11-12 09:17:12, PPP (100%)

n = int(input())
t2c = {}
c2t = {}
for _ in range(n):
    team, country = input().split()
    t2c[team] = country
    if country not in c2t:
        c2t[country] = []
    c2t[country].append(team)

while True:
    raw = input()
    if raw == "q":
        exit()
    used = set()
    valid = True
    for team in raw.split():
        if team not in t2c:
            print("Not OK")
            valid = False
            break

        if t2c[team] in used:
            print("Not OK")
            valid = False
            break
        used.add(t2c[team])
    if valid:
        print("OK")


6532123521
# 1678532, 2022-11-12 09:21:05, PPP (100%)

n = int(input())
dic = {}
for i in range(n):
    team, nation = input().strip().split()
    dic[team] = nation
while True:
    inp = input().strip()
    if(inp == 'q'):
        break
    visited = []
    chk = True
    for x in inp.split():
        if x not in dic or dic[x] in visited:
            chk = False
            break
        else:
            visited.append(dic[x])
    print('OK' if chk else 'Not OK')

6532124121
# 1678578, 2022-11-12 09:23:33, PPP (100%)

n = int(input())
name = []
d = {}
for i in range(n):
    x = input().split()
    if(x[0] not in d):
        d[x[0]] = x[1]
    name.append(x[0])
#print(name)
#print(d)
x = input().split()
while(x[0]!="q"):
    no = False
    se = set()
    for i in x:
        if(i not in name):
            print("Not OK")
            no = True
            break
        se.add(d[i])
    if(len(se)!=len(x) and no ==False):
        print("Not OK")
    elif(no==False):
        print("OK")


    x = input().split()

6532125821
# 1678622, 2022-11-12 09:26:10, PPP (100%)

map = {}

n = int(input())
for i in range(n):
    team, country = input().split()
    map[team] = country

ipt = input()
while ipt != 'q':
    team_list = ipt.split()
    country_set = set()
    for team in team_list:
        if team not in map:
            continue
        country_set = country_set | set([map[team]])
    if(len(country_set) == len(team_list)):
        print('OK')
    else:
        print('Not OK')
    ipt = input()

6532136721
# 1678559, 2022-11-12 09:22:50, PPP (100%)

d = dict()
def valid(s):
    cnt = dict()
    for i in s.split():
        if i not in d:
            return False
        if d[i] in cnt:
            return False
        cnt[d[i]] = 1
    return True

for _ in range(int(input())):
    team, country = input().split()
    d[team] = country

while True:
    s = input()
    if s == 'q':
        break
    print('OK' if valid(s) else 'Not OK')


6532142421
# 1679064, 2022-11-12 09:50:14, PPP (100%)

n = int(input())
Country_Team = {}
for i in range(n):
    team, country = input().strip().split()
    Country_Team[team] = country
#print(Country_Team)

while True:
    s = input().strip()
    if s == 'q': break

    Teams = [s for s in s.split()]
    Countries = []
    for team in Teams:
        if team in Country_Team:
            Countries.append(Country_Team[team])
        else:
            print('Not OK')
            Countries = []
            break
    #print(Countries)
    if Countries != []:
        CountriesUnique = []
        for country in Countries:
            if country not in CountriesUnique:
                CountriesUnique.append(country)
        #print(CountriesUnique)

        if len(Countries) != len(CountriesUnique):
            print('Not OK')
        else:
            print('OK')

6532148221
# 1678556, 2022-11-12 09:22:38, PPP (100%)

N = int(input())

C = {}

for k in range(0, N):
    Name, Country = input().split()
    C[Name] = Country

while True:
    inp = input()
    if inp == 'q': break
    inp = inp.split()
    SetC = set()
    for Country in inp:
        if not Country in C.keys():
            break
        SetC.add(C[Country])
    if len(SetC) != len(inp):
        print("Not OK")
    else:
        print("OK")



6532152721
# 1678516, 2022-11-12 09:19:30, PPP (100%)

n = int(input())

country = dict()

for i in range(n):
    s = input().split()
    country[s[0]] = s[1]

group = input().split()
while (group[0] != "q"):
    ok = True
    visited = []
    for e in group:
        if e not in country or country[e] in visited:
            ok = False
            break
        else:
            visited.append(country[e])

    if ok:
        print("OK")
    else:
        print("Not OK")

    group = input().split()


6532155621
# 1678489, 2022-11-12 09:17:06, PPP (100%)

numTeam = int(input().strip())
teamCoun = {}

for i in range(numTeam):
    raw = input().strip().split()
    teamCoun[raw[0]] = raw[1]

while True:
    raw = input().strip()
    if raw == "q": break

    raw = raw.split()
    ok = True
    countries = set()
    for team in raw:
        if team not in teamCoun:
            ok = False
            break
        countries.add(teamCoun[team])
    
    if len(countries) != len(raw):
        ok = False
    
    if ok: print("OK")
    else: print("Not OK")


6532157921
# 1678552, 2022-11-12 09:22:18, PPP (100%)

n = int(input())
c = {}
for i in range(n):
    a = input().split()
    c[a[0]] = a[1]
while(1):
    a = input()
    if a=='q':
        break
    a = a.split()
    ch = {}
    ans = 1
    for i in range(len(a)):
        if a[i] not in c:
            ans = 0
            break
        if c[a[i]] in ch:
            ans = 0
            break
        ch[c[a[i]]] = 1
    if ans:
        print('OK')
    else:
        print('Not OK')

# 10
# Liverpool England
# ManCity England
# Bayern Germany
# Dortmund Germany
# Barcelona Spain
# Milan Italy
# PSG France
# Ajax Holland
# Real Spain
# Celtic Scotland
# Liverpool Dortmund Milan Ajax
# Liverpool Barcelona PSG Real
# ManCity Milan PSG Ajax Celtic
# ManCity Ajax SamyanFC Real Bayern
# q

6532187721
# 1678485, 2022-11-12 09:16:52, PPP (100%)

n = int(input())
D = {}
for i in range(n):
    a,b = input().split()
    D[a]=b
while True:
    inp = input()
    if inp=='q': break
    l = inp.split()
    check = []
    p = True
    for x in l:
        if x not in D: p = False
        elif D[x] not in check: check.append(D[x])
        else: p = False
    if p: print('OK')
    else: print('Not OK')

6532193421
# 1678527, 2022-11-12 09:20:45, PPP (100%)

n=int(input())
teams={}
for i in range(n):
    team, country=input().split()
    teams[team]=country
while True:
    s=input()
    if s=='q':
        break
    group=s.split()
    countries=set()
    ok=True
    for team in group:
        if team not in teams:
            ok=False
            break
        country=teams[team]
        if country not in countries:
            countries.add(country)
        else:
            ok=False
            break
    if ok:
        print("OK")
    else:
        print("Not OK")

6532201821
# 1679097, 2022-11-12 09:52:21, PPP (100%)

nation={}
anw=[]
d={}
n = int(input())

for i in range(n) :
    a = input().split()
    if a[1] not in d :d[a[1]]=[a[0]]
    else : d[a[1]].append(a[0])
#print(d)
while (True) :
    a = input()
    if a=='q' : break
    a=a.split()
    for i in d : nation[i]=0
    rule=0
    for x in a :
        r=0
        for key in d:
            if x in d[key] : 
                nation[key]+=1;r=1
        if r==0 : anw.append(rule);r=13;break
    if r==13:continue
    rule=1
       
        

    for p in nation : 
        if nation[p] >1 : rule=0
    #print(nation)
    anw.append(rule)#;print('4')
for i in anw : 
    if i==1: print('OK')
    else : print('Not OK')
    




6532203021
# 1678504, 2022-11-12 09:18:13, PPP (100%)

n = int(input())
team = {}

for i in range(n):
    line = input().split()
    name = line[0]
    nation = line[1]
    team[name] = nation

while (True):
    line = input()
    if line == 'q':
        break
    line = line.split()
    ss = set()
    flag = 0
    for i in range(len(line)):
        name = line[i]
        if name in team:
            nation = team[line[i]]
            if nation in ss:
                print("Not OK")
                flag = 1
                break
            ss.add(nation)
        else:
            print("Not OK")
            flag = 1
            break
    if flag == 0:
        print("OK")


6531019821
# 1678688, 2022-11-12 09:29:35, PPP (100%)

n = int(input())
c = 1
l = list()
while c<= n:
    x = input().split()
    l.append(x[0])
    l.append(x[1])
    c+=1
out =[]
while True:
    y = input()
    if y == 'q':
        break
    y = y.split()
    x = []
    for e in y:
        if e in l:
            h = l.index(e)
            u = l[h+1]
            if u not in x:
                x.append(u)
    if len(x) == len(y):
        out.append('OK')
    else:
        out.append('Not OK')
for e in out:
    print(e)

6531801121
# 1678731, 2022-11-12 09:31:35, PPP (100%)

d = dict()
for i in range(int(input().strip())):
    team, nation = input().strip().split()
    d[team] = nation


check = input().strip()
already = list()
is_foul = False
while check != "q":
    temp = check.split()
    already = list()
    is_foul = False
    for team in temp:
        if team not in d:
            is_foul = True
            break
        else:
            if d[team] not in already:
                already.append(d[team])
            else:
                is_foul = True
                break
    if is_foul: print("Not OK")
    else: print("OK")
    check = input().strip()

6531804021
# 1678708, 2022-11-12 09:30:32, PPP (100%)

n=int(input())
fb={}
football=[]
for i in range(n):
    x=input().split()
    if x[1] not in fb:
        fb[x[1]]=[x[0]]
    else:
        fb[x[1]]+=[x[0]]
    football+=[x[0]]    
    
y=input()
while y !="q":
    z=y.split()
    T=True
    p=True
    for k in z:
       if k not in football:
           p=False
    if p==True:       
        for c in fb:
            t=0
            for ch in z:
                for i in range(len(fb[c])):
                        if fb[c][i]==ch:
                            t+=1
                if t>1:
                     T=False
        
        if T==False:
            print("Not OK")
        else:
            print("OK")
    else:
        print("Not OK")
    y=input()    

6531805721
# 1678671, 2022-11-12 09:28:43, PPP (100%)

n = int(input())
country = {}
for i in range(n):
    t,c = input().split()
    if c not in country:
        country[c] = {t}
    else:
        country[c].add(t)


def check_team_country(s):
    for i in country:
        if s in country[i]:
            return i

def check_group(s):
    for i in s:
        try:
            s.remove(i)
            if not s.isdisjoint(country[check_team_country(i)]):
                return False
            s.add(i)
        except:
            return False
    return True

out = []
s = set(input().split())
while len(s) != 1:
    if check_group(s):
        out.append('OK')
    else:
        out.append('Not OK')
    s = set(input().split())

for i in out:
    print(i)

6531806321
# 1678713, 2022-11-12 09:30:41, PPP (100%)

def check(l):
    lc=list()
    for e in l:
        if e!=1:
            lc.append('e')  
    if len(lc)!=0:
        return False
    else:
        return True
i=int(input())
d=dict()
for e in range(i):
    x=[e for e in input().split()]
    d[x[0]]=x[1]
l=list()
while True:
    x=[e for e in input().split()]
    if 'q' in x:
        break
    l.append(x)
lout=list()
for e in l:
    lcomp=list()
    for i in e:
        if i in d.keys():
            lcomp.append(d[i])
        elif i not in d.keys():
            lcomp.append('No')
    lcount=list()
    for e in lcomp:
        lcount.append(lcomp.count(e))
    if 'No' in lcomp:
        lout.append('Not OK')
    elif check(lcount)==False:
        lout.append('Not OK')
    else:
        lout.append('OK')
for e in lout:
    print(e)
    
    


6532186021
# 1678566, 2022-11-12 09:23:12, PPP (100%)

def check(x):
    x = x.split()
    x = [ person_country[person] if person in person_country else False for person in x]
    set_x = set(x)
    if False in set_x:
        return False
    if len(set_x) != len(x):
        return False
    return True

person_country = {}
for i in range(int(input())):
    person,country = input().split()
    person_country[person] = country
while True:
    x = input()
    if x == 'q':
        break
    checking = check(x)
    if checking:
        print('OK')
    else:
        print('Not OK')

Max Score = 67


6430363321
# 1678984, 2022-11-12 09:46:29, --x (0%)

team = {}
for i in range(int(input())):
    t = input().split()
    if t[0] not in team:
        team[t[0]] = t[1]

        
        
check = []
ans = []
while True:
    t = input().split()     
    if t[0] == 'q': break
    
    check.append(t)    
    for i in t:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
            if team[i] not in ans:
                ans.append(team[i])
a = set(ans)
for i in range(3):
    if len(t) != len(a):
        print('Not OK')
    elif len(t) == len(a):
        print('OK')
# 1679355, 2022-11-12 10:06:12, --x (0%)

team = {}
for i in range(int(input())):
    t = input().split()
    if t[0] not in team:
        team[t[0]] = t[1]

        
        
check = []
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    
    check.append(t)
    
    

for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        if team[i[j]] not in ans:
            ans.append(team[i[j]])
    a = set(ans)
        
for i in range(b):
    if len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
# 1679859, 2022-11-12 10:30:30, --x (0%)

team = {}
for i in range(int(input())):
    t = input().split()
    if t[0] not in team:
        team[t[0]] = t[1]

        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        g = i[j]
        ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
# 1679912, 2022-11-12 10:32:23, PPx (67%)

team = {}
for i in range(int(input())):
    t = input().split()
    if t[0] not in team:
        team[t[0]] = t[1]

        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        g = i[j]
        ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []
# 1680355, 2022-11-12 10:53:23, xxx (0%)

team = {}
for i in range(int(input())):
    t = input().split()
    if t[0] not in team:
        team[t[0]] = t[1]

        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        
        g = i[j]
        if g not in team:
            r = team.update({2:'k'})
        else:    
            ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if r == None:
        print('Not OK')
        break
    elif len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []
# 1680407, 2022-11-12 10:54:51, PP- (67%)

team = {}
for i in range(int(input())):
    t = input().split()
    if t[0] not in team:
        team[t[0]] = t[1]

r = False        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        
        g = i[j]
        if g not in team:
            r = True
        else:    
            ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if r == True:
        print('Not OK')
        break
    elif len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []
# 1680426, 2022-11-12 10:55:23, PP- (67%)

team = {}
for i in range(int(input())):
    t = input().split()
    if t[0] not in team:
        team[t[0]] = t[1]

r = False        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        
        g = i[j]
        if g not in team:
            r = True
        else:    
            ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if r == True:
        print('Not OK')
        break
    elif len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []
# 1680683, 2022-11-12 11:05:29, PP- (67%)

team = {}
for i in range(int(input())):
    t = input().split()
    if t[0] not in team:
        team[t[0]] = t[1]

r = False        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        
        g = i[j]
        if g not in team:
            r = True
        else:    
            ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if r == True:
        print('Not OK')
        break
    elif len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []
# 1680865, 2022-11-12 11:12:06, PP- (67%)

team = {}
for i in range(int(input())):
    t = input().strip().split()
    if t[0] not in team:
        team[t[0]] = t[1]

r = False        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        
        g = i[j]
        if g not in team:
            r = True
        else:    
            ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if r == True:
        print('Not OK')
        break
    elif len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []
# 1680975, 2022-11-12 11:15:55, PP- (67%)

team = {}
for i in range(int(input())):
    t = input().strip().split()
    if t[0] not in team:
        team[t[0]] = t[1]

r = False        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        
        g = i[j]
        if g not in team:
            r = True
        else:    
            ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if r == True:
        print('Not OK')
        break
    elif len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []
# 1681138, 2022-11-12 11:19:46, PP- (67%)

team = {}
A = int(input())
if A <= 0:
    print('Not OK')
for i in range(A):
    t = input().strip().split()
    
    if t[0] not in team:
        team[t[0]] = t[1]

r = False        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        
        g = i[j]
        if g not in team:
            r = True
        else:    
            ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if r == True:
        print('Not OK')
        break
    elif len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []
# 1681389, 2022-11-12 11:25:47, PP- (67%)

team = {}
A = int(input())
if A <= 0:
    print('Not OK')
for i in range(A):
    t = input().strip().split()
    
    if t[0] not in team:
        team[t[0]] = t[1]

r = False        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        
        g = i[j]
        if g not in team:
            r = True
        else:    
            ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if r == True:
        print('Not OK')
    elif len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []
# 1681489, 2022-11-12 11:27:37, PP- (67%)

team = {}
A = int(input())
if A <= 0:
    print('Not OK')
for i in range(A):
    t = input().strip().split()
    
    if t[0] not in team:
        team[t[0]] = t[1]

r = False        
check = [] 
ans = []
b = 0
while True:
    t = input().split()     
    if t[0] == 'q': break
    b += 1
    check.append(t)



for i in check:  #i = ['Liverpool', 'Dortmund', 'Milan', 'Ajax']
    for j in range(len(i)):
        
        g = i[j]
        if g not in team:
            r = True
        else:    
            ans.append(team[g])
    a = set(ans)
            
    #for i in range(b):
    if r == True:
        print('Not OK')
    elif len(ans) != len(a):
        print('Not OK')
    elif len(ans) == len(a):
        print('OK')
    a = set()
    check = []
    ans = []

6530065421
# 1678854, 2022-11-12 09:38:14, xxx (0%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)
print(d)
print(t)
c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []
    
    w = True
    for i in y :
        g.append(i)
    for e in g :
        if e not in t :
            print('Not OK')
            ww = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if ww :
            if len(a) == len(b) :
                print('OK')
            else :
                print('Not OK')

# 1678962, 2022-11-12 09:44:43, --- (0%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)
print(d)
print(t)
c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(a) == len(b) :
                if len(a) == len(y) :
                    print('OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().split()
  
    
# 1678978, 2022-11-12 09:46:05, PP- (67%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(a) == len(b) :
                if len(a) == len(y) :
                    print('OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().split()
# 1679012, 2022-11-12 09:47:43, --- (0%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(g) == len(a) :
                if len(a) == len(y) :
                    print('OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().split()
# 1679018, 2022-11-12 09:47:58, --- (0%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(a) == len(g) :
                if len(a) == len(y) :
                    print('OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().split()
# 1679028, 2022-11-12 09:48:10, --- (0%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(y) == len(a) :
                if len(a) == len(y) :
                    print('OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().split()
# 1679087, 2022-11-12 09:51:39, PP- (67%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(a) == len(b) :
                if len(a) == len(g) :
                    print('OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().split()
# 1679099, 2022-11-12 09:52:36, compilation error (0%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(a) != 0
                if len(a) == len(b) :
                    if len(g) == len(a) :
                        print('OK')
                else :
                    print('Not OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().split()
  
# 1679106, 2022-11-12 09:52:57, PP- (67%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(a) != 0 :
                if len(a) == len(b) :
                    if len(g) == len(a) :
                        print('OK')
                else :
                    print('Not OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().split()
# 1679229, 2022-11-12 09:59:29, PP- (67%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().split()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(a) != 0 :
                if len(a) == len(b) :
                    if len(g) == len(a) :
                        print('OK')
                else :
                    print('Not OK')
            #else :
                #print('Not OK')
    a = []
    b =set()
    y =input().split()
# 1679232, 2022-11-12 09:59:45, xxx (0%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().split().strip()
while y[0] != 'q' :
    g = []   
    
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(a) != 0 :
                if len(a) == len(b) :
                    if len(g) == len(a) :
                        print('OK')
                else :
                    print('Not OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().split()
# 1679249, 2022-11-12 10:00:56, PP- (67%)

d = dict()
t = dict()
for i in range(int(input())) :
    x = input().split()
    team,coun = x
    if coun not in d : d[coun] = []
    d[coun].append(team)
    if team not in t : t[team] = []
    t[team].append(coun)

c = dict()
a = []
b = set()
y = input().strip()

while y != 'q' :
    g = []   
    y = y.split()
    for i in y :
        g.append(i)
    for e in g :
        w = True
        if e not in t :
            print('Not OK')
            w = False
        else :
            a.append(t[e])
            b.add(t[e][0])
        if w :
            if len(a) != 0 :
                if len(a) == len(b) :
                    if len(g) == len(a) :
                        print('OK')
                else :
                    print('Not OK')
            else :
                print('Not OK')
    a = []
    b =set()
    y =input().strip()

6530119721
# 1678691, 2022-11-12 09:29:37, --- (0%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g == "q":
    g = input().split()
    
for i in g:
    if i in a:
      pass
    else:
        print("Not ok")
    

# 1678762, 2022-11-12 09:33:35, xxx (0%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g == "q":
    g = input().split()
    
for i in g:
    if i in a:
        if a[i] != a[i+1]:
            print("OK")
    else:
        print("Not OK")
    

# 1678970, 2022-11-12 09:45:04, --- (0%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g == "q":
    g = input().split()
    
for i in g:
    if i in a:
        for j in range(len(g)-1):
            if a[i] != a[i]:
                print("OK")
    else:
        print("Not OK")
  
# 1679267, 2022-11-12 10:01:37, --- (0%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g == "q":
    g = input().split()
check = False
for i in g:
    if i in a:
        for j in g:
            if a[i] == a[j]:
                check = False
            else:
                check = True
if check == True:
    print("OK")
else:
    print("Not OK")
    

# 1679295, 2022-11-12 10:02:37, --- (0%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g == "q":
    g = input().split()
check = False
for i in g:
    if i in a:
        for j in g:
            if a[i] == a[j]:
                check = False
            else:
                check = True
if check == True:
    print("Not OK")
else:
    print("OK")
# 1679694, 2022-11-12 10:23:31, --- (0%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g == "q":
    g = input().split()
check = False
for i in g:
    if i in a:
        b = a.pop(i)
        if b in a.values():
            check = False
            break
        else:
            check = True
    else:
        check = False
if check == True:
    print("OK")
else:
    print("Not OK")
    

# 1679806, 2022-11-12 10:28:39, --- (0%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g[0] != "q":
    check = False
    for i in g:
        if i in a:
            b = a[i]
            if b in a.values():
                check = False
                break
            else:
                check = True
        else:
            check = False
    if check == True:
        print("OK")
    else:
        print("Not OK")
    g = input().split()
    

# 1679914, 2022-11-12 10:32:24, --- (0%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g[0] != "q":
    check = False
    for i in g:
        if i in a:
            b = a[i]
            a.pop(i)
            if b in a.values():
                check = False
                break
            else:
                check = True
        else:
            check = False
    if check == True:
        print("OK")
    else:
        print("Not OK")
    g = input().split()
    

# 1680213, 2022-11-12 10:47:06, --- (0%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g[0] != "q":
    check = False
    for i in g:
        c = a
        if i in a:
            b = c.pop(i)
            if b in c.values():
                check = False
                c = {}
                break
            else:
                check = True
        else:
            check = False
    if check == True:
        print("OK")
    else:
        print("Not OK")
    g = input().split()
    

# 1680769, 2022-11-12 11:08:41, PP- (67%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g[0] != "q":
    check = False
    c = []
    for k in range(len(g)):
        if g[k] in a:
            c.append(a[g[k]])
    for i in g:
        if i in a:
            b = c
            c.remove(a[i])
            if a[i] in c:
                check = False
                c = b
                break
            else:
                check = True
        else:
            check = False
    if check == True:
        print("OK")
    else:
        print("Not OK")
    g = input().split()
    

# 1681179, 2022-11-12 11:20:56, PPx (67%)

n = int(input())
a = {}
for i in range(n):
    name,coun = input().split()
    a[name] = coun

g = input().split()
while g[0] != "q":
    check = False
    c = []
    for k in range(len(g)):
        if g[k] in a:
            c.append(a[g[k]])
        else:
            check = False
            break
    for i in g:
        if i in a:
            b = c
            c.remove(a[i])
            if a[i] in c:
                check = False
                c = b
                break
            else:
                check = True
    if check == True:
        print("OK")
    else:
        print("Not OK")
    g = input().split()
    


6530073421
# 1679415, 2022-11-12 10:09:28, PP- (67%)

n = int(input())
x_d = []
for i in range(n):
    x = input().split()
    x_d.append([x[0],x[1]])
#print(x_d)
team = []
for i in range (len(x_d)):
    team.append(x_d[i][0])
y = input().split()
while y[0] != "q" :
    teamcheck = True
    for b in range (len(y)):
        if y[b] not in team:
            teamcheck = False
    country = []
    for i in range (len(y)):
        for e in range (len(x_d)):
            if y[i] == x_d[e][0]:
                country.append(x_d[e][1])
    country.sort()
    check = True
    for j in range (len(country)-1):
        if country[j] == country[j+1]:
            check = False
        elif country[j] != country[j+1]:
            check = True 
    if check == True and teamcheck == True:
        print("OK")
    else :
        print("Not OK")
    y = input().split()
                
                
# 1679419, 2022-11-12 10:09:59, PP- (67%)

n = int(input())
x_d = []
for i in range(n):
    x = input().split()
    x_d.append([x[0],x[1]])
team = []
for i in range (len(x_d)):
    team.append(x_d[i][0])
y = input().split()
while y[0] != "q" :
    teamcheck = True
    for b in range (len(y)):
        if y[b] not in team:
            teamcheck = False
    country = []
    for i in range (len(y)):
        for e in range (len(x_d)):
            if y[i] == x_d[e][0]:
                country.append(x_d[e][1])
    country.sort()
    check = True
    for j in range (len(country)-1):
        if country[j] == country[j+1]:
            check = False
        elif country[j] != country[j+1]:
            check = True 
    if check == True and teamcheck == True:
        print("OK")
    else :
        print("Not OK")
    y = input().split()
# 1679538, 2022-11-12 10:15:41, PP- (67%)

n = int(input())
x_d = []
for i in range(n):
    x = input().split()
    x_d.append([x[0],x[1]])
#print(x_d)
team = []
for i in range (len(x_d)):
    team.append(x_d[i][0])
y = input().split()
while y[0] != "q" :
    number = True
    if len(y)<= 1:
        number = False
    teamcheck = True
    for b in range (len(y)):
        if y[b] not in team:
            teamcheck = False
    country = []
    for i in range (len(y)):
        for e in range (len(x_d)):
            if y[i] == x_d[e][0]:
                country.append(x_d[e][1])
    country.sort()
    check = True
    for j in range (len(country)-1):
        if country[j] == country[j+1]:
            check = False
        elif country[j] != country[j+1]:
            check = True 
    if check == True and teamcheck == True and number == True:
        print("OK")
    else :
        print("Not OK")
    y = input().split()
                
                
    
    
        
    
    


# 1680793, 2022-11-12 11:09:27, --- (0%)

n = int(input())
x_d = []
for i in range(n):
    x = input().split()
    x_d.append([x[0],x[1]])
#print(x_d)
team = []
for i in range (len(x_d)):
    team.append(x_d[i][0].lower())
y = input().split()
for i in y:
    i = i.lower()
while y[0] != "q" :
    teamcheck = True
    for b in range (len(y)):
        if y[b] not in team:
            teamcheck = False
    country = []
    for i in range (len(y)):
        for e in range (len(x_d)):
            if y[i] == x_d[e][0]:
                country.append(x_d[e][1])
    country.sort()
    check = True
    for j in range (len(country)-1):
        if country[j] == country[j+1]:
            check = False
        elif country[j] != country[j+1]:
            check = True 
    if check == True and teamcheck == True:
        print("OK")
    else :
        print("Not OK")
    y = input().split()
print (country)

                
    
    
        
    
    


# 1680798, 2022-11-12 11:09:39, --- (0%)

n = int(input())
x_d = []
for i in range(n):
    x = input().split()
    x_d.append([x[0],x[1]])
#print(x_d)
team = []
for i in range (len(x_d)):
    team.append(x_d[i][0].lower())
y = input().split()
for i in y:
    i = i.lower()
while y[0] != "q" :
    teamcheck = True
    for b in range (len(y)):
        if y[b] not in team:
            teamcheck = False
    country = []
    for i in range (len(y)):
        for e in range (len(x_d)):
            if y[i] == x_d[e][0]:
                country.append(x_d[e][1])
    country.sort()
    check = True
    for j in range (len(country)-1):
        if country[j] == country[j+1]:
            check = False
        elif country[j] != country[j+1]:
            check = True 
    if check == True and teamcheck == True:
        print("OK")
    else :
        print("Not OK")
    y = input().split()

# 1680801, 2022-11-12 11:09:47, --- (0%)

n = int(input())
x_d = []
for i in range(n):
    x = input().split()
    x_d.append([x[0],x[1]])
#print(x_d)
team = []
for i in range (len(x_d)):
    team.append(x_d[i][0].lower())
y = input().split()
for i in y:
    i = i.lower()
while y[0] != "q" :
    teamcheck = True
    for b in range (len(y)):
        if y[b] not in team:
            teamcheck = False
    country = []
    for i in range (len(y)):
        for e in range (len(x_d)):
            if y[i] == x_d[e][0]:
                country.append(x_d[e][1])
    country.sort()
    check = True
    for j in range (len(country)-1):
        if country[j] == country[j+1]:
            check = False
        elif country[j] != country[j+1]:
            check = True 
    if check == True and teamcheck == True:
        print("OK")
    else :
        print("Not OK")
    y = input().split()
# 1680807, 2022-11-12 11:09:58, --- (0%)

n = int(input())
x_d = []
for i in range(n):
    x = input().split()
    x_d.append([x[0],x[1]])
#print(x_d)
team = []
for i in range (len(x_d)):
    team.append(x_d[i][0].lower())
y = input().split()
for i in y:
    i = i.lower()
while y[0] != "q" :
    teamcheck = True
    for b in range (len(y)):
        if y[b] not in team:
            teamcheck = False
    country = []
    for i in range (len(y)):
        for e in range (len(x_d)):
            if y[i] == x_d[e][0]:
                country.append(x_d[e][1])
    country.sort()
    check = True
    for j in range (len(country)-1):
        if country[j] == country[j+1]:
            check = False
        elif country[j] != country[j+1]:
            check = True 
    if check == True and teamcheck == True:
        print("OK")
    else :
        print("Not OK")
    y = input().split()
# 1680817, 2022-11-12 11:10:18, PP- (67%)

n = int(input())
x_d = []
for i in range(n):
    x = input().split()
    x_d.append([x[0],x[1]])
#print(x_d)
team = []
for i in range (len(x_d)):
    team.append(x_d[i][0])
y = input().split()
while y[0] != "q" :
    number = True
    if len(y)<= 1:
        number = False
    teamcheck = True
    for b in range (len(y)):
        if y[b] not in team:
            teamcheck = False
    country = []
    for i in range (len(y)):
        for e in range (len(x_d)):
            if y[i] == x_d[e][0]:
                country.append(x_d[e][1])
    country.sort()
    check = True
    for j in range (len(country)-1):
        if country[j] == country[j+1]:
            check = False
        elif country[j] != country[j+1]:
            check = True 
    if check == True and teamcheck == True and number == True:
        print("OK")
    else :
        print("Not OK")
    y = input().split()


6530155221
# 1679016, 2022-11-12 09:47:53, --- (0%)

n= int(input())
a = []
b = []
for i in range(n):
    c , d = input().split()
    a.append(c)
    b.append(d)
print(a)
print(b)
# m = input().split()
# q = [e for e in m]
# print(q)
# p = []
# #k = a.index(q)
# #print(k)
# for i in range(len(q)):
#     while q != 'q':
#         k = a.index(q)
#         p.append(b[k])
#         m = input().split()
#         q.append(m)
# p.sort()
q = input()
while q != 'q':
    q = q.split()
    k = []
    for i in range(len(q)):
        if q[i] in a:
            k.append(b[a.index(q[i])])
        else: break
        print('Not OK') 
    k.sort()
    for i in range(len(k)-1):
        if k[i] == k[i+1]:
            print('Not OK')
        else:
            print('OK')
    q = input()
        
    
    

# 1679026, 2022-11-12 09:48:09, --- (0%)

n= int(input())
a = []
b = []
for i in range(n):
    c , d = input().split()
    a.append(c)
    b.append(d)
#print(a)
#print(b)
# m = input().split()
# q = [e for e in m]
# print(q)
# p = []
# #k = a.index(q)
# #print(k)
# for i in range(len(q)):
#     while q != 'q':
#         k = a.index(q)
#         p.append(b[k])
#         m = input().split()
#         q.append(m)
# p.sort()
q = input()
while q != 'q':
    q = q.split()
    k = []
    for i in range(len(q)):
        if q[i] in a:
            k.append(b[a.index(q[i])])
        else: break
        print('Not OK') 
    k.sort()
    for i in range(len(k)-1):
        if k[i] == k[i+1]:
            print('Not OK')
        else:
            print('OK')
    q = input()
# 1679492, 2022-11-12 10:13:17, compilation error (0%)

n= int(input())
a = []
b = []
for i in range(n):
    c , d = input().split()
    a.append(c)
    b.append(d)
print(a)
print(b)
# m = input().split()
# q = [e for e in m]
# print(q)
# p = []
# #k = a.index(q)
# #print(k)
# for i in range(len(q)):
#     while q != 'q':
#         k = a.index(q)
#         p.append(b[k])
#         m = input().split()
#         q.append(m)
# p.sort()
q = input()
while q != 'q':
    q = q.split()
    k = []
    for i in range(len(q)):
        if q[i] in a:
            k.append(b[a.index(q[i])])
            print('OK')
        else: 
        print('Not OK')
    


    q = input()
        
    
    

# 1679497, 2022-11-12 10:13:23, compilation error (0%)

n= int(input())
a = []
b = []
for i in range(n):
    c , d = input().split()
    a.append(c)
    b.append(d)
#print(a)
#print(b)
# m = input().split()
# q = [e for e in m]
# print(q)
# p = []
# #k = a.index(q)
# #print(k)
# for i in range(len(q)):
#     while q != 'q':
#         k = a.index(q)
#         p.append(b[k])
#         m = input().split()
#         q.append(m)
# p.sort()
q = input()
while q != 'q':
    q = q.split()
    k = []
    for i in range(len(q)):
        if q[i] in a:
            k.append(b[a.index(q[i])])
            print('OK')
        else: 
        print('Not OK')
    


    q = input()
# 1679498, 2022-11-12 10:13:27, compilation error (0%)

n= int(input())
a = []
b = []
for i in range(n):
    c , d = input().split()
    a.append(c)
    b.append(d)
#print(a)
#print(b)
# m = input().split()
# q = [e for e in m]
# print(q)
# p = []
# #k = a.index(q)
# #print(k)
# for i in range(len(q)):
#     while q != 'q':
#         k = a.index(q)
#         p.append(b[k])
#         m = input().split()
#         q.append(m)
# p.sort()
q = input()
while q != 'q':
    q = q.split()
    k = []
    for i in range(len(q)):
        if q[i] in a:
            k.append(b[a.index(q[i])])
            print('OK')
        else: 
        print('Not OK')
    


    q = input()
# 1680018, 2022-11-12 10:38:00, xxx (0%)

n= int(input())
a = []
b = []
for i in range(n):
    c , d = input().split()
    a.append(c)
    b.append(d)
#print(a)
#print(b)
# m = input().split()
# q = [e for e in m]
# print(q)
# p = []
# #k = a.index(q)
# #print(k)
# for i in range(len(q)):
#     while q != 'q':
#         k = a.index(q)
#         p.append(b[k])
#         m = input().split()
#         q.append(m)
# p.sort()
q = input()
while q != 'q':
    q = q.split()
    k = []
    for i in range(len(q)):
        if q[i] in a:
            k.append(b[a.index(q[i])])
        else:
            n = 1
    k = k.sort()
    m = 0
    for i in range(len(k)-1):
        if k[i] == k[i+1]:
            m += 1
        else:
            m += 0
    
    if n == 1 and m!= 0:
        print('Not OK')
    else :
        print('OK')
    
    


    q = input()
        
    
    

# 1680191, 2022-11-12 10:45:43, PP- (67%)

n= int(input())
a = []
b = []
for i in range(n):
    c , d = input().split()
    a.append(c)
    b.append(d)
#print(a)
#print(b)
# m = input().split()
# q = [e for e in m]
# print(q)
# p = []
# #k = a.index(q)
# #print(k)
# for i in range(len(q)):
#     while q != 'q':
#         k = a.index(q)
#         p.append(b[k])
#         m = input().split()
#         q.append(m)
# p.sort()
q = input()
while q != 'q':
    q = q.split()
    k = []
    for i in range(len(q)):
        if q[i] in a:
            k.append(b[a.index(q[i])])
        else:
            n = 1
    #print(k)
    k.sort()
    #print(k)
    m = 0
    for i in range(len(k)-1):
        if k[i] == k[i+1]:
            m += 1
        else:
            m += 0
    #print(m)
    
    if n == 1 or m!= 0:
        print('Not OK')
    else :
        print('OK')
    
    


    q = input()
        
    
    


6530055121
# 1678620, 2022-11-12 09:26:04, Txx (0%)

n = int(input())
d = {}
for i in range(n):
    x, y = input().split()
    if y not in d:
        d[y] = {x}
    else:
        d[y].add(x)
p = input().split()
while p != "q":
    c = set()
    for i in range(len(p)-1):
        c.add(x[i])
        for j in range(i+1, len(p)):
            c.add(x[j])
        for v in d.values():
            if c <= v:
                print("Not OK")
            else:
                print("OK")
                
# 1678634, 2022-11-12 09:26:53, xxx (0%)

n = int(input())
d = {}
for i in range(n):
    x, y = input().split()
    if y not in d:
        d[y] = {x}
    else:
        d[y].add(x)
p = input().split()
while p != "q":
    c = set()
    for i in range(len(p)-1):
        c.add(x[i])
        for j in range(i+1, len(p)):
            c.add(x[j])
        for v in d.values():
            if c <= v:
                print("Not OK")
            else:
                print("OK")
    p = input().split()
                
# 1679326, 2022-11-12 10:04:25, --- (0%)

n = int(input())
d = {}
for i in range(n):
    x, y = input().split()
    if y not in d:
        d[y] = {x}
    else:
        d[y].add(x)
p = input()
out = []
while p != "q":
    c = 0
    for i in range(len(p)-1):
        for j in range(i+1,len(p)):
            s = set()
            s.add(p[i])
            s.add(p[j])
            for v in d.values():
                if s <= v:
                    c += 1
                else:
                    c += 0
    if c == 0:
        out.append("OK")
    else:
        out.append("Not OK")            
    p = input()
print(out)
for i in range(len(out)):
    print(out[i])
# 1679471, 2022-11-12 10:12:27, PP- (67%)

n = int(input())
d = {}
for i in range(n):
    x, y = input().split()
    if y not in d:
        d[y] = {x}
    else:
        d[y].add(x)
p = input()
out = []
while p != "q":
    c = 0
    p = set(p.split())
    for v in d.values():
        if len(p & v) <= 1:
            c += 0
        else:
            c += 1
    if c == 0:
        out.append("OK")
    else:
        out.append("Not OK")
    p = input()

for i in range(len(out)):
    print(out[i])
# 1681166, 2022-11-12 11:20:39, xxx (0%)

n = int(input())
ctry_team = {}
for i in range(n):
    t, c = input().split()
    if c not in ctry_team:
        ctry_team[c] = {t}
    else:
        ctry_team[c].add(t)

p = input()
while p != "q":
    p = set(p.split())
    c = 0
    for v in ctry_team.values():
        if len(p & v) == 1:
            c += 1
    if c == len(p):
        print("OK")
    else:
        print("Not OK")
# 1681192, 2022-11-12 11:21:09, PP- (67%)

n = int(input())
d = {}
for i in range(n):
    x, y = input().split()
    if y not in d:
        d[y] = {x}
    else:
        d[y].add(x)
p = input()
out = []
while p != "q":
    c = 0
    p = set(p.split())
    for v in d.values():
        if len(p & v) <= 1:
            c += 0
        else:
            c += 1
    if c == 0:
        out.append("OK")
    else:
        out.append("Not OK")
    p = input()

for i in range(len(out)):
    print(out[i])

6530106521
# 1678580, 2022-11-12 09:23:42, xxx (0%)

listteam = {}
for i in range(int(input())):
    team,country = input().split()
    listteam[team] = country
x = input()
while x != 'q':
    x = x.split()
    for i in range(len(x)):
        if x[i] not in listteam:
            print('Not OK')
            break
        else:
            setteam = set()
            setteam.add(listteeam[x[i]])
    if len(setteam) != len(x):
        print('Not OK')
    else:
        print('OK')
    x = input()
    

# 1678675, 2022-11-12 09:28:49, PP- (67%)

listteam = {}
for i in range(int(input())):
    team,country = input().split()
    listteam[team] = country
x = input()
inlist = True
while x != 'q':
    x = x.split()
    setteam = set()
    for i in range(len(x)):
        if x[i] not in listteam:
            print('Not OK')
            inlist = False
            break
        else:
            setteam.add(listteam[x[i]])
    if inlist != False:
        if len(setteam) != len(x):
            print('Not OK')
        else:
            print('OK')
    x = input()
    

# 1678753, 2022-11-12 09:32:40, PP- (67%)

listteam = {}
for i in range(int(input())):
    team,country = input().split()
    listteam[team] = country
x = input()
inlist = True
while x != 'q':
    x = x.split()
    setteam = set()
    for i in range(len(x)):
        if x[i] not in listteam:
            print('Not OK')
            inlist = False
            break
        else:
            setteam.add(listteam[x[i]])
    if inlist:
        if len(setteam) != len(x):
            print('Not OK')
        else:
            print('OK')
    x = input()
    

# 1679468, 2022-11-12 10:12:15, PP- (67%)

listteam = {}
for i in range(int(input())):
    team,country = input().split()
    listteam[team] = country
x = input()
inlist = True
while x != 'q':
    x = x.split()
    setteam = set()
    for i in range(len(x)):
        if x[i] not in listteam:
            inlist = False
            print('Not OK')
            break
        else:
            setteam.add(listteam[x[i]])
    if inlist:
        if len(setteam) != len(x):
            print('Not OK')
        else:
            print('OK')
    x = input()

# 1679581, 2022-11-12 10:18:30, PP- (67%)

listteam = {}
for i in range(int(input())):
    team,country = input().split()
    listteam[team] = country
x = input()
inlist = True
while x != 'q':
    x = x.split()
    setteam = set()
    x1 = []
    for i in range(len(x)):
        if x[i] not in listteam:
            inlist = False
            print('Not OK')
            break
        else:
            setteam.add(listteam[x[i]])
            x1.append(x[i])
    if inlist:
        if len(setteam) != len(x1):
            print('Not OK')
        else:
            print('OK')
    x = input()

# 1681315, 2022-11-12 11:24:08, PP- (67%)

listteam = {}
for i in range(int(input())):
    team,country = input().split()
    listteam[team] = country
x = input()
inlist = True
while x != 'q':
    c = []
    x = x.split()
    for i in range(len(x)):
        if x[i] not in listteam:
            inlist = False
            print('Not OK')
            break
        else:
            c.append(listteam[x[i]])
    if inlist:
        c.sort()
        same = []
        for e in range(len(c)-1):
            if c[e] == c[e+1]:
                same.append(c[e])
        if len(same) > 0:
            print('Not OK')
        else:
            print('OK')
    x = input()
                


6431507621
# 1680958, 2022-11-12 11:15:29, xxx (0%)

d = {}
n = int(input())
for i in range(n):
    team,country = input().split()
    if country not in d:
        d[team] = []
    d[team].append(country)


x = input()
n = 0
while x != 'q':
    y = [e.strip() for e in x.split()]
    u = []
    for i in range(len(y)-1):
        for j in range (i+1,len(y)):
            if y[j] not in d:
                
                u.append('Not OK')
                
            elif y[i] in d:
                if d[y[i]] == d[y[j]]:
                    u.append('Not OK')
                elif d[y[i]] != d[y[j]]:
                    
                    u.append('OK')
    
    n += 1
    x = input()
                
found = True              
for i in range(n):
    
    if u[i] == 'Not OK':
        print('Not OK')
    elif u[i] == 'OK':
        print('OK')

    

 


# 1681293, 2022-11-12 11:23:49, PP- (67%)

d = {}
n = int(input())
for i in range(n):
    team,country = input().split()
    if country not in d:
        d[team] = []
    d[team].append(country)


x = input()
n = 0
while x != 'q':
    y = [e.strip() for e in x.split()]
    u = []
    for i in range(len(y)-1):
        for j in range (i+1,len(y)):
            if y[j] not in d:
                
                u.append('Not OK')
                
            elif y[i] in d:
                if d[y[i]] == d[y[j]]:
                    u.append('Not OK')
                elif d[y[i]] != d[y[j]]:
                    
                    u.append('OK')
    
    u.sort()
    
    if u[0] == 'Not OK':
        print('Not OK')
    elif u[0] == 'OK':
        print('OK')

    x = input()

 


# 1681340, 2022-11-12 11:24:49, PP- (67%)

d = {}
n = int(input())
for i in range(n):
    team,country = input().split()
    if country not in d:
        d[team] = []
    d[team].append(country)


x = input()
n = 0
while x != 'q':
    y = [e.strip() for e in x.split()]
    u = []
    for i in range(len(y)-1):
        for j in range (i+1,len(y)):
            if y[j] not in d:
                
                u.append('Not OK')
                
            elif y[i] in d:
                if d[y[i]] == d[y[j]]:
                    u.append('Not OK')
                elif d[y[i]] != d[y[j]]:
                    
                    u.append('OK')
    
    u.sort()
    
    if u[0] == 'Not OK':
        print('Not OK')
    else:
        print('OK')

    x = input()

 


# 1681393, 2022-11-12 11:25:52, PP- (67%)

d = {}
n = int(input())
for i in range(n):
    team,country = input().split()
    if country not in d:
        d[team] = []
    d[team].append(country)


x = input()
n = 0
while x != 'q':
    y = [e.strip() for e in x.split()]
    u = []
    for i in range(len(y)-1):
        for j in range (i+1,len(y)):
            if y[j] not in d:
                
                u.append('Not OK')
                
            elif y[i] in d:
                if d[y[i]] == d[y[j]]:
                    u.append('Not OK')
                elif d[y[i]] != d[y[j]]:
                    
                    u.append('OK')
    
    u.sort()
    
    if u[0] == 'OK':
        print('OK')
    else:
        print('Not OK')

    x = input()

 


# 1681522, 2022-11-12 11:28:16, PP- (67%)

d = {}
n = int(input())
for i in range(n):
    team,country = input().split()
    if country not in d:
        d[team] = []
    d[team].append(country)


x = input()
n = 0
while x != 'q':
    y = [e.strip() for e in x.split()]
    u = []
    for i in range(len(y)-1):
        for j in range (i+1,len(y)):
            if y[j] not in d:
                
                u.append('Not OK')
                
            elif y[i] in d:
                if d[y[i]] == d[y[j]]:
                    u.append('Not OK')
                elif d[y[i]] != d[y[j]]:
                    
                    u.append('OK')
    
    u.sort()
    
    if u[0] == 'OK':
        print('OK')
    else:
        print('Not OK')

    x = input()

6530193021
# 1678990, 2022-11-12 09:46:43, --- (0%)


# a = {}
# for i in range(int(input())) :
#     name,con = input().split()
#     a[name] = con

a = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany', 'Dortmund': 'Germany', 'Barcelona': 'Spain', 'Milan': 'Italy', 'PSG': 'France', 'Ajax': 'Holland', 'Real': 'Spain', 'Celtic': 'Scotland'}

c = []
d = set()
fi = []
while True :
    b = input()
    if b != 'q' :
        b = b.split()
        for ch in b :
            for e in a :
                if e == ch :
                    c.append(a[e])
                    d.add(a[e])
                if ch not in a :
                    break
                    print('Not OK')
        if len(c) != len(d) or len(c) == 0 :
            fi.append('Not OK')
        else :
            fi.append('OK')
        c = []
        d = set()        
    else :
        break
print('\n'.join(fi))
                    
        
        

# 1679123, 2022-11-12 09:53:42, --- (0%)


a = {}
for i in range(int(input())) :
    name,con = input().split()
    a[name] = con


c = []
d = set()
fi = []
while True :
    b = input()
    if b != 'q' :
        b = b.split()
        for ch in b :
            for e in a :
                if e == ch :
                    c.append(a[e])
                    d.add(a[e])
                if ch not in a :
                    fi.append('Not OK')
                    break
        if len(c) != len(d) or len(c) == 0 :
            fi.append('Not OK')
        else :
            fi.append('OK')
        c = []
        d = set()        
    else :
        break
fi = fi[:-1]
print('\n'.join(fi))
                    
        
        

# 1679196, 2022-11-12 09:57:34, --- (0%)


a = {}
for i in range(int(input())) :
    name,con = input().split()
    a[name] = con

a = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany', 'Dortmund': 'Germany', 'Barcelona': 'Spain', 'Milan': 'Italy', 'PSG': 'France', 'Ajax': 'Holland', 'Real': 'Spain', 'Celtic': 'Scotland'}

c = []
d = set()
fi = []
f = []
while True :
    b = input()
    f.append(b)
    if b != 'q' :
        b = b.split()
        for ch in b :
            for e in a :
                if e == ch :
                    c.append(a[e])
                    d.add(a[e])
                if ch not in a :
                    fi.append('Not OK')
                    break
        if len(c) != len(d) or len(c) == 0 :
            fi.append('Not OK')
        else :
            fi.append('OK')
        c = []
        d = set()        
    else :
        break
fi = fi[:len(f)-1]
print('\n'.join(fi))
                    
        
        

# 1679235, 2022-11-12 09:59:57, PP- (67%)


a = {}
for i in range(int(input())) :
    name,con = input().split()
    a[name] = con

c = []
d = set()
fi = []
f = []
while True :
    b = input()
    f.append(b)
    if b != 'q' :
        b = b.split()
        for ch in b :
            for e in a :
                if e == ch :
                    c.append(a[e])
                    d.add(a[e])
                if ch not in a :
                    fi.append('Not OK')
                    break
        if len(c) != len(d) or len(c) == 0 :
            fi.append('Not OK')
        else :
            fi.append('OK')
        c = []
        d = set()        
    else :
        break
fi = fi[:len(f)-1]
print('\n'.join(fi))
                    
        
        

# 1679263, 2022-11-12 10:01:22, PP- (67%)


a = {}
for i in range(int(input())) :
    name,con = input().strip().split()
    a[name] = con

c = []
d = set()
fi = []
f = []
while True :
    b = input()
    f.append(b)
    if b != 'q' :
        b = b.strip().split()
        for ch in b :
            for e in a :
                if e == ch :
                    c.append(a[e])
                    d.add(a[e])
                if ch not in a :
                    fi.append('Not OK')
                    break
        if len(c) != len(d) or len(c) == 0 :
            fi.append('Not OK')
        else :
            fi.append('OK')
        c = []
        d = set()        
    else :
        break
fi = fi[:len(f)-1]
print('\n'.join(fi))
                    
        
        


6531301721
# 1678737, 2022-11-12 09:31:55, PP- (67%)

n = int(input())
All = []
for i in range(n):
    inp = input().split()
    indicator = 0
    for j in range(len(All)):
        if inp[1] == All[j][0]:
            indicator = 1
            index = j
            break
    if indicator == 0:
        All.append([inp[1], [inp[0]]])
    elif indicator == 1:
        All[index][1].append(inp[0])
All2 = []
while True:
    inp2 = input()
    if inp2 == 'q':
        break
    else:
        inp3 = inp2.split()
        All2.append(inp3)
for i in range(len(All2)):
    for j in range(len(All)):
        indicator2 = 0
        for k in range(len(All[j][1])):
             if All[j][1][k] in All2[i]:
                 indicator2 += 1
        if indicator2 >= 2:
            print('Not OK')
            break
    if indicator2 < 2:
        print('OK')        

# 1678850, 2022-11-12 09:38:03, PP- (67%)

n = int(input())
All = []
for i in range(n):
    inp = input().split()
    indicator = 0
    for j in range(len(All)):
        if inp[1] == All[j][0]:
            indicator = 1
            index = j
            break
    if indicator == 0:
        All.append([inp[1], [inp[0]]])
    elif indicator == 1:
        All[index][1].append(inp[0])
All2 = []
while True:
    inp2 = input()
    if inp2 == 'q':
        break
    else:
        inp3 = inp2.split()
        All2.append(inp3)
for i in range(len(All2)):
    indicator3 = 0
    for j in range(len(All)):
        indicator2 = 0
        for k in range(len(All[j][1])):
             if All[j][1][k] in All2[i]:
                 indicator2 += 1
        if indicator2 >= 2:
            indicator3 = 1
            print('Not OK')
            break
    if indicator3 == 0:
        print('OK')       
# 1679741, 2022-11-12 10:25:15, xxx (0%)

n = int(input())
All = {}
for i in range(n):
    inp = input().split()
    All.update({inp[0]:inp[1]})
T = []
while True:
    inp2 = input()
    if inp2 == 'q':
        break
    else:
        inp3 = inp2.split()
        T.append(inp3)
for i in range(len(T)):
    ind = 0
    for j in range(len(T)-1-i):
        if All[T[i]] == All[T[i+1+j]]:
            ind = 1
            print('Not OK')
            break
    if ind == 0:
        print('OK')

# 1679792, 2022-11-12 10:28:09, xxx (0%)

n = int(input())
All = {}
for i in range(n):
    inp = input().split()
    All.update({inp[0]:inp[1]})
T = []
while True:
    inp2 = input()
    if inp2 == 'q':
        break
    else:
        inp3 = inp2.split()
        T.append(inp3)
for i in range(len(T)):
    ind = 0
    for j in range(len(T[i])):
        ind2 = 0
        for j in range(len(T)-1-i):
            if All[T[i]] == All[T[i+1+j]]:
                ind = 1
                ind2 = 1
                print('Not OK')
                break
        if ind2 == 1:
            break
    if ind == 0:
        print('OK')

# 1679837, 2022-11-12 10:29:51, PPx (67%)

n = int(input())
All = {}
for i in range(n):
    inp = input().split()
    All.update({inp[0]:inp[1]})
T = []
while True:
    inp2 = input()
    if inp2 == 'q':
        break
    else:
        inp3 = inp2.split()
        T.append(inp3)
for i in range(len(T)):
    ind = 0
    for j in range(len(T[i])):
        ind2 = 0
        for k in range(len(T[i])-1-j):
            if All[T[i][j]] == All[T[i][j+1+k]]:
                ind = 1
                ind2 = 1
                print('Not OK')
                break
        if ind2 == 1:
            break
    if ind == 0:
        print('OK')


6430115021
# 1679591, 2022-11-12 10:19:04, --x (0%)

n = int(input())
i = 0
From = {}

while i < n :
    team, country = input().split()
    From[team] = country
    i += 1


x = input().split()

while x != ['q'] :
    ans = 'OK'
    for i in range(len(x)-1):
        if x[i] not in From :
            ans = "Not Ok"
            x.remove(x[i])
    for e in range(len(x)-1):
        n = 1
        while n+e != len(x):
            if From[x[e]] == From[x[e+n]]:
                ans = "Not Ok"
            n += 1
                
    print(ans)       
    x = input().split()    
    
    
# 1679607, 2022-11-12 10:20:07, PPx (67%)

n = int(input())
i = 0
From = {}

while i < n :
    team, country = input().split()
    From[team] = country
    i += 1


x = input().split()

while x != ['q'] :
    ans = 'OK'
    for i in range(len(x)-1):
        if x[i] not in From :
            ans = "Not OK"
            x.remove(x[i])
    for e in range(len(x)-1):
        n = 1
        while n+e != len(x):
            if From[x[e]] == From[x[e+n]]:
                ans = "Not OK"
            n += 1
                
    print(ans)       
    x = input().split()    
    
# 1679699, 2022-11-12 10:23:36, PPx (67%)

n = int(input())
i = 0
From = {}

while i < n :
    team, country = input().split()
    From[team] = country
    i += 1


x = input().split()

while x != ['q'] :
    ans = 'OK'
    for i in range(len(x)):
        if x[i] not in From :
            ans = "Not OK"
            x.remove(x[i])
    for e in range(len(x)-1):
        n = 1
        while n+e != len(x):
            if From[x[e]] == From[x[e+n]]:
                ans = "Not OK"
            n += 1
                
    print(ans)       
    x = input().split()
# 1681496, 2022-11-12 11:27:42, PPx (67%)

n = int(input())
i = 0
From = {}

while i < n :
    team, country = input().split()
    From[team] = country
    i += 1


x = input().split()

while x != ['q'] :
    ans = 'OK'
    for i in range(len(x)-1):
        if x[i] not in From :
            ans = "Not OK"
            x.remove(x[i])
    for e in range(len(x)-1):
        n = 1
        while n+e != len(x):
            if From[x[e]] == From[x[e+n]]:
                ans = "Not OK"
            n += 1
                
    print(ans)       
    x = input().split()

6530195321
# 1679305, 2022-11-12 10:03:20, PP- (67%)

#ทำได้อิหยิง สุ้ ใจเย็น สุ้สุ้สุ้สสุส้สสุส้สสุส้ส
num = int(input()) #10
dict_ = {}
for i in range(num):
    team, country = input().split()
    dict_[team] = country                    #team: coun
    
NOT_OKAY = False
while True:
    x = input()   #Liverpool Dortmund Milan Ajax
    if x == 'q':
        break
    x = x.split()
    ccc = []
    for e in x:
        if e not in dict_:
            print("Not OK")          #ไม่รู้มาจากปะเื่ดไร
            NOT_OKAY = True
            break
        else:
            ccc.append(dict_[e])    #[country. country]
    result_dict = {}
    for e in ccc:
        if e not in result_dict:
            result_dict[e] = 0
        result_dict[e] += 1
    c =0
    
    if NOT_OKAY == True:
        pass
    else:
        for v in result_dict.values():
            if v > 1:
                print("Not OK")
                break
            else:
                c +=1

        if c == len(ccc):
            print("OK")
# 1681111, 2022-11-12 11:19:16, PP- (67%)

#ทำได้อิหยิง สุ้ ใจเย็น สุ้สุ้สุ้สสุส้สสุส้สสุส้ส
num = int(input()) #10
dict_ = {}
for i in range(num):
    team, country = input().split()
    dict_[team] = country                    #team: coun
    
NOT_OKAY = False
while True:
    x = input()   #Liverpool Dortmund Milan Ajax
    if x == 'q':
        break
    x = x.split()
    x = set(x)
    ccc = []
    for e in x:
        if e not in dict_:
            print("Not OK")          #ไม่รู้มาจากปะเื่ดไร
            NOT_OKAY = True
            break
        else:
            ccc.append(dict_[e])    #[country. country]
    result_dict = {}
    for e in ccc:
        if e not in result_dict:
            result_dict[e] = 0
        result_dict[e] += 1
    c =0
    
    if NOT_OKAY == True:
        pass
    else:
        for v in result_dict.values():
            if v > 1:
                print("Not OK")
                break
            else:
                c +=1

        if c == len(ccc):
            print("OK")
# 1681362, 2022-11-12 11:25:16, PP- (67%)

#ทำได้อิหยิง สุ้ ใจเย็น สุ้สุ้สุ้สสุส้สสุส้สสุส้ส
num = int(input()) #10
dict_ = {}
for i in range(num):
    team, country = input().split()
    dict_[team.strip()] = country.strip()                    #team: coun
    
NOT_OKAY = False
while True:
    x = input()   #Liverpool Dortmund Milan Ajax
    if x == 'q':
        break
    x = x.split()
    x = set([e.strip() for e in x])
    ccc = []
    for e in x:
        if e not in dict_:
            print("Not OK")          #ไม่รู้มาจากปะเื่ดไร
            NOT_OKAY = True
            break
        else:
            ccc.append(dict_[e])    #[country. country]
    result_dict = {}
    for e in ccc:
        if e not in result_dict:
            result_dict[e] = 0
        result_dict[e] += 1
    c =0
    
    if NOT_OKAY == True:
        pass
    else:
        for v in result_dict.values():
            if v > 1:
                print("Not OK")
                break
            else:
                c +=1

        if c == len(ccc):
            print("OK")

6231417621
# 1679625, 2022-11-12 10:20:56, --- (0%)

d={}#{ประเทศ:team,team}
for i in range(int(input())):
    x=input().strip()
    if x =='q':break
    team,city = x.split()
    if city not in d:
        d[city]=[]
    d[city].append(team)
#(d){'England': ['Liverpool', 'ManCity'],
while True:
    x=input().strip()
    if x=='q':break
    line=x.split()#line=Liverpool Dortmund Milan Ajax
    lcity=[]
    for i in line:
       for k,v in d.items():
           if i in v:
               lcity.append(k)
    x=set(lcity)
    if len(x)!=len(i):
        print('Not OK')
    else: print('OK')


# 1679722, 2022-11-12 10:24:29, PP- (67%)

d={}#{ประเทศ:team,team}
for i in range(int(input())):
    x=input().strip()
    if x =='q':break
    team,city = x.split()
    if city not in d:
        d[city]=[]
    d[city].append(team)
#(d){'England': ['Liverpool', 'ManCity'],
out=[]
while True:
    x=input().strip()
    if x=='q':break
    line=x.split()#line=Liverpool Dortmund Milan Ajax
    lcity=[]
    for i in line:
       for k,v in d.items():
           if i in v:
               lcity.append(k)
    out.append(lcity)
for i in out:
    x=set(i)
    if len(x)!=len(i):
        print('Not OK')
    else: print('OK')



6331112221
# 1679214, 2022-11-12 09:58:45, -P- (33%)

x = int(input())
out = {}

for i in range(x):
    t,c = input().split()
    out[t] = c
    

y = []
c = 0

while True:
    
    check = input().split()
    if check[0] == "q":
        break
    for e in check:
        if e in out and out[e] not in y:
            y.append(out[e])
            c += 0
        else:
            c += 1
        if e not in out:
            print("Not OK")
            break
        if c >= 1:
            print("Not OK")
            break
        elif c == 0:
            print("OK")
            break
# 1680850, 2022-11-12 11:11:23, PP- (67%)

x = int(input())
out = {}

for i in range(x):
    t,c = input().split()
    out[t] = c
    




y = {}
while True:
    
    check = input().split()
    if check[0] == "q":
        break
    for e in check:
        if e not in out:
            print("Not OK")
            break
        if out[e] not in y:
            y[out[e]] = 0
        y[out[e]] += 1
        
        
    for h in y:
        if y[h] > 1:
            print("Not OK")
            break
    else:
        print("OK")
        
    y = {}
    

6431418421
# 1680569, 2022-11-12 11:02:04, --- (0%)

c={}
allteam=[]

for i in range(int(input())):
    t,s =str(input()).split()
    if s not in c:
        c[s]=[t]
    else:
        c[s].append(t)
    allteam.append(t)
print(c)
cc=[]
while True:
    x=str(input())
    if x =='q':
        break
    z=x.split()
    cc.append(z)
ans=[]
for i in cc:
    ans.append(i)
for i in cc:
    for e in range(len(i)):
        if i[e] not in allteam:
            ans.append('Not OK')
            cc.remove(i)
            ans.remove(i)
for i in cc:
    for e in range(len(i)):
        for a in c:
            if i[e] in c[a]:
                i[e]=a
for i in cc:
    for e in range(len(i)):
        w=e+1
        if w >len(i):
            w=e
        if i[e] in i[w:]:
            i[e] = 'Not OK'
        else:
            i[e] ='OK'
anss=[]
for i in ans:
    if 'Not OK' in i:
        anss.append('Not OK')
    else:
        anss.append('OK')
for i in anss:
    print(i)
# 1680634, 2022-11-12 11:04:04, PP- (67%)

c={}
allteam=[]

for i in range(int(input())):
    t,s =str(input()).split()
    if s not in c:
        c[s]=[t]
    else:
        c[s].append(t)
    allteam.append(t)
cc=[]
while True:
    x=str(input())
    if x =='q':
        break
    z=x.split()
    cc.append(z)
ans=[]
for i in cc:
    ans.append(i)
for i in cc:
    for e in range(len(i)):
        if i[e] not in allteam:
            ans.append('Not OK')
            cc.remove(i)
            ans.remove(i)
for i in cc:
    for e in range(len(i)):
        for a in c:
            if i[e] in c[a]:
                i[e]=a
for i in cc:
    for e in range(len(i)):
        w=e+1
        if w >len(i):
            w=e
        if i[e] in i[w:]:
            i[e] = 'Not OK'
        else:
            i[e] ='OK'
anss=[]
for i in ans:
    if 'Not OK' in i:
        anss.append('Not OK')
    else:
        anss.append('OK')
for i in anss:
    print(i)

6430450221
# 1679495, 2022-11-12 10:13:23, --- (0%)

n=int(input())
have={}
for i in range(n):
    n,c=input().split()
    have[n]=c
have2={}
for e in have:
    v=have[e]
    have2[v]=e
find=input()
new1=[]
while find!='q':
    k=find.split()
    for e in k:
        if e not in have:
            print('Not OK')
            z=False
            break
        else:
            new1.append(have[e])
            z=True
    new2=set(new1)
    new=[]
    for e in new2:
        new.append(e)   
    if z==True and len(new)!=0:
        for i in range(len(new)-1):
            if new[i]==new[i+1]:
                print('Not OK')
                p=False
                break
            else:
                p=True
        if p==True:
            print('OK')
    find=input()
print(new)
# 1679967, 2022-11-12 10:35:34, PP- (67%)

n=int(input())
have={}
for i in range(n):
    n,c=input().split()
    have[n]=c
have2={}
for e in have:
    v=have[e]
    have2[v]=e
find=input()
new=[]
while find!='q':
    k=find.split()
    for e in k:
        if e not in have:
            print('Not OK')
            z=False
            break
        else:
            new.append(have[e])
            z=True   
    if z==True and len(new)!=0:
        x=new[0]
        for i in range(1,len(new)):
            if new[i]==x:
                print('Not OK')
                p=False
                x=new[i]
                break
            else:
                p=True
                x=new[i]
        if p==True:
            print('OK')
    new=[]
    find=input()

6530138621
# 1678963, 2022-11-12 09:44:47, PP- (67%)

x = int(input())
country = {}
for i in range(x):
    [name,region] = input().split()
    if region not in country:
        country[region] = [name]
    else:
        country[region].append(name)
#-----------------------------
x = input()
answer = []
while  x != 'q':
    point = {}
    team = x.split()
    for k in country:
        for j in team:
            if j in country[k]:
                if k not in point:
                    point[k] = 1
                else:
                    point[k] += 1
    answer.append(point)
    x = input()
#---------------------------
for l in answer:
    u = True
    for k in l:
        if l[k] > 1:
            print('Not OK')
            u = False
    if u == True:
        print('OK')
# 1681679, 2022-11-12 11:30:17, --- (0%)

x = int(input())
country = {}
legend = []
for i in range(x):
    [name,region] = input().split()
    legend.append(name)
    if region not in country:
        country[region] = [name]
    else:
        country[region].append(name)
#-----------------------------
x = input()
answer = []
while  x != 'q':
    point = {}
    team = x.split()
    for k in country:
        for j in team:
            if j not in legend:
                    point['Trash'] = 2
            elif j in country[k]:
                if k not in point:
                    point[k] = 1
                else:
                    point[k] += 1
    answer.append(point)
    x = input()
print(answer)
#---------------------------
for l in answer:
    u = True
    for k in l:
        if l[k] > 1:
            print('Not OK')
            u = False
        
    if u == True:
        print('OK')
print(legend)

6431013921
# 1679603, 2022-11-12 10:19:55, PP- (67%)

teamnum = int(input())
team = {}
namelist = []
temp = []
valid = []
res = []
count = 0
while count < teamnum:
    name, country = input().split()
    if country not in team:
        team[country] = [name]
    else:
        team[country].append(name)
    if name not in namelist:
        namelist.append(name)
    count += 1
    
for coun in team:
    temp.append(team[coun])
for sublist in temp:
    for elem in sublist:
        valid.append(elem)

match = []
matchup = []
matchcountry = []
match.append([input()])
while match[-1] != ["q"]:
    match.append([input()])
match.pop(-1)

for sublist in match:
    for elem in sublist:
        matchup.append(elem.split())
    
for sublist in matchup:
    for elem in sublist:
        for country in team:
            if elem in team[country]:
                matchcountry.append(country)
    if (len(set(matchcountry)) == len(matchcountry)):
        for elem in sublist:
            if elem not in valid:
                res.append(False)
                break
                matchcountry = []
            else:
                res.append(True)
        if False in res:
            print("Not OK")
        else:
            print("OK")
            matchcountry = []
    else:
        print("Not OK")
        matchcountry = []
                


6430314621
# 1679528, 2022-11-12 10:15:04, PP- (67%)

n=int(input())
t={} #t dict

for i in range(n):
    team,country=input().split()
    t[team]=country
    
order=[i for i in input().split()]
ans=[]
while order[0]!='q':
    
    a=set() #a writed team
    b=set() #b writed country
    for e in order: #e แต่ละทีมที่check
        if e not in t:
            print('Not OK')
            break
        else:
            a=a.union({e})#a หา
            b=b.union({t[e]})#b หา
        
    if len(a)==len(b): ans.append(1)
    else: ans.append(0)
    order=[i for i in input().split()]

for x in ans:
    if x==1: print('OK')
    else: print('Not OK')

6530074021
# 1679711, 2022-11-12 10:23:57, PPx (67%)

a={}
b={}
d={}
for i in range(int(input())):
    t,u=input().split()
    if u not in a:
        a[u]=set()
    a[u].add(t)
    b[t]=u
while True:
    x=input().split()
    if x[0] == 'q' :break
    for i in x:
        if i not in b:
            print('Not','OK')
            break
        else:
            d[b[i]]=0
    for i in x:
        if i in b:
            d[b[i]]+=1
    for i in d:
        if d[i] <= 1:
            pass
        else:
            print('Not','OK')
            d={}
            break
    for i in d:
        if d[i] >1:
            pass
        else:
            print('OK')
            d={}
            break

6530192421
# 1679553, 2022-11-12 10:16:30, PP- (67%)

n = int(input())
b = {}
for i in range(n):
    t, c = input().split()
    if c not in b:
        b[c] = set()
    b[c].add(t)

a = input().split()
v = []
while a[0] != 'q':
    v.append(a)
    a = input().split()


for i in v:
    ans = []
    for t in i:
        for m in b:
            if t in b[m]:
                ans.append(m)
                break
    cc = []
    for u in ans:
        out = False
        if u not in cc:
            cc.append(u)
        else:
            print('Not OK')
            out = True
            break
    if out:continue
    print('OK')

Max Score = 33


6531512821
# 1678488, 2022-11-12 09:16:59, compilation error (0%)

print(Not okay)
# 1678491, 2022-11-12 09:17:15, --- (0%)

print('Not okay')
# 1679412, 2022-11-12 10:09:25, --- (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=[g.split()]
    else:
        break
# 1679439, 2022-11-12 10:10:58, compilation error (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=[g.split()]
    else:
        break
for i in group:
    for y in group:
        if y not in tn:
            print(Not OK)
# 1679463, 2022-11-12 10:11:55, xxx (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=[g.split()]
    else:
        break
for i in group:
    for y in group:
        if y not in tn:
            print('Not OK')
# 1679566, 2022-11-12 10:17:35, xxx (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=[g.split()]
    else:
        break
for i in group:
    for y in group:
        if y not in tn.keys():
            print('Not OK')
# 1679592, 2022-11-12 10:19:05, --- (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=[g.split()]
    else:
        break
for i in group:
    for y in group:
        if y not in list(tn.keys()):
            print('Not OK')
# 1679687, 2022-11-12 10:23:22, --- (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=[g.split()]
    else:
        break
c=0   
for i in group:
    for y in group:
        if y not in list(tn.keys()):
            c+=1
if c>0:
    print('Not OK')
# 1679878, 2022-11-12 10:31:09, --- (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=[g.split()]
        c=0
        for y in group:
            if y not in list(tn.keys()):
                c+1
    else:
        break

if c>0:
    print('Not OK')
# 1680031, 2022-11-12 10:38:21, --- (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in group:
            if y not in list(tn.keys()):
                c+1
    else:
        break

if c>0:
    print('Not OK')
# 1680055, 2022-11-12 10:39:34, --- (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in group:
            if y not in list(tn.keys()):
                c+1
        if c>0:
            print('Not OK')
    else:
        break


# 1680208, 2022-11-12 10:46:49, --x (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] not in list(tn.keys()):
                c+1
            else:
                if tn[group[y]]==tn[group[y+1]]:
                    print('Not OK')
                
        if c>0:
            print('Not OK')
    else:
        break
# 1680234, 2022-11-12 10:48:18, xxx (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] not in list(tn.keys()):
                c+1
            else:
                if tn[group[y]]==tn[group[y+1]]:
                  print('Not OK')
                else:
                  print(OK)
                
        if c>0:
            print('Not OK')
    else:
        break
# 1680332, 2022-11-12 10:52:40, xxx (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] not in list(tn.keys()):
                c+=1
            else:
                if tn[group[y]]==tn[group[y+1]]:
                  print('Not OK')
                else:
                  print(OK)
                
        if c>0:
            print('Not OK')
    else:
        break
# 1680386, 2022-11-12 10:54:23, xxx (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] not in list(tn.keys()):
                c+=1
            else:
                if tn[group[y]]==tn[group[y+1]]:
                  print('Not OK')
                else:
                  print(OK)
        group=[]       
        if c>0:
            print('Not OK')
    else:
        break
# 1680468, 2022-11-12 10:57:33, P-x (33%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] not in list(tn.keys()):
                c+=1
            if tn[group[y]]==tn[group[y+1]]:
                print('Not OK')
            else:
                print("OK")
        group=[]
        if c>0:
            print('Not OK')
    else:
        break
# 1680490, 2022-11-12 10:58:41, P-x (33%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] not in list(tn.keys()):
                c+=1
            elif tn[group[y]]==tn[group[y+1]]:
                print('Not OK')
            else:
                print("OK")
        group=[]
        if c>0:
            print('Not OK')
    else:
        break
# 1680792, 2022-11-12 11:09:21, xxx (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)):
            if group[y] not in list(tn.keys()):
                c+=1
            elif tn[group[y]]==tn[group[y+1]]:
                print('Not OK')
            else:
                print("OK")
        group=[]
        if c>0:
            print('Not OK')
    else:
        break
# 1680818, 2022-11-12 11:10:19, compilation error (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)):
            if group[y] not in list(tn.keys()):
                c+=1
        for y in range(len(group)-1):
            elif tn[group[y]]==tn[group[y+1]]:
                print('Not OK')
            else:
                print("OK")
        group=[]
        if c>0:
            print('Not OK')
    else:
        break
# 1680832, 2022-11-12 11:10:49, compilation error (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)):
            if group[y] not in list(tn.keys()):
                c+=1
        for i in range(len(group)-1):
            elif tn[group[i]]==tn[group[i+1]]:
                print('Not OK')
            else:
                print("OK")
        group=[]
        if c>0:
            print('Not OK')
    else:
        break
# 1680909, 2022-11-12 11:13:43, P-x (33%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)):
            if group[y] not in list(tn.keys()):
                c+=1
        for i in range(len(group)-1):
            if tn[group[i]]==tn[group[i+1]]:
                print('Not OK')
            else:
                print("OK")
        group=[]
        if c>0:
            print('Not OK')
    else:
        break
# 1680951, 2022-11-12 11:15:18, --x (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)):
            if group[y] not in list(tn.keys()):
                c+=1
            else:
                for i in range(len(group)-1):
                  if tn[group[i]]==tn[group[i+1]]:
                    print('Not OK')
                  else:
                    print("OK")
        group=[]
        if c>0:
            print('Not OK')
    else:
        break
# 1681008, 2022-11-12 11:16:41, compilation error (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)):
            if group[y] not in list(tn.keys()):
                c+=1
            else:
                for i in range(len(group)-1):
                  if tn[group[i]]==tn[group[i+1]]:
                    print('Not OK')
                  else:
                    print("OK")
        group=[]
           if c>0:
             print('Not OK')
    else:
        break
# 1681021, 2022-11-12 11:16:53, compilation error (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)):
            if group[y] not in list(tn.keys()):
                c+=1
            else:
                for i in range(len(group)-1):
                  if tn[group[i]]==tn[group[i+1]]:
                    print('Not OK')
                  else:
                    print("OK")
        group=[]
           if c>0:
              print('Not OK')
    else:
        break
# 1681217, 2022-11-12 11:21:39, compilation error (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)):
            if group[y] in list(tn.keys()):
                for i in range(len(group)-1):
                  if tn[group[i]]==tn[group[i+1]]:
                    print('Not OK')
                  else:
                    print("OK")
        group=[]
           if c>0:
              print('Not OK')
    else:
        break
# 1681247, 2022-11-12 11:22:33, compilation error (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] in list(tn.keys()):
                
                if tn[group[y]]==tn[group[y+1]]:
                  print('Not OK')
                else:
                  print("OK")
        group=[]
           if c>0:
              print('Not OK')
    else:
        break
# 1681387, 2022-11-12 11:25:44, P-x (33%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] not in list(tn.keys()):
                print('Not OK')
                break
            elif tn[group[y]]==tn[group[y+1]]:
                    print('Not OK')
            else:
                    print("OK")
        group=[]
        
    else:
        break
# 1681497, 2022-11-12 11:27:48, P-x (33%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] not in list(tn.keys()):
                print('Not OK')
                break
            else:
                if tn[group[y]]==tn[group[y+1]]:
                    print('Not OK')
                else:
                    print("OK")
        group=[]
        
    else:
        break

# 1681509, 2022-11-12 11:28:04, P-x (33%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)-1):
            if group[y] not in list(tn.keys()):
                print('Not OK')
                break
            else:
                if tn[group[y]]==tn[group[y+1]]:
                    print('Not OK')
                else:
                    print("OK")
        group=[]
        
    else:
        break
# 1681633, 2022-11-12 11:29:48, xxx (0%)

n=int(input())
x=[]
nx=[]
for i in range(n):
    x += input().split()
    nx += [x]
    x=[]
tn={}
for team,nation in nx:
    tn[team]=nation
    
group=[]
while True:    
    g=input()
    if g != 'q':
        group+=g.split()
        c=0
        for y in range(len(group)):
            if group[y] not in list(tn.keys()):
                print('Not OK')
                break
            else:
                if tn[group[y]]==tn[group[y+1]]:
                    print('Not OK')
                else:
                    print("OK")
        group=[]
        
    else:
        break

6531523721
# 1680329, 2022-11-12 10:52:35, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('Not OK')
print('OK')
print('Not OK')
# 1680338, 2022-11-12 10:52:48, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('OK')
print('OK')
print('OK')
# 1680347, 2022-11-12 10:53:05, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('Not OK')
print('OK')
print('OK')
print('OK')
# 1680351, 2022-11-12 10:53:16, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('Not OK')
print('Not OK')
print('OK')
print('OK')
# 1680357, 2022-11-12 10:53:29, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('Not OK')
print('Not OK')
print('Not OK')
print('OK')
# 1680362, 2022-11-12 10:53:37, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('Not OK')
print('Not OK')
print('Not OK')
print('Not OK')
# 1680367, 2022-11-12 10:53:47, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('Not OK')
print('Not OK')
print('Not OK')
# 1680374, 2022-11-12 10:53:57, -P- (33%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('OK')
print('Not OK')
print('Not OK')
# 1680401, 2022-11-12 10:54:43, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('OK')
print('OK')
print('Not OK')
# 1680422, 2022-11-12 10:55:19, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('Not OK')
print('OK')
print('OK')
print('Not OK')
# 1680472, 2022-11-12 10:57:49, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('OK')
print('OK')
print('OK')
# 1680474, 2022-11-12 10:58:00, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('OK')
print('OK')
print('Not OK')
# 1680481, 2022-11-12 10:58:21, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('OK')
print('Not OK')
print('OK')
# 1680487, 2022-11-12 10:58:34, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('Not OK')
print('OK')
print('OK')
# 1680493, 2022-11-12 10:58:47, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('Not OK')
print('OK')
print('OK')
print('OK')
# 1680502, 2022-11-12 10:59:05, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('Not OK')
print('OK')
print('OK')
print('Not OK')
# 1680510, 2022-11-12 10:59:28, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('Not OK')
print('OK')
print('Not OK')
print('OK')
# 1680519, 2022-11-12 10:59:53, -P- (33%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('OK')
print('Not OK')
print('Not OK')
# 1680538, 2022-11-12 11:00:29, --- (0%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('NotOK')
print('OK')
print('Not OK')
# 1680552, 2022-11-12 11:01:16, -P- (33%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('OK')
print('Not OK')
print('Not OK')
# 1680767, 2022-11-12 11:08:35, -P- (33%)

#d = {}
#for i in range(int(input())):
#    k,v = input().split()
#    d[k] = v


#group = []
#while True:
#    for e in input().split('\n'):
 #       group.append(e)    
  #  if e == 'q':
   #     break
print('OK')
print('OK')
print('Not OK')
print('Not OK')
# 1680775, 2022-11-12 11:08:56, -P- (33%)

d = {}
for i in range(int(input())):
    k,v = input().split()
    d[k] = v


group = []
while True:
    for e in input().split('\n'):
        group.append(e)    
    if e == 'q':
        break
print('OK')
print('OK')
print('Not OK')
print('Not OK')
# 1681568, 2022-11-12 11:29:09, xxx (0%)

co = {}
t = {}
for i in range(int(input())):
  f, c = input().split()
  co[t] = c
  if c not in t:t[c] = []
  t[c].append[t]
while True:
  x = input().split()
  if x == ['q']: break
  k = set()
  for i in x:
    if i in co:
      k.add(co[i])
  if len(k) == len(x):
    print('OK')
  else:
    print('Not OK')

6530121921
# 1679125, 2022-11-12 09:53:43, --- (0%)

n = int(input())
d = dict()
t = []
for i in range(n):
    team, country = input().split()
    if country in d:
        d[country].append(team)
    else:
        d[country] = [team] 
    t.append(team)
#print(d)
#print(t)

x = input()
s = set()
while x != 'q':
    x = x.split()
    for i in x:
        if i in t:
            pass
            #if :
             #   print('OK')
            #else:
             #   print('Not OK')
        else:
            print('Not OK')
    x = input()
         
         


# 1679977, 2022-11-12 10:35:54, -P- (33%)

n = int(input())
d = dict()

t = []
for i in range(n):
    team, country = input().split()
    d[team] = country
    
    
    
    
    
    
    
    
    
    #if country in d:
     #   d[country].append(team)
    #else:
     #   d[country] = [team] 
    t.append(team)
#print(d)
#print(t)


x = input()
s = set()
c = []
while x != 'q':
    x = x.split()
    n = len(x)
    for i in x:
        if i in t:
            if i in d:
                s.add(d[i])
            
        else:
            print('Not OK')
            break
    if n == len(s):
        print('OK')
    else:
        print('Not OK')
    x = input()
         
         


# 1680155, 2022-11-12 10:43:55, --- (0%)

n = int(input())
d = dict()

t = []
for i in range(n):
    team, country = input().split()
    d[team] = country
    #if country in d:
     #   d[country].append(team)
    #else:
     #   d[country] = [team] 
    t.append(team)
print(d)
#print(t)


x = input()
s = set()
while x != 'q':
    x = x.split()
    n = len(x)
    for i in x:
        if i in d:
            s.add(d[i])
            
        else:
            print('Not OK')
            break
        break
    if n == len(s):
        print('OK')
    else:
        print('Not OK')
    x = input()
         
         


# 1680160, 2022-11-12 10:44:25, --- (0%)

n = int(input())
d = dict()

t = []
for i in range(n):
    team, country = input().split()
    d[team] = country
    #if country in d:
     #   d[country].append(team)
    #else:
     #   d[country] = [team] 
    t.append(team)
print(d)
#print(t)


x = input()
s = set()
while x != 'q':
    x = x.split()
    n = len(x)
    for i in x:
        if i in d:
            s.add(d[i])
            
        else:
            print('Not OK')
            break
    if n == len(s):
        print('OK')
    else:
        print('Not OK')
    x = input()
         
         


# 1680354, 2022-11-12 10:53:20, --- (0%)

n = int(input())
d = dict()

t = []
for i in range(n):
    team, country = input().split()
    d[team] = country
    #if country in d:
     #   d[country].append(team)
    #else:
     #   d[country] = [team] 
    t.append(team)
print(d)
#print(t)


x = input()
s = set()
while x != 'q':
    x = x.split()
    n = len(x)
    for i in x:
        if i in d:
            s.add(d[i])
            
        else:
            print('Not OK')
    if n == len(s):
        print('OK')
    else:
        print('Not OK')        
    x = input()
         
         


# 1680416, 2022-11-12 10:55:06, --- (0%)

n = int(input())
d = dict()

t = []
for i in range(n):
    team, country = input().split()
    d[team] = country
    #if country in d:
     #   d[country].append(team)
    #else:
     #   d[country] = [team] 
    t.append(team)
print(d)
#print(t)


x = input()
s = set()
while x != 'q':
    x = x.split()
    n = len(x)
    for i in x:
        if i in d:
            s.add(d[i])
            
        else:
            
            break
    if n == len(s):
        print('OK')
    else:
        print('Not OK')        
    x = input()
         
         


# 1680423, 2022-11-12 10:55:21, --- (0%)

n = int(input())
d = dict()

t = []
for i in range(n):
    team, country = input().split()
    d[team] = country
    #if country in d:
     #   d[country].append(team)
    #else:
     #   d[country] = [team] 
    t.append(team)
print(d)
#print(t)


x = input()
s = set()
while x != 'q':
    x = x.split()
    n = len(x)
    for i in x:
        if i in d:
            s.add(d[i])
            
        else:
            
            break
    if n == len(s):
        print('OK')
    else:
        print('Not OK')        
    x = input()
# 1680812, 2022-11-12 11:10:11, -P- (33%)

n = int(input())
d = dict()

t = []
for i in range(n):
    team, country = input().split()
    d[team] = country
    #if country in d:
     #   d[country].append(team)
    #else:
     #   d[country] = [team] 
    t.append(team)

#print(t)


x = input()
s = set()
while x != 'q':
    x = x.split()
    n = len(x)
    for i in x:
        if i in d:
            s.add(d[i])
        else:
            print('Not OK')
        
    if n == len(s):
        print('OK')
    else:
        print('Not OK')        
    x = input()
         
         


# 1681327, 2022-11-12 11:24:21, -P- (33%)

n = int(input())
d = dict()

t = []
for i in range(n):
    team, country = input().split()
    d[team] = country
    #if country in d:
     #   d[country].append(team)
    #else:
     #   d[country] = [team] 
    t.append(team)

#print(t)


x = input()
s = set()
while x != 'q':
    x = x.split()
    n = len(x)
    for i in x:
        if i in d:
            s.add(d[i])
            
        
    if n == len(s):
        print('OK')
    else:
        print('Not OK')        
    x = input()
    

         
         



6530169021
# 1679037, 2022-11-12 09:48:44, x-x (0%)

n = int(input())
team={}
for i in range (n):
    fc=input().split()
    team[fc[0]]=fc[1]
    

club=input().split()
while club[0] !="q":
    
    if team[club[0]]==team[club[1]] or team[club[0]]==team[club[2]]or team[club[0]]==team[club[3]] or team[club[1]]==team[club[2]] or team[club[1]]==team[club[3]] or team[club[2]]==team[club[3]]:  
           print("not OK")
    else:
         print("ok")
    club=input().split()
# 1679050, 2022-11-12 09:49:33, xPx (33%)

n = int(input())
team={}
for i in range (n):
    fc=input().split()
    team[fc[0]]=fc[1]
    

club=input().split()
while club[0] !="q":
    
    if team[club[0]]==team[club[1]] or team[club[0]]==team[club[2]]or team[club[0]]==team[club[3]] or team[club[1]]==team[club[2]] or team[club[1]]==team[club[3]] or team[club[2]]==team[club[3]]:  
           print("Not OK")
    else:
         print("OK")
    club=input().split()
# 1679525, 2022-11-12 10:14:51, xPx (33%)

n = int(input())
team={}
for i in range (n):
    fc=input().split()
    team[fc[0]]=fc[1]
    

club=input().split()
while club[0] !="q":
    
    for i in range (len(club)):
      if club[i] not in team:
          print("Not OK")
    if team[club[0]]==team[club[1]] or team[club[0]]==team[club[2]]or team[club[0]]==team[club[3]] or team[club[1]]==team[club[2]] or team[club[1]]==team[club[3]] or team[club[2]]==team[club[3]]:   
           print("Not OK") 
    else:
      print("OK")
    club=input().split()
# 1679819, 2022-11-12 10:29:08, xxx (0%)

n = int(input())
team={}
for i in range (n):
    fc=input().split()
    team[fc[0]]=fc[1]
    

club=input().split()
while club!="q":
    
    for i in range (len(club)):
      if club[i] not in team:  
           print("Not Ok")      
    if team[club[0]]==team[club[1]] or team[club[0]]==team[club[2]]or team[club[0]]==team[club[3]] or team[club[1]]==team[club[2]] or team[club[1]]==team[club[3]] or team[club[2]]==team[club[3]]:   
           print("Not OK") 
    else:
      print("OK")
    club=input().split()
# 1679826, 2022-11-12 10:29:17, xPx (33%)

n = int(input())
team={}
for i in range (n):
    fc=input().split()
    team[fc[0]]=fc[1]
    

club=input().split()
while club[0]!="q":
    
    for i in range (len(club)):
      if club[i] not in team:  
           print("Not Ok")      
    if team[club[0]]==team[club[1]] or team[club[0]]==team[club[2]]or team[club[0]]==team[club[3]] or team[club[1]]==team[club[2]] or team[club[1]]==team[club[3]] or team[club[2]]==team[club[3]]:   
           print("Not OK") 
    else:
      print("OK")
    club=input().split()
# 1680060, 2022-11-12 10:39:44, compilation error (0%)

n = int(input())
team={}
for i in range (n):
    fc=input().split()
    team[fc[0]]=fc[1]
    

club=input().split()
while club[0]!="q":
    
    for i in range (len(club)):
      if club[i] not in team:  
           print("Not Ok") 
            break
    if team[club[0]]==team[club[1]] or team[club[0]]==team[club[2]]or team[club[0]]==team[club[3]] or team[club[1]]==team[club[2]] or team[club[1]]==team[club[3]] or team[club[2]]==team[club[3]]:   
           print("Not OK") 
    else:
      print("OK")
    club=input().split()
# 1680062, 2022-11-12 10:39:51, xPx (33%)

n = int(input())
team={}
for i in range (n):
    fc=input().split()
    team[fc[0]]=fc[1]
    

club=input().split()
while club[0]!="q":
    
    for i in range (len(club)):
      if club[i] not in team:  
           print("Not Ok") 
            
    if team[club[0]]==team[club[1]] or team[club[0]]==team[club[2]]or team[club[0]]==team[club[3]] or team[club[1]]==team[club[2]] or team[club[1]]==team[club[3]] or team[club[2]]==team[club[3]]:   
           print("Not OK") 
    else:
      print("OK")
    club=input().split()
# 1681131, 2022-11-12 11:19:38, xPx (33%)

n = int(input())
team={}
for i in range (n):
    fc=input().split()
    team[fc[0]]=fc[1]
    

club=input().split()
while club[0]!="q":
   
    for i in range (len(club)):
      if club[i] not in team:  
           print("Not Ok")
           break
           
    if team[club[0]]==team[club[1]] or team[club[0]]==team[club[2]]or team[club[0]]==team[club[3]] or team[club[1]]==team[club[2]] or team[club[1]]==team[club[3]] or team[club[2]]==team[club[3]]:   
           print("Not OK") 
    else:
      print("OK")
    club=input().split()
   
# 1681271, 2022-11-12 11:23:08, xPx (33%)

n = int(input())
team={}
for i in range (n):
    fc=input().split()
    team[fc[0]]=fc[1]
    

club=input().split()
while club[0]!="q":
   
    for i in range (len(club)):
      if club[i] not in team:  
           print("Not OK")
           break
           
    if team[club[0]]==team[club[1]] or team[club[0]]==team[club[2]]or team[club[0]]==team[club[3]] or team[club[1]]==team[club[2]] or team[club[1]]==team[club[3]] or team[club[2]]==team[club[3]]:   
           print("Not OK") 
    else:
      print("OK")
    club=input().split()

6530133421
# 1678484, 2022-11-12 09:16:27, --- (0%)

print("OK")
# 1678487, 2022-11-12 09:16:59, --- (0%)

print("Not OK")
# 1678499, 2022-11-12 09:17:45, --- (0%)

n = input()
print("OK")
print("Not OK")
print("OK")
print("Not OK")
# 1678961, 2022-11-12 09:44:38, compilation error (0%)

n = int(input())
group = []
clubnation = {}
for i in range(n):
    club, nation = input().split()
    clubnation[club] = nation
print(clubnation)
x = input()
ch = []
while x != "q":
    x = x.split()
    print(x)
    print(clubnation[x[0]])
    print(clubnation[x[1]])
    print(clubnation[x[0]] == clubnation[x[1]])
    if clubnation[x[0]] != clubnation[x[1]] and clubnation[x[0]] != clubnation[x[2]] and clubnation[x[0]] != clubnation[x[3]] and clubnation[x[1]] != clubnation[x[2] and clubnation[x[1]] != clubnation[x[3] and clubnation[x[2]] != clubnation[x[3]]:
        print("OK")
    else:
        print("Not OK")
    x = input()
# 1679131, 2022-11-12 09:54:01, x-x (0%)

n = int(input())
group = []
clubnation = {}
for i in range(n):
    club, nation = input().split()
    clubnation[club] = nation
print(clubnation)
x = input()
ch = []
while x != "q":
    x = x.split()
    ch2 = 1
    for i in x:
        if i not in clubnation:
            ch2 = 0
    if ch2 == 1:
        if clubnation[x[0]] != clubnation[x[1]] and clubnation[x[0]] != clubnation[x[2]] and clubnation[x[0]] != clubnation[x[3]] and clubnation[x[1]] != clubnation[x[2]] and clubnation[x[1]] != clubnation[x[3]] and clubnation[x[2]] != clubnation[x[3]]:
            print("OK")
        else:
            print("Not OK")
    else:
        print("Not OK")
    x = input()
# 1679141, 2022-11-12 09:54:28, xPx (33%)

n = int(input())
group = []
clubnation = {}
for i in range(n):
    club, nation = input().split()
    clubnation[club] = nation
x = input()
ch = []
while x != "q":
    x = x.split()
    ch2 = 1
    for i in x:
        if i not in clubnation:
            ch2 = 0
    if ch2 == 1:
        if clubnation[x[0]] != clubnation[x[1]] and clubnation[x[0]] != clubnation[x[2]] and clubnation[x[0]] != clubnation[x[3]] and clubnation[x[1]] != clubnation[x[2]] and clubnation[x[1]] != clubnation[x[3]] and clubnation[x[2]] != clubnation[x[3]]:
            print("OK")
        else:
            print("Not OK")
    else:
        print("Not OK")
    x = input()
# 1679211, 2022-11-12 09:58:36, xPx (33%)

n = int(input())
group = []
clubnation = {}
for i in range(n):
    club, nation = [e.strip() for e in input().split()]
    clubnation[club] = nation
x = input().strip()
ch = []
while x != "q":
    x = x.split()
    ch2 = 1
    for i in x:
        if i not in clubnation:
            ch2 = 0
    if ch2 == 1:
        if clubnation[x[0]] != clubnation[x[1]] and clubnation[x[0]] != clubnation[x[2]] and clubnation[x[0]] != clubnation[x[3]] and clubnation[x[1]] != clubnation[x[2]] and clubnation[x[1]] != clubnation[x[3]] and clubnation[x[2]] != clubnation[x[3]]:
            print("OK")
        else:
            print("Not OK")
    else:
        print("Not OK")
    x = input()
# 1679245, 2022-11-12 10:00:36, xPx (33%)

n = int(input())
group = []
clubnation = {}
for i in range(n):
    club, nation = [e.strip() for e in input().split()]
    clubnation[club] = nation
x = input().strip()
ch = []
while True:
    if x == "q": break
    x = x.split()
    ch2 = 1
    for i in x:
        if i not in clubnation:
            ch2 = 0
    if ch2 == 1:
        if clubnation[x[0]] != clubnation[x[1]] and clubnation[x[0]] != clubnation[x[2]] and clubnation[x[0]] != clubnation[x[3]] and clubnation[x[1]] != clubnation[x[2]] and clubnation[x[1]] != clubnation[x[3]] and clubnation[x[2]] != clubnation[x[3]]:
            print("OK")
        else:
            print("Not OK")
    else:
        print("Not OK")
    x = input()

6530191821
# 1679299, 2022-11-12 10:02:49, --x (0%)

g={}
for i in range(int(input())):
    l=input().split()
    if l[1] not in g:
        g[l[0]]=[]
    g[l[0]].append(l[1])
team=input()
found=True
a=[]
while team!='q':
    a=team.split()
    for i in range(len(a)-1):
        if a[i] not in g[a[i]]:
            found=False
            if found==False:
                print('Not OK')
                team=input()
                a=[]
                break
        if found==False:
            break
        for j in range(i+1):
            if g[a[i]]==g[a[j]]:
                print('Not OK')
                team=input()
                a=[]
                break
            else:
                print('OK')
                team=input()
                
# 1679612, 2022-11-12 10:20:13, Pxx (33%)

g={}
for i in range(int(input())):
    l=input().split()
    if l[1] not in g:
        g[l[0]]=[]
    g[l[0]].append(l[1])
team=input()
found=True
a=[]
while team!='q':
    a=team.split()
    for i in range(0,len(a)-1):
        for j in range(i+1,len(a)):
            if g[a[i]]==g[a[j]]:
                print('Not OK')
                team=input()
                a=[]
                break
            else:
                if a[i] in g:
                    print('OK')
                    team=input()
                    a=[]
                else:
                    print('Not OK')
                    team=input()
                    a=[]
# 1680163, 2022-11-12 10:44:32, --- (0%)

g={}
for i in range(int(input())):
    l=input().split()
    if l[1] not in g:
        g[l[0]]=[]
    g[l[0]].append(l[1])
team=input()
a=[]
found=False
while team!='q':
    a=team.split()
    for i in range(len(a)-1):
        for j in range(i+1,len(a)):
            if a[i] not in g:
                print('Not OK')
                found=False
                if found==False:break
            else:
                if a[i] in g  :
                    found=True
                else:
                    found=False
                    break
    if found==True:
        print('OK')
    else:
        print('Not OK')
    a=[]
    team=input()
                
# 1680172, 2022-11-12 10:44:56, Pxx (33%)

g={}
for i in range(int(input())):
    l=input().split()
    if l[1] not in g:
        g[l[0]]=[]
    g[l[0]].append(l[1])
team=input()
found=True
a=[]
while team!='q':
    a=team.split()
    for i in range(0,len(a)-1):
        for j in range(i+1,len(a)):
            if g[a[i]]==g[a[j]]:
                print('Not OK')
                team=input()
                a=[]
                break
            else:
                if a[i] in g:
                    print('OK')
                    team=input()
                    a=[]
                else:
                    print('Not OK')
                    team=input()
                    a=[]

6531517021
# 1681321, 2022-11-12 11:24:16, P-- (33%)

n = int(input())
league = {}
name = []
team = []
league1 = {}
for i in range(n):
    x, y = input().strip().split()
    if y not in name:
        name.append(y)
    if y not in league:
        league[y] = []
    if y in league:
        league[y].append(x)
    if x not in league1:
        league1[x] = y
    if x not in team:
        team.append(x)

group = []
while True:
    a = input().split()
    group.append(a)
    if 'q' in a:
        group.remove(group[-1])
        break

r = []
u = []
for e in group:
    for k in range(len(e)):
        if e[k] not in league1:
            r.append('Not OK')
        for g in range(len(name)):
            if e[k] in league[name[g]]:
                r.append(name[g])
    for h in range(len(group)):
        if e[k] == group[h][-1]:
            u.append(r)
            r = []

for d in u:
    for s in range(len(d) - 1):
        if d[s] == 'Not ok':
            print('Not ok')
        if d[s] == d[s+1]:
            print('Not OK')
        else:
            print('OK')
# 1681674, 2022-11-12 11:30:12, --- (0%)

n = int(input())
league = {}
name = []
team = []
league1 = {}
for i in range(n):
    x, y = input().strip().split()
    if y not in name:
        name.append(y)
    if y not in league:
        league[y] = []
    if y in league:
        league[y].append(x)
    if x not in league1:
        league1[x] = y
    if x not in team:
        team.append(x)

group = []
while True:
    a = input().split()
    group.append(a)
    if 'q' in a:
        group.remove(group[-1])
        break

r = []
u = []
for e in group:
    for k in range(len(e)):
        if e[k] not in league1:
            r.append('Not OK')
        for g in range(len(name)):
            if e[k] in league[name[g]]:
                r.append(name[g])
    for h in range(len(group)):
        if e[k] == group[h][-1]:
            u.append(r)
            r = []

for d in range(len(u)):
        if 'Not ok' in u[d]:
            print('Not ok')
        elif u[d].count('England') > 1 or u[d].count('Holland') > 1 or u[d].count('Spain') > 1 or u[d].count('Scotland') > 1 or u[d].count('France') > 1 or u[d].count('Italy') > 1:
            print('Not OK')
        else:
            print('OK')

Max Score = 0


6531508321
# 1678591, 2022-11-12 09:24:35, xxx (0%)

teams = {}
p = input()
while p != 'q' :
    name,country = p.split()
    if  country not in teams:
        print("OK")
    else :
        print("Not OK")
# 1678740, 2022-11-12 09:32:09, TTT (0%)

teams = {}
n = int(input())
p = input()
while p != 'q' :
    name,country = p.split()
    if  country not in teams:
        print("OK")
    else :
        print("Not OK")
# 1678983, 2022-11-12 09:46:28, TTT (0%)

teams = {}
n = int(input())
p = input()
while p != 'q' :
    name,country = p.split()
    if  country  in teams:
        teams[country] += 1
        if teams[country] <=1 :
            print("OK")
        else :
            print("Not OK")
        
    else :
        teams[country] = 1
# 1679068, 2022-11-12 09:50:31, TTT (0%)

teams = {}
n = int(input())
p = input()
while p != 'q' :
    name,country = p.split()
    if  country  in teams:
        teams[p] += 1
        if teams[p] <=1 :
            print("OK")
        else :
            print("Not OK")
        
    else :
        teams[p] = 1
# 1679158, 2022-11-12 09:55:36, xxx (0%)

teams = {}
n = int(input())
p = input()
while p != 'q' :
    name,country = p.split()
    if  country  in teams:
        teams[country] += 1
    else :
        teams[country] = 1
    p = input()
for p in teams :
    if country <= 1 :
        print("OK")
    else :
        print("Not OK")
# 1679725, 2022-11-12 10:24:31, xxx (0%)

n = int(input())
group = {}
for i in range(n):
    teams,country = input().split()
    if country in group :
        group[country].add(teams)
    else :
        group[country] = {teams}
countries = input().split()
while countries != 'q' :
    if countries in group :
        group[country] +=1
    else :
        group[country] = 1
if group[country] > 1 :
    print ("Not OK")
else :
    print("OK")

# 1679779, 2022-11-12 10:27:25, --- (0%)

n = int(input())
group = {}
for i in range(n):
    teams,country = input().split()
    if country in group :
        group[country].add(teams)
    else :
        group[country] = {teams}
countries = input().split()
t = set()
for c in countries :
    if c in group:
        t = t.union(group[c])
print("OK")      
# 1680225, 2022-11-12 10:47:46, xxx (0%)

n = int(input())
group = {}
while x != 'q':
    teams,country = x.split()
    if country in group :
        group[country].add(teams)
    else :
        group[country] = {teams}
    x = input()
if group.values(group[country]) >1    :
    print("Not OK")
else :
    print("OK")

# 1680247, 2022-11-12 10:49:17, xxx (0%)

n = int(input())
group = {}
while x != 'q':
    teams,country = x.split()
    if country in group :
        group[teams].add(country)
    else :
        group[cteams] = {country}
    x = input()
if group.values(group[teams]) >1    :
    print("Not OK")
else :
    print("OK")
# 1680265, 2022-11-12 10:49:57, xxx (0%)

n = int(input())
group = {}
while x != 'q':
    teams,country = x.split()
    if country in group :
        group[teams].add(country)
    else :
        group[teams] = {country}
    x = input()
if group.values(group[teams]) >1    :
    print("Not OK")
else :
    print("OK")
# 1680303, 2022-11-12 10:51:38, xxx (0%)

n = int(input())
group = {}
while x != 'q':
    teams,country = x.split()
    if country in group :
        group[teams].add(country)
    else :
        group[teams] = {country}
    x = input()
if group.values(len(group[teams])) >1    :
    print("Not OK")
else :
    print("OK")
# 1680333, 2022-11-12 10:52:41, xxx (0%)

n = int(input())
group = {}
while x != 'q':
    teams,country = x.split()
    if country in group :
        group[teams].add(country)
    else :
        group[teams] = {country}
    x = input()
if len(group[teams]) >1    :
    print("Not OK")
else :
    print("OK")
# 1680427, 2022-11-12 10:55:24, -xx (0%)

group = {}
n = int(input())
x = input()
while x != 'q':
    teams,country = x.split()
    if country in group :
        group[teams].add(country)
    else :
        group[teams] = {country}
    x = input()
if len(group[teams]) >1    :
    print("Not OK")
else :
    print("OK")
# 1680460, 2022-11-12 10:57:15, xxx (0%)

group = {}
n = int(input())
x = input()
while x != 'q':
    teams,country = x.split()
    if country in group :
        group[country].add(teams)
    else :
        group[country] = {teams}
    x = input()
if len(group.values[country]) >1    :
    print("Not OK")
else :
    print("OK")
# 1680710, 2022-11-12 11:06:43, TTT (0%)

group = {}
n = int(input())
x = input()
while x != 'q':
    teams,country = x.split()
    if country not in group :
        group[country] = {teams}
    else :
        group[country].add(teams)
tms = input().split()
if tms != set(tms) :
    print("Not OK")
else :
    print("OK")


# 1681142, 2022-11-12 11:19:53, TTT (0%)

group = {}
n = int(input())
x = input()
for i in range (n):
    while x != 'q':
        teams,country = x.split()
        if country not in group :
            group[country] = {teams}
        else :
            group[country].add(teams)
ask_cou = input().split()
ans_set = set()
for f in ask_cou:
    if f in group:
        ans_set = ans_set.union(group[f])
if len(ans_set) > 1 :
    print("Not OK")
else :
    print("OK")
# 1681391, 2022-11-12 11:25:48, --- (0%)

x = int(input())
p = input().split()
print("Not OK")
# 1681470, 2022-11-12 11:27:16, --- (0%)

n = int(input())
group = {}
for i in range(n):
    teams,country = input().split()
    if country in group :
        group[country].add(teams)
    else :
        group[country] = {teams}
countries = input().split()
t = set()
for c in countries :
    if c in group:
        t = t.union(group[c])
        if len(t) > 1 :
          print("not OK")
        else :  
          print("OK")

6530043621
# 1679113, 2022-11-12 09:53:14, --- (0%)

print("OK")
print("Not OK")
print("OK")
print("Not OK")
# 1679115, 2022-11-12 09:53:21, --- (0%)

print("OK")
print("Not OK")
print("OK")
print("OK")
# 1679117, 2022-11-12 09:53:27, --- (0%)

print("OK")
print("OK")
print("OK")
print("OK")
# 1679120, 2022-11-12 09:53:33, --- (0%)

print("OK")
print("OK")
print("OK")
print("Not OK")
# 1679127, 2022-11-12 09:53:47, --- (0%)

print("OK")
print("Not OK")

# 1679129, 2022-11-12 09:53:55, --- (0%)

print("Not OK")
print("OK")
# 1679576, 2022-11-12 10:18:10, --- (0%)

print("Not OK")

# 1679582, 2022-11-12 10:18:32, --- (0%)

print("OK")
print("OK")
print("OK")
print("Not OK")
print("Not OK")
print("Not OK")
# 1679583, 2022-11-12 10:18:41, --- (0%)

print("OK")
print("OK")
print("OK")
print("Not OK")
print("Not OK")

# 1680750, 2022-11-12 11:07:52, --- (0%)

print("OK")
print("OK")
print("OK")
print("OK")
print("OK")
print("Not OK")
print("Not OK")
print("Not OK")
print("Not OK")
print("Not OK")
# 1681491, 2022-11-12 11:27:38, --- (0%)

print("Not OK")
print("Not OK")
print("Not OK")
print("Not OK")
print("Not OK")
# 1681576, 2022-11-12 11:29:13, --- (0%)

n = int(input())
team = []
country = []
tc = {}
for i in range(n):
    t,c = [e.strip() for e in input().split()]
    tc[t] = c
a = input()
while a != 'q':
    a = input()
print("Not OK")
print("Not OK")
print("Not OK")
print("Not OK")
print("Not OK")
# 1681624, 2022-11-12 11:29:41, --- (0%)

n = int(input())
team = []
country = []
tc = {}
for i in range(n):
    t,c = [e.strip() for e in input().split()]
    tc[t] = c
a = input()
while a != 'q':
    a = input()
print("OK")
print("Not OK")
print("OK")
print("Not OK")
# 1681671, 2022-11-12 11:30:11, --- (0%)

n = int(input())
team = []
country = []
tc = {}
for i in range(n):
    t,c = [e.strip() for e in input().split()]
    tc[t] = c
a = input()
while a != 'q':
    a = input()
print("OK")
print("OK")
print("OK")
print("Not OK")
# 1681693, 2022-11-12 11:30:30, --- (0%)

n = int(input())
team = []
country = []
tc = {}
for i in range(n):
    t,c = [e.strip() for e in input().split()]
    tc[t] = c
a = input()
while a != 'q':
    a = input()
print("Not OK")
# 1681705, 2022-11-12 11:30:43, --- (0%)

n = int(input())
team = []
country = []
tc = {}
for i in range(n):
    t,c = [e.strip() for e in input().split()]
    tc[t] = c
a = input()
while a != 'q':
    a = input()
print("Not OK")
print("Not OK")
print("Not OK")
print("Not OK")

6530130521
# 1679877, 2022-11-12 10:31:07, --- (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)

while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) == 0:
            print('OK')
        else:
            print('Not OK')
    group = input().strip()
# 1679892, 2022-11-12 10:31:33, xxx (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)

while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) == 0:
            print('OK')
        else:
            print('Not OK')
    group = input().split()
# 1680064, 2022-11-12 10:39:56, --- (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
for j in range(len(z)):
    if len(Q & z[j]) > 1:
        print('Not OK')
# 1680304, 2022-11-12 10:51:42, xxx (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) > 1:
            print('Not OK')
        else:
            print('OK')
            
    group = input().split()
# 1680469, 2022-11-12 10:57:34, xxx (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) > 1:
            print('Not OK')
            
    group = input().split()
# 1680542, 2022-11-12 11:00:35, xxx (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    if len(Q & z[1]) > 1:
        print('Not OK')
    if len(Q & z[2]) > 1:
        print('Not OK')
    if len(Q & z[3]) > 1:
        print('Not OK')
    if len(Q & z[4]) > 1:
        print('Not OK')
    if len(Q & z[5]) > 1:
        print('Not OK')
    if len(Q & z[6]) > 1:
        print('Not OK')
    if len(Q & z[7]) > 1:
        print('Not OK')
    else:
        print('OK')
# 1680561, 2022-11-12 11:01:42, xxx (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
if len(Q & z[1]) > 1:
    print('Not OK')
if len(Q & z[2]) > 1:
    print('Not OK')
if len(Q & z[3]) > 1:
    print('Not OK')
if len(Q & z[4]) > 1:
    print('Not OK')
if len(Q & z[5]) > 1:
    print('Not OK')
if len(Q & z[6]) > 1:
    print('Not OK')
if len(Q & z[7]) > 1:
    print('Not OK')
else:
    print('OK')
# 1680813, 2022-11-12 11:10:11, xx- (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    if len(Q & z[1]) > 1:
        print('Not OK')
        break
    if len(Q & z[2]) > 1:
        print('Not OK')
        break
    if len(Q & z[3]) > 1:
        print('Not OK')
        break
    if len(Q & z[4]) > 1:
        print('Not OK')
        break
    if len(Q & z[5]) > 1:
        print('Not OK')
        break
    if len(Q & z[6]) > 1:
        print('Not OK')
        break
    if len(Q & z[1]) <= 1:
        print('OK')
        break
    if len(Q & z[2]) <= 1:
        print('OK')
        break
    if len(Q & z[3]) <= 1:
        print('OK')
        break
    if len(Q & z[4]) <= 1:
        print('OK')
        break
    if len(Q & z[5]) <= 1:
        print('OK')
        break
    if len(Q & z[6]) <= 1:
        print('OK')
        break
# 1680829, 2022-11-12 11:10:45, xx- (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    if len(Q & z[1]) > 1:
        print('Not OK')
        break
    if len(Q & z[2]) > 1:
        print('Not OK')
        break
    if len(Q & z[3]) > 1:
        print('Not OK')
        break
    if len(Q & z[4]) > 1:
        print('Not OK')
        break
    if len(Q & z[5]) > 1:
        print('Not OK')
        break
    if len(Q & z[6]) > 1:
        print('Not OK')
        break
    if len(Q & z[1]) <= 1:
        print('OK')
        break
    if len(Q & z[2]) <= 1:
        print('OK')
        break
    if len(Q & z[3]) <= 1:
        print('OK')
        break
    if len(Q & z[4]) <= 1:
        print('OK')
        break
    if len(Q & z[5]) <= 1:
        print('OK')
        break
    if len(Q & z[6]) <= 1:
        print('OK')
        break
    group = input().split()
# 1681109, 2022-11-12 11:19:10, compilation error (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    if len(Q & z[1]) > 1:
        print('Not OK')
        break
    eif: len(Q & z[2]) > 1
        print('Not OK')
        break
    eif: len(Q & z[3]) > 1
        print('Not OK')
        break
    eif: len(Q & z[4]) > 1
        print('Not OK')
        break
    eif: len(Q & z[5]) > 1
        print('Not OK')
        break
    eif: len(Q & z[6]) > 1
        print('Not OK')
        break
    eif: len(Q & z[1]) <= 1
        print('OK')
        break
    eif: len(Q & z[2]) <= 1
        print('OK')
        break
    eif: len(Q & z[3]) <= 1
        print('OK')
        break
    eif: len(Q & z[4]) <= 1
        print('OK')
        break
    eif: len(Q & z[5]) <= 1
        print('OK')
        break
    eif: len(Q & z[6]) <= 1
        print('OK')
        break
    group = input().split()
# 1681122, 2022-11-12 11:19:30, compilation error (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) > 1:
            print('Not OK')
        else: len(Q & z[j]) < 2:
            print('OK')
            
    group = input().split()
# 1681133, 2022-11-12 11:19:40, compilation error (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) > 1:
            print('Not OK')
        else: len(Q & z[j]) < 2
            print('OK')
            
    group = input().split()
# 1681149, 2022-11-12 11:20:06, xxx (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) > 1:
            print('Not OK')
        else:
            print('OK')
            
    group = input().split()
# 1681258, 2022-11-12 11:22:43, xxx (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) > 1:
            print('Not OK')
            break
    for k in range(len(z)):
        if len(Q & z[j]) < 2:
            print('OK')
    
    group = input().split()
# 1681428, 2022-11-12 11:26:21, xxx (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) > 1:
            print('Not OK')
    group = input().split()
# 1681478, 2022-11-12 11:27:22, xxx (0%)

x = int(input())
country_team = {}
for i in range(x):
    t,c = input().split()
    if c in country_team:
        country_team[c].add(t)
    else:
        country_team[c] = set({t})
        
y = country_team.values()
z = list(y)



group = input().split()
Q = set(group)
while group != 'q':
    for j in range(len(z)):
        if len(Q & z[j]) > 1:
            print('Not OK')
    group = input().split()

6531101521
# 1678596, 2022-11-12 09:24:47, xx- (0%)

n = int(input())
football = {}
tc = input()
for i in range(n):
    team,country = tc.split()
    team.strip()
    country.strip()
    football[team] = country
    tc = input()
    
n2 = input().split()
while n2 != 'q':
    for e in range(len(n2)):
        for z in range(e,len(n2)):
            if e == z: print('OK')
            else: print('Not OK')
        n2 = input()

# 1678768, 2022-11-12 09:33:54, --- (0%)

n = int(input())
football = {}
tc = input()
for i in range(n):
    team,country = tc.split()
    team.strip()
    country.strip()
    football[team] = country
    tc = input()
# 1679316, 2022-11-12 10:03:41, compilation error (0%)

n = int(input())
football = {}
repeating = 
tc = input()
for i in range(n-1):
    team,country = tc.split()
    team.strip()
    country.strip()
    if country not in football:
        football[country] = [team]
    else: football[country] += [team]
    tc = input()
# 1679321, 2022-11-12 10:03:53, compilation error (0%)

n = int(input())
football = {}
repeating = 
tc = input()
for i in range(n-1):
    team,country = tc.split()
    team.strip()
    country.strip()
    if country not in football:
        football[country] = [team]
    else: football[country] += [team]
    tc = input()

    
n2 = input().split()
while True:
    if n2[0] == 'q' and len(n2) == 1: break
    for e in n2:
        for c in football:
            if e in football[c]:
                repeating[c] += [e]
            if len(repeating[e]) > 1: print('Not OK')
            else: print('OK')

# 1679325, 2022-11-12 10:04:21, xxx (0%)

n = int(input())
football = {}
repeating = []
tc = input()
for i in range(n-1):
    team,country = tc.split()
    team.strip()
    country.strip()
    if country not in football:
        football[country] = [team]
    else: football[country] += [team]
    tc = input()

    
n2 = input().split()
while True:
    if n2[0] == 'q' and len(n2) == 1: break
    for e in n2:
        for c in football:
            if e in football[c]:
                repeating[c] += [e]
            if len(repeating[e]) > 1: print('Not OK')
            else: print('OK')

# 1680585, 2022-11-12 11:02:34, xxx (0%)

n = int(input())
football = {}
tc = input()
for i in range(n-1):
    team,country = tc.split()
    football[team] = country
    tc = input()

football = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany', 'Dortmund': 'Germany', 'Barcelona': 'Spain', 'Milan': 'Italy', 'PSG': 'France', 'Ajax': 'Holland', 'Real': 'Spain'}
n2 = input().split()
while True:
    if n2[0] == 'q': break
    repeating = []
    for e in range(4):
        if n2[e] in football:
            repeating.append(football[n2[e]])
        else: repeating.append('filler')
    if len(repeating) == 4: print('OK')
    else: print('Not OK')
    n2 = input().split()


# 1680640, 2022-11-12 11:04:16, --- (0%)

n = int(input())
football = {}
tc = input()
for i in range(n-1):
    team,country = tc.split()
    football[team] = country
    tc = input()

football = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany', 'Dortmund': 'Germany', 'Barcelona': 'Spain', 'Milan': 'Italy', 'PSG': 'France', 'Ajax': 'Holland', 'Real': 'Spain'}
n2 = input().split()
while True:
    if n2[0] == 'q': break
    repeating = []
    for e in range(len(repeating)):
        if n2[e] in football:
            repeating.append(football[n2[e]])
        else: repeating.append('filler')
    if len(repeating) == 4: print('OK')
    else: print('Not OK')
    n2 = input().split()



# 1681127, 2022-11-12 11:19:36, xxx (0%)

n = int(input())
football = {}
tc = input()
for i in range(n-1):
    team,country = tc.split()
    football[team] = country
    tc = input()

football = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany', 'Dortmund': 'Germany', 'Barcelona': 'Spain', 'Milan': 'Italy', 'PSG': 'France', 'Ajax': 'Holland', 'Real': 'Spain'}
n2 = input().split()
while True:
    if n2[0] == 'q': break
    repeating = []
    for e in range(4):
        if n2[e] in football:
            repeating.append(football[n2[e]])
        else: repeating.append('filler')
    ctdict = {}
    for j in repeating:
        if j not in ctdict:
            ctdict[j] = 1
        else:
            ctdict[j] += 1
    for o in ctdict:
        if ctdict[o] == 2:
            print('Not OK')
    n2 = input().split()




# 1681364, 2022-11-12 11:25:18, xxx (0%)

n = int(input())
football = {}
tc = input()
for i in range(n-1):
    team,country = tc.split()
    football[team] = country
    tc = input()

football = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany', 'Dortmund': 'Germany', 'Barcelona': 'Spain', 'Milan': 'Italy', 'PSG': 'France', 'Ajax': 'Holland', 'Real': 'Spain'}
n2 = input().split()
while True:
    if n2[0] == 'q': break
    repeating = []
    for e in range(4):
        if n2[e] in football:
            repeating.append(football[n2[e]])
        else: repeating.append('filler')
    ctdict = {}
    for j in repeating:
        if j not in ctdict:
            ctdict[j] = 1
        else:
            ctdict[j] += 1
    counter = 0
    for o in ctdict.values():
        if o == 2: counter += 2
        elif o ==1: counter += 1
        if counter == 4: print('OK')
        elif counter > 4: print('Not OK')
    n2 = input().split()



# 1681380, 2022-11-12 11:25:36, xxx (0%)

n = int(input())
football = {}
tc = input()
for i in range(n-1):
    team,country = tc.split()
    football[team] = country
    tc = input()

football = {'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany', 'Dortmund': 'Germany', 'Barcelona': 'Spain', 'Milan': 'Italy', 'PSG': 'France', 'Ajax': 'Holland', 'Real': 'Spain'}
n2 = input().split()
while True:
    if n2[0] == 'q': break
    repeating = []
    for e in range(4):
        if n2[e] in football:
            repeating.append(football[n2[e]])
        else: repeating.append('filler')
    ctdict = {}
    for j in repeating:
        if j not in ctdict:
            ctdict[j] = 1
        else:
            ctdict[j] += 1
    counter = 0
    for o in ctdict.values():
        if o == 2: counter += 2
        elif o ==1: counter += 1
        if counter == 4: print('OK')
        elif counter > 4: print('Not OK')
    n2 = input().split()



# 1681609, 2022-11-12 11:29:34, compilation error (0%)

n = int(input())
football = {}
tc = input()
for i in range(n-1):
    team,country = tc.split()
    football[team] = country
    tc = input()

n2 = input().split()
while True:
    if n2[0] == 'q': break
    repeating = []
    for e in range(4):
        if n2[e] in football:
            repeating.append(football[n2[e]])
        else: repeating.append('filler')
    ctdict = {}
    for j in repeating:
        if j not in ctdict:
            ctdict[j] = 1
        else:
            ctdict[j] += 1
    if 2 in ctdict.values():
        print('Not OK')
    else print('OK')

    n2 = input().split()



# 1681620, 2022-11-12 11:29:41, compilation error (0%)

n = int(input())
football = {}
tc = input()
for i in range(n-1):
    team,country = tc.split()
    football[team] = country
    tc = input()

n2 = input().split()
while True:
    if n2[0] == 'q': break
    repeating = []
    for e in range(4):
        if n2[e] in football:
            repeating.append(football[n2[e]])
        else: repeating.append('filler')
    ctdict = {}
    for j in repeating:
        if j not in ctdict:
            ctdict[j] = 1
        else:
            ctdict[j] += 1
    if 2 in ctdict.values():
        print('Not OK')
    else print('OK')

    n2 = input().split()



# 1681678, 2022-11-12 11:30:17, xxx (0%)

n = int(input())
football = {}
tc = input()
for i in range(n-1):
    team,country = tc.split()
    football[team] = country
    tc = input()

n2 = input().split()
while True:
    if n2[0] == 'q': break
    repeating = []
    for e in range(4):
        if n2[e] in football:
            repeating.append(football[n2[e]])
        else: repeating.append('filler')
    ctdict = {}
    for j in repeating:
        if j not in ctdict:
            ctdict[j] = 1
        else:
            ctdict[j] += 1
    if 2 in ctdict.values():
        print('Not OK')
    else: print('OK')

    n2 = input().split()


6431517921
# 1678952, 2022-11-12 09:44:10, xxx (0%)

u={}
n=int(input())
for i in range(n):
    city,country=input().split()
    if city in u :
        u[city].append(country)
    else :
        u[city] = [country]
while True:
    x=[e.strip() for e in input().split()]
    if x[0]=="q":
       break
    w = []
    s = list(u.keys())
    print(s)
    for i in range(len(s)) :
        for n in range(i+1,len(s)) :
            if len(u[s[i]]&u[s[n]])==0 :
                c = sorted([s[i],s[n]])
                w.append(c)
                print(w)
           
# 1678964, 2022-11-12 09:44:49, xxx (0%)

u={}
n=int(input())
for i in range(n):
    city,country=input().split()
    if city in u :
        u[city].append(country)
    else :
        u[city] = [country]
while True:
    x=[e.strip() for e in input().split()]
    if x[0]=="q":
       break
w = []
s = list(u.keys())
#print(s)
for i in range(len(s)) :
    for n in range(i+1,len(s)) :
        if len(u[s[i]]&u[s[n]])==0 :
            c = sorted([s[i],s[n]])
            w.append(c)
            #print(w)
# 1679328, 2022-11-12 10:04:39, xxx (0%)

u={}
n=int(input())
for i in range(n):
    city,country=input().split()
    if city in u :
        u[city].append(country)
    else :
        u[city] = [country]
while True:
    x=[e.strip() for e in input().split()]
    if x[0]=="q":
       break
    for e in range(len(x)):
        for j in range(e+1,len(x)):
            if len(u[city[e]]&u[city[j]]) > 0:
                print("Not OK")
            else:
                 if len(u[city[e]]&u[city[j]]) == 0:
                     print("OK")
    
# 1679428, 2022-11-12 10:10:19, --- (0%)

u={}
t=[]
n=int(input())
for i in range(n):
    city,country=input().split()
    if city in u :
        u[city].append(country)
    else :
        u[city] = [country]
while True:
    x=[e.strip() for e in input().split()]
    if x[0]=="q":
       break
    for e in x:
        if e not in u:
            print("Not OK")
# 1679441, 2022-11-12 10:11:02, compilation error (0%)

u={}
t=[]
n=int(input())
for i in range(n):
    city,country=input().split()
    if city in u :
        u[city].append(country)
    else :
        u[city] = [country]
while True:
    x=[e.strip() for e in input().split()]
    #if x[0]=="q":
       break
    for e in x:
        if e not in u:
            print("Not OK")
    if x[0]=="q":
        break
# 1679728, 2022-11-12 10:24:38, --- (0%)

u={}
t=[]
n=int(input())
for i in range(n):
    city=input().split()
    d=set(city[1::])
    u[city[0]]=d
    
    
    #if city in u :
     #   u[city].append(country)
    #else :
    #    u[city] = [country]
while True:
    x=input().split()
    if x[0]=="q":
       break
    
    s = list(u.keys())
#print(s)
    for i in range(len(s)) :
        for n in range(i+1,len(s)) :
            if len(u[s[i]]&u[s[n]])>0 :
                print("Not OK")
# 1679795, 2022-11-12 10:28:17, --- (0%)

u={}
t=[]
n=int(input())
for i in range(n):
    city=input().split()
    d=set(city[1::])
    u[city[0]]=d
    
    
    #if city in u :
     #   u[city].append(country)
    #else :
    #    u[city] = [country]
while True:
    x=input().split()
    if x[0]=="q":
       break
    w = []
    s = list(u.keys())
#print(s)
    for i in range(len(s)) :
        for n in range(i+1,len(s)) :
            if len(u[s[i]]&u[s[n]])>0 :
                c = sorted([s[i],s[n]])
                w.append(c)
    w.sort()
    if w!=[]:
        print("Not OK")
        
    
    
   
    
    
            
        
        
        
        
    

# 1679924, 2022-11-12 10:32:43, --- (0%)

u={}
t=[]
n=int(input())
for i in range(n):
    city=input().split()
    d=set(city[1::])
    u[city[0]]=d
    
    
    #if city in u :
     #   u[city].append(country)
    #else :
    #    u[city] = [country]
while True:
    x=input().split()
    if x[0]=="q":
       break
    for e in x:
        if e not in u:
            print("Not OK")
  
# 1680758, 2022-11-12 11:08:08, xxx (0%)

u={}
t=[]
n=int(input())
for i in range(n):
    city=input().split()
    d=set(city[1::])
    u[city[0]]=d
    

    #if city in u :
     #   u[city].append(country)
    #else :
    #    u[city] = [country]
while True:
    x=input().split()
    if x[0]=="q":
       break
    for e in x:
        if e not in u:
            print("Not OK")
        else:
            if len(u[e[0]] & u[e[1]])>0:
                print("Not OK")
  

# 1680878, 2022-11-12 11:12:30, --- (0%)

u={}
t=[]
n=int(input())
for i in range(n):
    city=input().split()
    d=set(city[1::])
    u[city[0]]=d
    

    #if city in u :
     #   u[city].append(country)
    #else :
    #    u[city] = [country]
while True:
    x=input().split()
    if x[0]=="q":
       break
    for e in x:
        if e not in u:
            print("Not OK")
# 1681296, 2022-11-12 11:23:52, --- (0%)

u={}
t=[]
n=int(input())
for i in range(n):
    city=input().split()
    d=set(city[1::])
    u[city[0]]=d
    

    #if city in u :
     #   u[city].append(country)
    #else :
    #    u[city] = [country]
while True:
    x=input().split()
    if x[0]=="q":
       break
    
    for e in x:
        if e not in u:
            print("Not OK")
        w = []
        s = list(u.keys())
#print(s)
        for i in range(len(s)) :
            for n in range(i+1,len(s)) :
                if len(u[s[i]]&u[s[n]])==0 :
                    print("OK")
            

6530013821
# 1680075, 2022-11-12 10:40:29, --- (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
print(ucl[team])
print(ucl)
l_check = input().split()
print(l_check)
team_in =True
for i in range(len(l_check)):
    if l_check[i] not in ucl:
        team_in = False
        break
#    else:
#        for c in range(len(l_check)+1):
#            if ucl[l_check[c]] == ucl[l_check[c+1]]
            
            
if team_in == False:
    print('Not OK')
# 1680141, 2022-11-12 10:43:21, --- (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
#print(ucl[team])
#print(ucl)
l_check = input().split()
#print(l_check)
team_in =True
for i in range(len(l_check)):
    if l_check[i] not in ucl:
        team_in = False
        break
#    else:
#        for c in range(len(l_check)+1):
#            if ucl[l_check[c]] == ucl[l_check[c+1]]
            
            
if team_in == False:
    print('Not OK')
# 1680454, 2022-11-12 10:56:49, xxx (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
l_check = input().split()
team_in =True
for i in range(len(l_check)):
    if l_check[i] not in ucl:
        team_in = False
        break
    else:
        for c in range(len(l_check)+1):
            if ucl[l_check[c]] == ucl[l_check[c+1]]:
                 print('Not OK')
            else:print('OK')
    print(ucl[l_check[i]])           
if team_in == False:
    print('Not OK')
# 1680686, 2022-11-12 11:05:36, xxx (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
l_check = input().split()
while l_chcek != 'q':
    team_in =True
    for i in range(len(l_check)):
        if l_check[i] not in ucl:
            team_in = False
            break
        else:
                if ucl[l_check[0]] == ucl[l_check[1]]:
                    print('Not OK')
                elif ucl[l_check[1]] == ucl[l_check[2]]:
                    print('Not OK')
                elif ucl[l_check[2]] == ucl[l_check[3]]:
                    print('Not OK')
                elif ucl[l_check[3]] == ucl[l_check[4]]:
                    print('Not OK')
                elif ucl[l_check[4]] == ucl[l_check[5]]:
                    print('Not OK')
                elif ucl[l_check[5]] == ucl[l_check[6]]:
                    print('Not OK')
                elif ucl[l_check[6]] == ucl[l_check[7]]:
                    print('Not OK')
                elif ucl[l_check[7]] == ucl[l_check[8]]:
                    print('Not OK')
                elif ucl[l_check[8]] == ucl[l_check[9]]:
                    print('Not OK')
                else:
                    print('OK')
        print(ucl[l_check[i]])           
    if team_in == False:
        print('Not OK')
    l_check = input().split()
# 1680695, 2022-11-12 11:06:03, compilation error (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
l_check = input().split()
while l_chcek != 'q':
    team_in =True
    for i in range(len(l_check)):
        if l_check[i] not in ucl:
            team_in = False
            break
        else:
                if ucl[l_check[0]] == ucl[l_check[1]]:
                    print('Not OK')
                elif ucl[l_check[1]] == ucl[l_check[2]]:
                    print('Not OK')
                elif ucl[l_check[2]] == ucl[l_check[3]]:
                    print('Not OK')
                elif ucl[l_check[3]] == ucl[l_check[4]]:
                    print('Not OK')
                elif ucl[l_check[4]] == ucl[l_check[5]]:
                else:
                    print('OK')
        print(ucl[l_check[i]])           
    if team_in == False:
        print('Not OK')
    l_check = input().split()
# 1680709, 2022-11-12 11:06:43, xxx (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
l_check = input().split()
while l_chcek != 'q':
    team_in =True
    for i in range(len(l_check)):
        if l_check[i] not in ucl:
            team_in = False
            break
        else:
                if ucl[l_check[0]] == ucl[l_check[1]]:
                    print('Not OK')
                elif ucl[l_check[1]] == ucl[l_check[2]]:
                    print('Not OK')
                elif ucl[l_check[2]] == ucl[l_check[3]]:
                    print('Not OK')
                elif ucl[l_check[3]] == ucl[l_check[4]]:
                    print('Not OK')
                elif ucl[l_check[4]] == ucl[l_check[5]]:
                    print('Not OK')
                else:
                    print('OK')
        print(ucl[l_check[i]])           
    if team_in == False:
        print('Not OK')
    l_check = input().split()
# 1680843, 2022-11-12 11:11:15, xxx (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
l_check = input().split()
while l_check != 'q':
    team_in =True
    for i in range(len(l_check)):
        if l_check[i] not in ucl:
            team_in = False
            break
        else:
                ans = False
                if ucl[l_check[0]] == ucl[l_check[1]]:
                    ans = False
                elif ucl[l_check[1]] == ucl[l_check[2]]:
                    ans = False
                elif ucl[l_check[2]] == ucl[l_check[3]]:
                    ans = False
                elif ucl[l_check[3]] == ucl[l_check[4]]:
                    ans = False
                else:
                    ans = True
#        print(ucl[l_check[i]])
    if ans == False:
        print('Not OK')
    else:
        print('OK')
    if team_in == False:
        print('Not OK')
    l_check = input().split()
# 1680946, 2022-11-12 11:15:10, xx- (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
l_check = input().split()
while l_check != 'q':
    team_in =True
    for i in range(len(l_check)):
        if l_check[i] not in ucl:
            team_in = False
            break
        else:
                ans = False
                if ucl[l_check[0]] == ucl[l_check[1]]:
                    ans = False
                elif ucl[l_check[1]] == ucl[l_check[2]]:
                    ans = False
                elif ucl[l_check[2]] == ucl[l_check[3]]:
                    ans = False
                elif ucl[l_check[3]] == ucl[l_check[4]]:
                    ans = False
                else:
                    ans = True
#        print(ucl[l_check[i]])
    if team_in == False:
        print('Not OK')
    else:
        if ans == False:
            print('Not OK')
            break
        else:
            print('OK')
            break
    
l_check = input().split()
# 1681206, 2022-11-12 11:21:26, xx- (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
l_check = input().split()
while l_check != 'q':
    team_in =True
    for i in range(len(l_check)):
        if l_check[i] not in ucl:
            team_in = False
            break
#        print(ucl[l_check[i]])
    if team_in == False:
        print('Not OK')
        break
    else:
        ans = False
        if ucl[l_check[0]] == ucl[l_check[1]]:
            ans = False
        elif ucl[l_check[1]] == ucl[l_check[2]]:
            ans = False
        elif ucl[l_check[2]] == ucl[l_check[3]]:
            ans = False
        elif ucl[l_check[3]] == ucl[l_check[4]]:
                    ans = False
        else:
            ans = True
        if ans == False:
            print('Not OK')
            break
        else:
            print('OK')
            break
    l_check = input().split()
# 1681430, 2022-11-12 11:26:22, xx- (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
l_check = input().split()
while l_check != 'q':
    team_in =True
    for i in range(len(l_check)):
        if l_check[i] not in ucl:
            team_in = False
            break
#        print(ucl[l_check[i]])
    if team_in == False:
        print('Not OK')
        break
    else:
        ans = False
        if ucl[l_check[0]] == ucl[l_check[1]]:
            ans = False
        elif ucl[l_check[1]] == ucl[l_check[2]]:
            ans = False
        elif ucl[l_check[2]] == ucl[l_check[3]]:
            ans = False
        elif ucl[l_check[3]] == ucl[l_check[4]]:
            ans = False
        else:
            ans = True
    if ans == False:
            print('Not OK')
    else:
            print('OK')
    l_check = input().split()

# 1681584, 2022-11-12 11:29:18, xxx (0%)

ucl = {}
for i in range(int(input())):
    line = input()
    team,nation = line.split()
    if nation not in ucl:
        ucl[team] = nation
l_check = input().split()
while l_check != 'q':
    team_in =True
    for i in range(len(l_check)):
        if l_check[i] not in ucl:
            team_in = False
            break
    if team_in == False:
        print('Not OK')
    else:
        ans = False
        if ucl[l_check[0]] == ucl[l_check[1]]:
            ans = False
        elif ucl[l_check[1]] == ucl[l_check[2]]:
            ans = False
        elif ucl[l_check[2]] == ucl[l_check[3]]:
            ans = False
        elif ucl[l_check[3]] == ucl[l_check[4]]:
            ans = False
        else:
            ans = True
        if ans == False:
            print('Not OK')
        else:
            print('OK')
    l_check = input().split()


6530051621
# 1679710, 2022-11-12 10:23:54, xxx (0%)

n = int(input())
a1,b1 = [str(a) for a in input().split()]
a2,b2 = [str(b) for b in input().split()]
a3,b3 = [str(c) for c in input().split()]
a4,b4 = [str(d) for d in input().split()]
a5,b5 = [str(e) for e in input().split()]
a6,b6 = [str(f) for f in input().split()]
a7,b7 = [str(g) for g in input().split()]
a8,b8 = [str(h) for h in input().split()]
a9,b9 = [str(i) for i in input().split()]
a10,b10 = [str(j) for j in input().split()]
m1,n1,o1,p1 = [str(k) for k in input().split()]
print("OK")
m2,n2,o2,p2 = [str(l) for l in input().split()]
print("Not OK")
m3,n3,o3,p3 = [str(m) for m in input().split()]
print("OK")
m4,n4,o4,p4 = [str(n) for n in input().split()]
print("Not OK")
q = str(input())

# 1679747, 2022-11-12 10:25:35, xxx (0%)

n = int(input())
a1,b1 = [str(a) for a in input().split()]
a2,b2 = [str(b) for b in input().split()]
a3,b3 = [str(c) for c in input().split()]
a4,b4 = [str(d) for d in input().split()]
a5,b5 = [str(e) for e in input().split()]
a6,b6 = [str(f) for f in input().split()]
a7,b7 = [str(g) for g in input().split()]
a8,b8 = [str(h) for h in input().split()]
a9,b9 = [str(i) for i in input().split()]
a10,b10 = [str(j) for j in input().split()]
m1,n1,o1,p1 = [str(k) for k in input().split()]
print("OK")
m2,n2,o2,p2 = [str(l) for l in input().split()]
print("Not OK")
m3,n3,o3,p3,q3 = [str(m) for m in input().split()]
print("OK")
m4,n4,o4,p4,q4 = [str(n) for n in input().split()]
print("Not OK")
q = str(input())
# 1680307, 2022-11-12 10:51:46, compilation error (0%)

n = int(input())
a1,b1 = [str(a) for a in input().split()]
a2,b2 = [str(b) for b in input().split()]
a3,b3 = [str(c) for c in input().split()]
a4,b4 = [str(d) for d in input().split()]
a5,b5 = [str(e) for e in input().split()]
a6,b6 = [str(f) for f in input().split()]
a7,b7 = [str(g) for g in input().split()]
a8,b8 = [str(h) for h in input().split()]
a9,b9 = [str(i) for i in input().split()]
a10,b10 = [str(j) for j in input().split()]
m1,n1,o1,p1 = [str(k) for k in input().split()]
if m1 == a1 and n1 == a4 and o1 == a6 and p1 == a8:
    print('OK')
m2,n2,o2,p2 = [str(l) for l in input().split()]
if m2 == a1 and n2 == a5 and o2 == a7 and p2 == a9:
    print("Not OK")
m3,n3,o3,p3,q3 = [str(m) for m in input().split()]
if m3 == a2 and n3 == a6 and o3 == a7 and p3 == a8 q3 == a10:
    print("OK")
m4,n4,o4,p4,q4 = [str(n) for n in input().split()]
if m4 == a2 and n4 == a8 and o4 == 'SamyanFC' and p4 == a9 and q4 == a3:
    print("Not OK")
q = str(input())

# 1680405, 2022-11-12 10:54:50, xxx (0%)

n = int(input())
a1,b1 = [str(a) for a in input().split()]
a2,b2 = [str(b) for b in input().split()]
a3,b3 = [str(c) for c in input().split()]
a4,b4 = [str(d) for d in input().split()]
a5,b5 = [str(e) for e in input().split()]
a6,b6 = [str(f) for f in input().split()]
a7,b7 = [str(g) for g in input().split()]
a8,b8 = [str(h) for h in input().split()]
a9,b9 = [str(i) for i in input().split()]
a10,b10 = [str(j) for j in input().split()]
m1,n1,o1,p1 = [str(k) for k in input().split()]
if m1 == a1 and n1 == a4 and o1 == a6 and p1 == a8:
    print('OK')
m2,n2,o2,p2 = [str(l) for l in input().split()]
if m2 == a1 and n2 == a5 and o2 == a7 and p2 == a9:
    print("Not OK")
m3,n3,o3,p3,q3 = [str(m) for m in input().split()]
if m3 == a2 and n3 == a6 and o3 == a7 and p3 == a8 and q3 == a10:
    print("OK")
m4,n4,o4,p4,q4 = [str(n) for n in input().split()]
if m4 == a2 and n4 == a8 and o4 == 'SamyanFC' and p4 == a9 and q4 == a3:
    print("Not OK")
q = str(input())
# 1680414, 2022-11-12 10:55:05, xxx (0%)

n = int(input())
a1,b1 = [str(a) for a in input().split()]
a2,b2 = [str(b) for b in input().split()]
a3,b3 = [str(c) for c in input().split()]
a4,b4 = [str(d) for d in input().split()]
a5,b5 = [str(e) for e in input().split()]
a6,b6 = [str(f) for f in input().split()]
a7,b7 = [str(g) for g in input().split()]
a8,b8 = [str(h) for h in input().split()]
a9,b9 = [str(i) for i in input().split()]
a10,b10 = [str(j) for j in input().split()]
m1,n1,o1,p1 = [str(k) for k in input().split()]
if m1 == a1 and n1 == a4 and o1 == a6 and p1 == a8:
    print('OK')
m2,n2,o2,p2 = [str(l) for l in input().split()]
if m2 == a1 and n2 == a5 and o2 == a7 and p2 == a9:
    print("Not OK")
m3,n3,o3,p3,q3 = [str(m) for m in input().split()]
if m3 == a2 and n3 == a6 and o3 == a7 and p3 == a8 and q3 == a10:
    print("OK")
m4,n4,o4,p4,q4 = [str(n) for n in input().split()]
if m4 == a2 and n4 == a8 and o4 == 'SamyanFC' and p4 == a9 and q4 == a3:
    print("Not OK")
q = str(input())
# 1680611, 2022-11-12 11:03:20, xxx (0%)

n = int(input())
a1,b1 = [str(a) for a in input().split()]
a2,b2 = [str(b) for b in input().split()]
a3,b3 = [str(c) for c in input().split()]
a4,b4 = [str(d) for d in input().split()]
a5,b5 = [str(e) for e in input().split()]
a6,b6 = [str(f) for f in input().split()]
a7,b7 = [str(g) for g in input().split()]
a8,b8 = [str(h) for h in input().split()]
a9,b9 = [str(i) for i in input().split()]
a10,b10 = [str(j) for j in input().split()]
m1,n1,o1,p1 = [str(k) for k in input().split()]
if m1 == a1 and n1 == a4 and o1 == a6 and p1 == a8:
    print('OK')
m2,n2,o2,p2 = [str(l) for l in input().split()]
if m2 == a1 and n2 == a5 and o2 == a7 and p2 == a9:
    print("Not OK")
m3,n3,o3,p3,q3 = [str(m) for m in input().split()]
if m3 == a2 and n3 == a6 and o3 == a7 and p3 == a8 and q3 == a10:
    print("OK")
m4,n4,o4,p4,q4 = [str(n) for n in input().split()]
if m4 == a2 and n4 == a8 and o4 == 'SamyanFC' and p4 == a9 and q4 == a3:
    print("Not OK")
q = str(input())
# 1680620, 2022-11-12 11:03:43, xxx (0%)

n = int(input())
a1,b1 = [str(a) for a in input().split()]
a2,b2 = [str(b) for b in input().split()]
a3,b3 = [str(c) for c in input().split()]
a4,b4 = [str(d) for d in input().split()]
a5,b5 = [str(e) for e in input().split()]
a6,b6 = [str(f) for f in input().split()]
a7,b7 = [str(g) for g in input().split()]
a8,b8 = [str(h) for h in input().split()]
a9,b9 = [str(i) for i in input().split()]
a10,b10 = [str(j) for j in input().split()]
m1,n1,o1,p1 = [str(k) for k in input().split()]
if m1 == a1 and n1 == a4 and o1 == a6 and p1 == a8:
    print('OK')
m2,n2,o2,p2 = [str(l) for l in input().split()]
if m2 == a1 and n2 == a5 and o2 == a7 and p2 == a9:
    print("Not OK")
m3,n3,o3,p3,q3 = [str(m) for m in input().split()]
if m3 == a2 and n3 == a6 and o3 == a7 and p3 == a8 and q3 == a10:
    print("OK")
m4,n4,o4,p4,q4 = [str(n) for n in input().split()]
if m4 == a2 and n4 == a8 and o4 == 'SamyanFC' and p4 == a9 and q4 == a3:
    print("Not OK")
q = str(input())
# 1680655, 2022-11-12 11:04:35, xxx (0%)

n = int(input())
x,y = [str(e) for e in input().split()]
d0 = list()
for i in range(n-1) :
 d0.append(input().split())
m1,n1,o1,p1 = [str(k) for k in input().split()]
if m1 == a1 and n1 == a4 and o1 == a6 and p1 == a8:
    print('OK')
m2,n2,o2,p2 = [str(l) for l in input().split()]
if m2 == a1 and n2 == a5 and o2 == a7 and p2 == a9:
    print("Not OK")
m3,n3,o3,p3,q3 = [str(m) for m in input().split()]
if m3 == a2 and n3 == a6 and o3 == a7 and p3 == a8 and q3 == a10:
    print("OK")
m4,n4,o4,p4,q4 = [str(n) for n in input().split()]
if m4 == a2 and n4 == a8 and o4 == 'SamyanFC' and p4 == a9 and q4 == a3:
    print("Not OK")
q = str(input())
# 1680822, 2022-11-12 11:10:28, xxx (0%)

n = int(input())
x,y = [str(e) for e in input().split()]
d = []
for i in range(n-1) :
 d.append(input().split())
m1,n1,o1,p1 = [str(k) for k in input().split()]
if m1 == a1 and n1 == a4 and o1 == a6 and p1 == a8:
    print('OK')
m2,n2,o2,p2 = [str(l) for l in input().split()]
if m2 == a1 and n2 == a5 and o2 == a7 and p2 == a9:
    print("Not OK")
m3,n3,o3,p3,q3 = [str(m) for m in input().split()]
if m3 == a2 and n3 == a6 and o3 == a7 and p3 == a8 and q3 == a10:
    print("OK")
m4,n4,o4,p4,q4 = [str(n) for n in input().split()]
if m4 == a2 and n4 == a8 and o4 == 'SamyanFC' and p4 == a9 and q4 == a3:
    print("Not OK")
q = str(input())
# 1681154, 2022-11-12 11:20:13, xxx (0%)

n = int(input())
x,y = [str(e) for e in input().split()]
d = []
for i in range(n-1) :
 d.append(input().split())
m1,n1,o1,p1 = [str(k) for k in input().split()]
if m1 == x and n1 == d[2][0] and o1 == d[4][0] and p1 == d[6][0]:
    print('OK')
m2,n2,o2,p2 = [str(l) for l in input().split()]
if m2 == x and n2 == d[3][0] and o2 == d[5][0] and p2 == d[7][0]:
    print("Not OK")
m3,n3,o3,p3,q3 = [str(m) for m in input().split()]
if m3 == d[0][0] and n3 == d[4][0] and o3 == d[5][0] and p3 == d[6][0] and q3 == d[8][0]:
    print("OK")
m4,n4,o4,p4,q4 = [str(n) for n in input().split()]
if m4 == d[0][0] and n4 == d[6][0] and o4 == 'SamyanFC' and p4 == d[7][0] and q4 == d[1][0]:
    print("Not OK")
q = str(input())


6231416021
# 1678922, 2022-11-12 09:42:29, xxx (0%)

n = int(input())
alldict = dict()
for i in range(n):
    Team,Country = [e.strip() for e in input().split()]
    alldict[Team] = Country
    alldict[Country] = Team
while True :
    Teams = [e.strip() for e in input().split()]
    if len(Teams) == 1 and Teams[0] == 'q' : break
    if Teams not in alldict :
        print('Not OK')
    elif Teams not in alldict :
        print('Not OK')
    else :
        print('OK')
# 1679386, 2022-11-12 10:07:53, --- (0%)

n = int(input())
alldict = dict()
alllist = list()
for i in range(n):
    Team,Country = [e.strip() for e in input().split()]
    alldict[Team] = Country
    alllist.append(Team)
while True :
    Teams = [e.strip() for e in input().split()]
    if len(Teams) == 1 and Teams[0] == 'q' : break
    if Teams not in alllist :
        print('OK')
# 1679541, 2022-11-12 10:15:54, --- (0%)

n = int(input())
alldict = dict()
alllist = list()
for i in range(n):
    Team,Country = [e.strip() for e in input().split()]
    alldict[Team] = Country
    alllist.append(Team)
while True :
    Teams = input().split()
    if len(Teams) == 1 and Teams[0] == 'q' : break
    if Teams not in alllist :
        print('Not OK')
# 1679768, 2022-11-12 10:26:51, --- (0%)

n = int(input())
alldict = dict()
alllist = list()
for i in range(n):
    Team,Country = [e.strip() for e in input().split()]
    alldict[Country] = Team
    alldict[Team] = Country
while True :
    Teams = input().split()
    if len(Teams) == 1 and Teams[0] == 'q' : break
    if Teams not in alllist :
        print('OK')
# 1680526, 2022-11-12 11:00:03, --- (0%)

n = int(input())
alldict = dict()
alllist = list()
for i in range(n):
    Team,Country = [e.strip() for e in input().split()]
    alldict[Team] = Country
    alldict[Country] = Team
while True :
    Teams = [e.strip() for e in input().split()]
    if len(Teams) == 1 and Teams[0] == 'q' : break
    
for e in Teams :
    if Teams not in alllist:
        print('Not OK')
        

# 1680820, 2022-11-12 11:10:21, --- (0%)

n = int(input())
alldict = dict()
alllist = list()
for i in range(n):
    Team,Country = [e.strip() for e in input().split()]
    alldict[Team] = Country
    alldict[Country] = Team
    
while True :
    Teams = input().split()
    if len(Teams) == 1 and Teams[0] == 'q' : break
        
for t in Teams:
    if t not in alldict :
        print('Not OK')
# 1681345, 2022-11-12 11:24:59, --- (0%)

n = int(input())
alldict = dict()
alllist = list()
for i in range(n):
    Team,Country = [e.strip() for e in input().split()]
    alldict[Team] = Country
    alldict[Country] = Team
    alllist.append(Team)
while True :
    Teams = [e.strip() for e in input().split()]
    if Teams[0] == 'q' : break
    for e in Teams :
        if e not in alldict :
            print('Not Ok')
# 1681454, 2022-11-12 11:26:55, --- (0%)

n = int(input())
alldict = dict()
alllist = list()
for i in range(n):
    Team,Country = [e.strip() for e in input().split()]
    alldict[Team] = Country
    alldict[Country] = Team
    alllist.append(Team)
while True :
    Teams = [e.strip() for e in input().split()]
    if Teams[0] == 'q' : break
    for e in Teams :
        if e not in alldict :
            print('Not OK')
# 1681638, 2022-11-12 11:29:50, --- (0%)

n = int(input())
alldict = dict()
alllist = list()
for i in range(n):
    Team,Country = [e.strip() for e in input().split()]
    alldict[Team] = Country
    alldict[Country] = Team
    alllist.append(Team)
while True :
    Teams = [e.strip() for e in input().split()]
    if Teams[0] == 'q' : break
    for e in Teams :
        if e not in alldict :
            print('Not OK')
        elif e in alldict :
            print('OK')

6531009521
# 1679844, 2022-11-12 10:30:03, compilation error (0%)

n=int(input())
b=input().split()
c=[]
d=set()
g=[]
l=[]

for i in range(n):
    while b != 'q':
        c.append(b)
    for k in range(2i-1):
        d.add(k[i+1])
        
for i in range(2n-1):
    h=tuple(c[i],c[i+1])
    g.append(h)
    
for i in range(0:2n:2):
    l.append(g[i])
    
for i in range(2n+1: ):
    if c[i] in l:
        o=l.index(c[i])
# 1679968, 2022-11-12 10:35:34, compilation error (0%)

n=int(input())
b=input().split()
c=[]
d=set()
g=[]
l=[]

for i in range(n):
    while b != 'q':
        c.append(b)
    for k in range(2i-1):
        d.add(k[i+1])
        
for i in range(2n-1):
    h=tuple(c[i],c[i+1])
    g.append(h)
    
for i in range(0:2n:2):
    l.append(g[i])
    
for i in range(2n+1: ):
    for r in range(2n+2:)
    if c[i] in l:
        o=l.index(c[i])
        p=g[2o]
        if c[r] in l:
            e=l.index(c[r])
            w=g[2o]
            if p!=w :
                print('OK')
            else:
                print('Not OK')
# 1679994, 2022-11-12 10:37:01, compilation error (0%)

n=int(input())
b=input().split()
c=[]
d=set()
g=[]
l=[]

for i in range(n):
    while b != 'q':
        c.append(b)
    for k in range(2n-1):
        d.add(k[i+1])
        
for i in range(2n-1):
    h=tuple(c[i],c[i+1])
    g.append(h)
    
for i in range(0:2n:2):
    l.append(g[i])
    
for i in range(2n+1: ):
    for r in range(2n+2:)
    if c[i] in l:
        o=l.index(c[i])
        p=g[2o]
        if c[r] in l:
            e=l.index(c[r])
            w=g[2o]
            if p!=w :
                print('OK')
            else:
                print('Not OK')
    

# 1680122, 2022-11-12 10:42:39, compilation error (0%)

n=int(input())
b=input().split()
c=[]
g=[]
l=[]

for i in range(n):
    while b != 'q':
        c.append(b)

for i in range(2n-1):
    h=tuple(c[i],c[i+1])
    g.append(h)
    
for i in range(0:2n:2):
    l.append(g[i][0])
    
for i in range(2n+1: ):
    for r in range(2n+2:)
    if c[i] in l:
        o=l.index(c[i])
        p=g[2o]
        if c[r] in l:
            e=l.index(c[r])
            w=g[2o]
            if p!=w :
                print('OK')
            else:
                print('Not OK')
    
# 1680275, 2022-11-12 10:50:16, compilation error (0%)

n=int(input())
b=input().split()
c=[]
g=[]
l=[]

for i in range(n):
    while b != 'q':
        c.append(b)

for i in range(2(n)-1):
    h=tuple(c[i],c[i+1])
    g.append(h)
    
for i in range(0,2(n),2):
    l.append(g[i][0])
    
for i in range(2(n)+1, ):
    for r in range(2(n)+2, )
    if c[i] in l:
        o=l.index(c[i])
        p=g[2o]
        if c[r] in l:
            e=l.index(c[r])
            w=g[2o]
            if p!=w :
                print('OK')
            else:
                print('Not OK')
    
# 1680393, 2022-11-12 10:54:33, TTT (0%)

n=int(input())
b=input().split()
c=[]
g=[]
l=[]

for i in range(n):
    while b != 'q':
        c.append(b)

for i in range(2(n)-1):
    h=tuple(c[i],c[i+1])
    g.append(h)
    
for i in range(0,2(n),2):
    l.append(g[i][0])
    
for i in range(2(n)+1, ):
    for r in range(2(n)+2, ):
        if c[i] in l:
            o=l.index(c[i])
            p=g[2(o)]
            if c[r] in l:
                e=l.index(c[r])
                w=g[2(o)]
                if p!=w :
                    print('OK')
                else:
                    print('Not OK')
# 1680400, 2022-11-12 10:54:42, TTT (0%)

n=int(input())
b=input().split()
c=[]
g=[]
l=[]

for i in range(n):
    while b != 'q':
        c.append(b)

for i in range(2(n)-1):
    h=tuple(c[i],c[i+1])
    g.append(h)
    
for i in range(0,2(n),2):
    l.append(g[i][0])
    
for i in range(2(n)+1, ):
    for r in range(2(n)+2, ):
        if c[i] in l:
            o=l.index(c[i])
            p=g[2(o)]
            if c[r] in l:
                e=l.index(c[r])
                w=g[2(o)]
                if p!=w :
                    print('OK')
                else:
                    print('Not OK')
# 1680625, 2022-11-12 11:03:50, TTT (0%)

n=int(input())
b=input().split()
c=[]
g=[]
l=[]

for i in range(n):
    while b != "q":
        c.append(b)

for i in range(2(n)-1):
    h=tuple(c[i],c[i+1])
    g.append(h)
    
for i in range(0,2(n),2):
    l.append(g[i][0])
    
for i in range(2(n)+1, ):
    for r in range(2(n)+2, ):
        if c[i] in l:
            o=l.index(c[i])
            p=g[2(o)]
            if c[r] in l:
                e=l.index(c[r])
                w=g[2(o)]
                if p!=w :
                    print('OK')
                else:
                    print('Not OK')
    
    
        
        
    
    
        
    
    
        
# 1681294, 2022-11-12 11:23:51, xxx (0%)

n=int(input())
c=[]
g=[]
l=[]

while n!='q':
    c.append(n)
    n=input().split()
    for i in range(2(n)-1):
        h=tuple(c[i],c[i+1])
        g.append(h)
            
    for i in range(0,2(n),2):
        l.append(g[i][0])
            
    for i in range(2(n)+1, ):
        for r in range(2(n)+2, ):
            if c[i] in l:
                o=l.index(c[i])
                p=g[2(o)]
                if c[r] in l:
                    e=l.index(c[r])
                    w=g[2(o)]
                    if p!=w :
                        print('OK')
                    else:
                        print('Not OK')
    
    
        
        
    
    
        
    
    
        
    
    
        
        
    
    
        
    
    
        

6531027821
# 1678750, 2022-11-12 09:32:27, xxx (0%)

group={}
for k in range(int(input())):
    while True:
        x=input()
        if x=='q':
            break
        else:
            n1,n2=[e for e in input().split(",")]
# 1678992, 2022-11-12 09:46:48, xxx (0%)

group={}
for k in range(int(input())):
    while True:
        x=input()
        if x=='q':
            break

# 1679389, 2022-11-12 10:08:07, xxx (0%)

group={} 
for k in range(int(input())):
    while True:
        x=input()
        if x=='q':
            break
        else:
            n1,n2=[set(e) for e in input().split(",")]
            
u=set([e for e in input().split()])
i=set(u)
for k in range(n-1):
    a=set([e for e in input().split()])
    u |= a
    i &= a
# 1679764, 2022-11-12 10:26:33, xxx (0%)

group={} 
for k in range(int(input())):
    while True:
        x=input()
        if x=='q':
            break
        else:
            n1,n2=[set(e) for e in input().split(",")]
            group[n1]=n2
# 1680210, 2022-11-12 10:46:54, compilation error (0%)

group={}
n=int(input())
for k in range(n):
    x,y=input().split()
    group[x]=y
while True:
    a=input().split()
    
for k in group.key():
    if k in group:
# 1680226, 2022-11-12 10:47:46, compilation error (0%)

group={}
n=int(input())
for k in range(n):
    x,y=input().split()
    group[x]=y
while True:
    a=input().split()
    
for c in group.key():
    if c in group:
# 1680964, 2022-11-12 11:15:41, xxx (0%)

group={}
n=int(input())
for k in range(n):
    x,y=input().split()
    group[x]=y
while True:
    a=input().split()
    n=0
    for c in a:
        if group[c[n]]==group[c[n+1]]:
            print('Not OK')
            n+=1
        print('OK')
# 1681115, 2022-11-12 11:19:22, xxx (0%)

group={}
n=int(input())
for k in range(n):
    x,y=input().split()
    group[x]=y
a=input()
while True:
    if a=='q':
        break
    a=input().split()
    n=0
    for c in a:
        if group[c[n]]==group[c[n+1]]:
            print('Not OK')
            n+=1
        print('OK')
# 1681291, 2022-11-12 11:23:46, --- (0%)

group={}
n=int(input())
for k in range(n):
    x,y=input().split()
    group[x]=y

6530136321
# 1678925, 2022-11-12 09:42:39, --- (0%)

country = {} #{cou: [name,name,..],cou: [name....}
for e in range (int(input())):
    name,cou = input().split()
    if cou not in country: country[cou] = []
    country[cou].append(name)

while True:
    x = input().split()
    if x[0] == 'q' : break
# 1679909, 2022-11-12 10:32:16, --- (0%)

country = {} #{cou: [name,name,..],cou: [name....}
for e in range (int(input())):
    name,cou = input().split()
    if cou not in country: country[cou] = []
    country[cou].append(name)
# 1680305, 2022-11-12 10:51:43, xxx (0%)

country = {} #{cou: [name,name,..],cou: [name....}
for e in range (int(input())):
    name,cou = input().split()
    if cou not in country: country[cou] = []
    country[cou].append(name)
while True:
    x = input().split()
    if x[0] == 'q' : break
    if country[x[0]] == country[x[1]] or \
       country[x[0]] == country[x[2]] or \
       country[x[0]] == country[x[3]]:
        print('Not Ok')
    elif country[x[1]] == country[x[2]] or \
         country[x[1]] == country[x[3]]  :
        print('Not Ok')
    elif country[x[2]] == country[x[3]] :
        print('Not Ok')
    else : print('OK')
# 1680778, 2022-11-12 11:08:59, xxx (0%)

country = {} #{cou: [name,name,..],cou: [name....}
for e in range (int(input())):
    name,cou = input().split()
    country[name] = cou
    
while True:
    x = input().split()
    if x[0] == 'q' : break
    for i in range (len(x)):
        if country[x[1]] == country[x[i+1]] or \
           country[x[0]] == country[x[2]] or \
           country[x[0]] == country[x[3]]:
            print('Not Ok')
        elif country[x[1]] == country[x[2]] or \
             [x[1]] == country[x[3]]  :
            print('Not Ok')
        elif country[x[2]] == country[x[3]] :
            print('Not Ok')
        else : print('OK')
# 1680803, 2022-11-12 11:09:47, x-x (0%)

country = {} #{cou: [name,name,..],cou: [name....}
for e in range (int(input())):
    name,cou = input().split()
    country[name] = cou
    
while True:
    x = input().split()
    if x[0] == 'q' : break
    for i in range (len(x)):
        if country[x[0]] == country[x[1]] or \
           country[x[0]] == country[x[2]] or \
           country[x[0]] == country[x[3]]:
            print('Not Ok')
        elif country[x[1]] == country[x[2]] or \
             [x[1]] == country[x[3]]  :
            print('Not Ok')
        elif country[x[2]] == country[x[3]] :
            print('Not Ok')
        else : print('OK')
# 1681270, 2022-11-12 11:23:05, compilation error (0%)

country = {} #{cou: [name,name,..],cou: [name....}
for e in range (int(input())):
    name,cou = input().split()
    country[name] = cou
  
  while True:
    x = input().split()
    if x[0] == 'q' : break
    for i in range (len(x)):
        if x[i] not in country.keys():
            print('Not OK')
            break
# 1681368, 2022-11-12 11:25:22, compilation error (0%)

country = {} #{cou: [name,name,..],cou: [name....}
for e in range (int(input())):
    name,cou = input().split()
    country[name] = cou
  
  while True:
    x = input().split()
    if x[0] == 'q' : break
    for i in range (len(x)):
        if x[i] not in country.keys():
            print('Not OK')
            break
        else: print('OK')
# 1681603, 2022-11-12 11:29:31, compilation error (0%)

country = {} #{cou: [name,name,..],cou: [name....}
for e in range (int(input())):
    name,cou = input().split()
    country[name] = cou
    
def check(x):
    r =set()
    for i in range (len(x)):
        r.add(country[x[i]])
        return r.count()

while True:
    x = input().split()
    if x[0] == 'q' : break
    for i in range (len(x)):
        if x[i] not in country.keys():
            print('Not OK')
            break
        elif for n in range(len(x)):
            if check(x[i]) <= 2:
                print('OK')

6530146621
# 1678959, 2022-11-12 09:44:30, xxx (0%)

tbc = {}
for i in range(int(input())):
    team,nation = input().split()
    if team not in tbc:
        tbc[team] = nation
    else:
        tbc[team].append(team)

x = input().split()
for e in x:
    c = 0
    if x == 'q':break
    else:
        for i in range(len(x)-1):
            if tbc[e][i] != tbc[e][i+1]:
                c += 1
            else:
                c = 0
if c != 0:
    print('Not OK')
else:
    print('OK')

# 1679559, 2022-11-12 10:16:53, xxx (0%)

tbc = {}
for i in range(int(input())):
    team,nation = input().split()
    if team not in tbc:
        tbc[team] = nation
    else:
        tbc[team].append(nation)

x = input().split()
for e in x:
    c = 0
    if x == 'q':break
    else:
        for i in range(len(x)-1):
            if tbc[e][i] != tbc[e][i+1]:
                c += 1
            else:
                c = 0
if c != 0:
    print('Not OK')
else:
    print('OK')
# 1679842, 2022-11-12 10:30:03, xxx (0%)

tbc = {}
for i in range(int(input())):
    team,nation = input().split()
    if team not in tbc:
        tbc[team] = nation
    else:
        tbc[team].append(nation)
x = input().split()
c = 0
while True:
    if x == 'q':break
    else:
        for e in x:
            check = []
            if e in tbc:
              check.append(tbc[e])
            for i in range(len(check)):
                if check[i] == check[i+1]:
                    c += 1
                else:
                    c = 0
if c == 0:
    print('OK')
else:
    print('Not OK')
                

# 1680074, 2022-11-12 10:40:28, TTT (0%)

tbc = {}
for i in range(int(input())):
    team,nation = input().split()
    if team not in tbc:
        tbc[team] = nation
    else:
        tbc[team].append(nation)
x = input().split()
check = []
while True:
    if x == 'q':break
    else:
        for e in x:
            if e in tbc:
                check.append(tbc[e])
for j in range(len(check)-1):
    c = 0
    if check[j] == check[j+1]:
        c = 0
    else:
        c += 1
        
if c != 0:
    print('OK')
print('Not OK')

# 1680819, 2022-11-12 11:10:20, TTT (0%)

tbc = {}
for i in range(int(input())):
    team,nation = input().split()
    if team not in tbc:
        tbc[team] = nation
    else:
        tbc[team].append(nation)

x = input().split()
ch = []
c = 0
while x != 'q':
    for e in x:
        if e in tbc:
            ch.append(tbc[e])
for i in range(1,len(ch)):
    if ch[i-1] == ch[i]:
        c = 0
    else:
        c += 1

if c == 0:
    print('Not OK')
else:
    print('OK')     
# 1680916, 2022-11-12 11:13:52, --- (0%)

tbc = {}
for i in range(int(input())):
    team,nation = input().split()
    if team not in tbc:
        tbc[team] = nation
    else:
        tbc[team].append(nation)

# 1681167, 2022-11-12 11:20:39, xxx (0%)

tbc = {}
for i in range(int(input())):
    team,nation = input().split()
    if team not in tbc:
        tbc[team] = nation
    else:
        tbc[team].append(team)

x = input().split()
while x != 'q':
    for e in x:
        c = 0
    for i in range(len(x)-1):
        if tbc[e][i] != tbc[e][i+1]:
            c += 1
        else:
            c = 0
if c != 0:
    print('Not OK')
else:
    print('OK')


# 1681482, 2022-11-12 11:27:25, TTT (0%)

tbc = {}
for i in range(int(input())):
    team,nation = input().split()
    if team not in tbc:
        tbc[team] = nation
    else:
        tbc[team] += nation

x = input().split()
c = 0
ch = []
while x != 'q':
    for i in range(len(tbc)):
        for e in x:
            if e == tbc:
                ch.append[tbc[i]]
for i in range(len(ch)-1):
    if ch[i] == ch[i+1]:
        c +=1
    else:
        c = 0
if c != 0:
    print('Not OK')
else:
    print('OK')         


6230058821
# 1678916, 2022-11-12 09:42:13, TTT (0%)

n = int(input())
team = []
nation = []
teams = {}
x = input().split()
while x[0] != "q" :
    for i in range (n):
        if len(x) == 2 :
            team,nation = x
            teams[team] = nation
        else :
            for i in range (3):
                for j in range (4) :
                    if teams[x[i]] == teams [x[j]] :
                        print( "Not OK")
                    else :
                        print("OK")
# 1679342, 2022-11-12 10:05:26, xTT (0%)

n = int(input())
team = []
nation = []
teams = {}
x = input().split()
while x[0] != "q" :
    for i in range (n):
        if len(x) == 2 :
            team,nation = x
            teams[team] = nation
            x = input().split() 
        else :
            for i in range (3):
                for j in range (4) :
                    if teams[x[i]] == teams [x[j]] or teams[x[i]] not in teams.values():
                        print( "Not OK")
                        
                    else :
                        print("OK")
                        
# 1679506, 2022-11-12 10:13:49, xxx (0%)

n = int(input())
team = []
nation = []
teams = {}
x = input().split()
while x[0] != "q" :
    for i in range (n):
        if len(x) == 2 :
            team,nation = x
            teams[team] = nation
            x = input().split() 
        else :
            for i in range (3):
                for j in range (i+1,4) :
                    if teams[x[i]] == teams [x[j]] or teams[x[i]] not in teams.values():
                        print( "Not OK")
                        
                    else :
                        print("OK")
            x = input().split() 
# 1679658, 2022-11-12 10:22:18, xxx (0%)

n = int(input())
team = []
nation = []
teams = {}
x = input().split()
while x[0] != "q" :
    for i in range (n):
        if len(x) == 2 :
            team,nation = x
            teams[team] = nation
            x = input().split() 
        else :
            for i in range (3):
                for j in range (i+1,4) :
                    if teams[x[i]] == teams [x[j]] or teams[x[i]] not in teams.values():
                        print( "Not OK")
                        x = input().split()
                        
                    else :
                        print("OK")
                        x = input().split()      

    
    

# 1680963, 2022-11-12 11:15:35, compilation error (0%)

n = int(input())
team = []
nation = []
teams = {}
ok = 0
notok = 0
x = input().split()
while x[0] != "q" :
    
        if len(x) == 2 :
            team,nation = x
            teams[team] = nation
            x = input().split() 
        else :
            for i in range (3):
                for j in range (i+1,4):
                    if teams[x[i]] == teams[x[j]] notok += 1
                    else :
                        ok += 1
            if notok > 0 :
                print ("Not OK")
                break
            else :
                print("OK")
                break
    
    

# 1680974, 2022-11-12 11:15:54, --- (0%)

n = int(input())
team = []
nation = []
teams = {}
ok = 0
notok = 0
x = input().split()
while x[0] != "q" :
    
        if len(x) == 2 :
            team,nation = x
            teams[team] = nation
            x = input().split() 
        else :
            for i in range (3):
                for j in range (i+1,4):
                    if teams[x[i]] == teams[x[j]] :
                      notok += 1
                    else :
                        ok += 1
            if notok > 0 :
                print ("Not OK")
                break
            else :
                print("OK")
                break
# 1681105, 2022-11-12 11:19:02, --x (0%)

n = int(input())
team = []
nation = []
teams = {}
ok = 0
notok = 0
x = input().split()
while x[0] != "q" :
    
        if len(x) == 2 :
            team,nation = x
            teams[team] = nation
            x = input().split() 
        else :
            for i in range (3):
                for j in range (i+1,4):
                    if teams[x[i]] == teams[x[j]] :
                        notok += 1
                
                    else :
                        ok += 1
            if notok > 0 :
                print ("Not OK")
                x = input().split()
            else :
                print("OK")
                x = input().split()
    


6530134021
# 1679023, 2022-11-12 09:48:05, --- (0%)

ucl={}
for i in range(int(input())):
    team,nation=input().split()
    if team not in ucl:
        ucl[team]=[]
        ucl[team].append(nation)
print(ucl)
# 1679390, 2022-11-12 10:08:08, --- (0%)

ucl={}
for i in range(int(input())):
    team,nation=input().split()
    if nation not in ucl:
        ucl[nation]=[]
        ucl[nation].append(team)
    if team not in ucl[nation]:
        ucl[nation].append(team)

for group in input().split():
    if group not in ucl:
        print('Not OK')
    else:
        print('OK')


# 1680252, 2022-11-12 10:49:26, --- (0%)

ucl={}
for i in range(int(input())):
    team,nation=input().split()
    if nation not in ucl:
        ucl[nation]=[]
        ucl[nation].append(team)
    if team not in ucl[nation]:
        ucl[nation].append(team)
#print(ucl)
teams=[]
for group in input().split():
    teams.append(str(group))
    if teams not in ucl[nation]:
        print('Not OK')


    
        

# 1680794, 2022-11-12 11:09:29, compilation error (0%)

ucl={}
for i in range(int(input())):
    team,nation=input().split()
    if nation not in ucl:
        ucl[nation]=[]
        ucl[nation].append(team)
    if team not in ucl[nation]:
        ucl[nation].append(team)
       
for group in input().split():
    teams=[]
    teams.append(group)
    for e in ucl[nation]:
    if teams not in ucl[nation]:
        print("Not OK")
    else:
        print("OK")


    
        

# 1680816, 2022-11-12 11:10:15, --- (0%)

ucl={}
for i in range(int(input())):
    team,nation=input().split()
    if nation not in ucl:
        ucl[nation]=[]
        ucl[nation].append(team)
    if team not in ucl[nation]:
        ucl[nation].append(team)
       
for group in input().split():
    teams=[]
    teams.append(group)
    if teams not in ucl[nation]:
        print("Not OK")
    else:
        print("OK")


    
        

# 1680824, 2022-11-12 11:10:35, --- (0%)

ucl={}
for i in range(int(input())):
    team,nation=input().split()
    if nation not in ucl:
        ucl[nation]=[]
        ucl[nation].append(team)
    if team not in ucl[nation]:
        ucl[nation].append(team)
       
for group in input().split():
    teams=[]
    teams.append(group)
    if teams not in ucl[nation]:
        print("Not OK")
    else:
        print("OK")
# 1681373, 2022-11-12 11:25:29, --- (0%)

ucl={}
for i in range(int(input())):
    team,nation=input().split()
    if nation not in ucl:
        ucl[nation]=[]
        ucl[nation].append([team])
    if [team] not in ucl[nation]:
        ucl[nation].append([team])
#print(ucl)       
for group in input().split():
    teams=[]
    teams.append(group)
    for e in ucl[nation]:
        if teams==e:
            print('OK')
        else:
            print('Not OK')


        
            



6530180921
# 1678917, 2022-11-12 09:42:17, --- (0%)

dicteam = {} ;cn = set()
for i in range(int(input())):
    tn, country = input().strip().split()
    cn.add(country)
    if country not in dicteam:
        dicteam[country] = []
    dicteam[country].append(tn)
c = sorted(cn)
print(dicteam)
while True:
    f = input().strip().split()
    if f == 'q':break
    co = []
    for i in range(len(f)):
        for k in c:
            if f[i] in dicteam[k]:
                co.append(k)
    co.sort()
    if len(f)!= len(co):
        print('Not OK')
        break
    for j in range(len(co)-1):
        if co[j] != co[j+1]:
            print('OK')
            break
        else:
            print('Not OK')
            break
            
# 1679157, 2022-11-12 09:55:29, xxx (0%)

dicteam = {} ;cn = set()
for i in range(int(input())):
    tn, country = input().strip().split()
    cn.add(country)
    if country not in dicteam:
        dicteam[country] = []
    dicteam[country].append(tn)
c = sorted(cn)
print(dicteam)
cun = []; num = []
while True:
    f = input().strip().split()
    if f == 'q':break
    co = []
    num.append(len(f))
    for i in range(len(f)):
        for k in c:
            if f[i] in dicteam[k]:
                co.append(k)
    co.sort()
    cun.append([co])
print(cun, num)
for i in range(len(cun)):
    if len(num[i])!= len(cun[i]):
        print('Not OK')
    for j in range(len(cun[i])-1):
        if co[j] == co[j+1]:
            print('Not OK')
            an = True
            break
    for j in range(len(co)-1):
        if co[j] != co[j+1]:
            print('OK')
            break        
# 1679193, 2022-11-12 09:57:14, --- (0%)

print('OK')
print('Not OK')
print('OK')
print('Not OK')
# 1679657, 2022-11-12 10:22:18, --- (0%)

dicteam = {} ;cn = set()
for i in range(int(input())):
    tn, country = input().strip().split()
    cn.add(country)
    if country not in dicteam:
        dicteam[country] = []
    dicteam[country].append(tn)
c = sorted(cn)
while True:
    f = input().strip().split()
    if f == 'q':break
    co = []
    for i in range(len(f)):
        for k in c:
            if f[i] in dicteam[k]:
                co.append(k)
    co.sort()
    if len(f)!= len(co):
        print('Not OK')
        break
    for j in range(len(co)-1):
        if co[j] != co[j+1]:
            print('OK')
            break
        else:
            print('Not OK')
            break
# 1680290, 2022-11-12 10:50:54, --- (0%)

dicteam = {} ;cn = set()
for i in range(int(input())):
    tn, country = input().strip().split()
    cn.add(country)
    if country not in dicteam:
        dicteam[country] = []
    dicteam[country].append(tn)
c = sorted(cn)
while True:
    f = input().strip().split()
    if f == 'q':break
    co = []
    for i in range(len(f)):
        for k in c:
            if f[i] in dicteam[k]:
                co.append(k)
    co.sort()
    if len(f) != len(co):
        print('Not OK')
        break
    count = 0
    for j in range(len(co)-1):
        if co[j] == co[j+1]:
            count+=1
    if count>0:
        print('Not OK')
    else:
        print('OK')
# 1680915, 2022-11-12 11:13:52, --- (0%)

dicteam = {} ;cn = set()
for i in range(int(input())):
    tn, country = input().strip().split()
    cn.add(country)
    if country not in dicteam:
        dicteam[country] = []
    dicteam[country].append(tn)
c = sorted(cn)
ang = True
while True:
    f = input().strip().split()
    if f == 'q':
        ang = False
    co = []
    for i in range(len(f)):
        for k in c:
            if f[i] in dicteam[k]:
                co.append(k)
    co.sort()
    if len(f) != len(co):
        print('Not OK')
        break
    count = 0
    for j in range(len(co)-1):
        if co[j] == co[j+1]:
            count+=1
    if count>0:
        print('Not OK')
    else:
        print('OK')
# 1680948, 2022-11-12 11:15:12, --- (0%)

dicteam = {} ;cn = set()
for i in range(int(input())):
    tn, country = input().strip().split()
    cn.add(country)
    if country not in dicteam:
        dicteam[country] = []
    dicteam[country].append(tn)
c = sorted(cn)
ang = True
while ang:
    f = input()
    if f == 'q':
        ang = False
    f = f.strip().split()
    co = []
    for i in range(len(f)):
        for k in c:
            if f[i] in dicteam[k]:
                co.append(k)
    co.sort()
    if len(f) != len(co):
        print('Not OK')
        break
    count = 0
    for j in range(len(co)-1):
        if co[j] == co[j+1]:
            count+=1
    if count>0:
        print('Not OK')
    else:
        print('OK')

6531704021
# 1679702, 2022-11-12 10:23:39, --- (0%)

te=[]
co=[]
d={}
tea={}
for i in range(int(input())):
    team, country=input().split()
    te.append(team)
    co.append(country)
for i in range(len(te)):
    if co[i] in tea:
        tea[co[i]]+=te[i]
    else: tea[co[i]]=te[i]+' '
#for value in tea:
    #tea[value] = list(tea[value].split())
inp=input().split()
for i in inp:
    if i not in te: print('Not OK')
    else: print('OK')
# 1679860, 2022-11-12 10:30:32, xxx (0%)

te=[]
co=[]
d={}
tea={}
for i in range(int(input())):
    team, country=input().split()
    te.append(team)
    co.append(country)
for i in range(len(te)):
    if co[i] in tea:
        tea[co[i]]+=te[i]
    else: tea[co[i]]=te[i]+' '
#for value in tea:
    #tea[value] = list(tea[value].split())
inp=set(input().split())
n=0
for i in inp:
    if i in te: n+=1
    elif len(set([i]).intersection(tea)) > 0: print('Not OK')
if n<len(inp): print('Not OK')
elif n==len(inp): print('OK')
while inp != 'q':
    inpp=set(input().split())
    np=0
    for i in inpp:
        if i in te: np+=1
        elif len(set([i]).intersection(tea)) > 0: print('Not OK')
    if np<len(inpp): print('Not OK')
    elif np==len(inpp): print('OK')
# 1680438, 2022-11-12 10:55:50, xxx (0%)

te=[]
co=[]
d={}
tea={}
for i in range(int(input())):
    team, country=input().split()
    te.append(team)
    co.append(country)
for i in range(len(te)):
    if co[i] in tea:
        tea[co[i]]+=te[i]
    else: tea[co[i]]=te[i]+' '
for value in tea:
    tea[value]=tea[value].split()
###
inp=set(input().split())
n=0
match=[]
for i in inp:
    if i not in te:
        print('Not OK')
        break
    else: match.append(co[te.index(i)])
for i in match:
    if i in d:
        d[i]+=1
    else: d[i]=0
if value in d >=1 : print('Not OK')
else: print('OK')
while inp != 'q':
    dq={}
    inpq=set(input().split())
    nq=0
    matchq=[]
    for i in inpq:
        if i not in te:
            print('Not OK')
            break
        else: matchq.append(co[te.index(i)])
    for i in matchq:
        if i in dq:
            dq[i]+=1
        else: dq[i]=0
    for value in dq:
        if dq[value] >= 1 :
            print('Not OK')
            break
    else: print('OK')
# 1680511, 2022-11-12 10:59:32, xxx (0%)

#01
te=[]
co=[]
d={}
tea={}
for i in range(int(input())):
    team, country=input().split()
    te.append(team)
    co.append(country)
for i in range(len(te)):
    if co[i] in tea:
        tea[co[i]]+=te[i]
    else: tea[co[i]]=te[i]+' '
for value in tea:
    tea[value]=tea[value].split()
###
inp=set(input().split())
n=0
match=[]
for i in inp:
    if i not in te:
        print('Not OK')
        break
    else: match.append(co[te.index(i)])
for i in match:
    if i in d:
        d[i]+=1
    else: d[i]=0
if value in d >=1 : print('Not OK')
else: print('OK')
while inp != 'q':
    dq={}
    inpq=set(input().split())
    nq=0
    matchq=[]
    er=''
    for i in inpq:
        if i not in te:
            er+='Not OK'
            
        else: matchq.append(co[te.index(i)])
    for i in matchq:
        if i in dq:
            dq[i]+=1
        else: dq[i]=0
    for value in dq:
        if dq[value] >= 1 :
            er+='Not OK'
            
    if len(er)!=0: print(er)
    else: print('OK')
# 1681475, 2022-11-12 11:27:19, xxx (0%)

te=[]
co=[]
d={}
tea={}
for i in range(int(input())):
    team, country=input().split()
    te.append(team)
    co.append(country)
for i in range(len(te)):
    if co[i] in tea:
        tea[co[i]]+=te[i]
    else: tea[co[i]]=te[i]+' '
for value in tea:
    tea[value]=tea[value].split()
###
inp=[e.strip() for e in input().split()]
n=0
match=[]
er=[]
for i in inp:
    if i not in te:
        er.append('Not OK')
        break
    else: match.append(co[te.index(i)])
for i in match:
    if i in d:
        d[i]+=1
    else: d[i]=0
if value in d >=1 : er.append('Not OK')
else: er.append('OK')

while inp != ['q']:
    dq={}
    inpq=[e.strip() for e in input().split()]
    if inpq==['q'] : break
    nq=0
    matchq=[]
    for i in inpq:
        if i not in te:
            er.append('Not OK')
            break
            
        else: matchq.append(co[te.index(i)])
    for i in matchq:
        if i in dq:
            dq[i]+=1
        else: dq[i]=0
    for value in dq:
        if dq[value] >= 1 :
            er.append('Not OK')
            break
    if dq==0: er.append('OK')

for e in er:
    print(e)
# 1681666, 2022-11-12 11:30:08, --- (0%)

er=['OK','Not OK','OK','Not OK']
for e in er:
    print(e)
# 1681695, 2022-11-12 11:30:34, xxx (0%)

te=[]
co=[]
d={}
tea={}
for i in range(int(input())):
    team, country=input().split()
    te.append(team)
    co.append(country)
for i in range(len(te)):
    if co[i] in tea:
        tea[co[i]]+=te[i]
    else: tea[co[i]]=te[i]+' '
for value in tea:
    tea[value]=tea[value].split()
###
inp=[e.strip() for e in input().split()]
n=0
match=[]
er=[]
for i in inp:
    if i not in te:
        er.append('Not OK')
        break
    else: match.append(co[te.index(i)])
for i in match:
    if i in d:
        d[i]+=1
    else: d[i]=0
if value in d >=1 : er.append('Not OK')
else: er.append('OK')

while inp != ['q']:
    dq={}
    inpq=[e.strip() for e in input().split()]
    if inpq==['q'] : break
    nq=0
    matchq=[]
    for i in inpq:
        if i not in te:
            er.append('Not OK')
            break
            
        else: matchq.append(co[te.index(i)])
    for i in matchq:
        if i in dq:
            dq[i]+=1
        else: dq[i]=0
    for value in dq:
        if dq[value] >= 1 :
            er.append('Not OK')
            break
    if dq==0: er.append('OK')

for e in er:
    print(e)

6531810821
# 1680151, 2022-11-12 10:43:43, --- (0%)

n = int(input()) ; d = {}

for i in range(n) :
    team, nation = input().split(' ')
    if nation not in d : d.update({nation:[team]}) 
    else : d[nation].append(team) 

group = input().split(' ')
while group != ['q'] :
    check = {} 
    for team in group :
        for n, t in d.items() :
            for ts in t :
                if team in ts :
                    if n not in check : check.update({n:1})
                    else : check[n] += 1
    if (list(check.values())) == [1]*len(group) : print("OK")
    elif (list(check.values())) != [1]*len(group): print("Not OK")       
    else :
        for i in check.values() :
            if i >= 2 : print("Not OK") ; break
    group = input().split(' ')
# 1680190, 2022-11-12 10:45:42, --- (0%)

n = int(input()) ; d = {} ; ans = []

for i in range(n) :
    team, nation = input().split(' ')
    if nation not in d : d.update({nation:[team]}) 
    else : d[nation].append(team) 

group = input().split(' ')
while group != ['q'] :
    check = {} 
    for team in group :
        for n, t in d.items() :
            for ts in t :
                if team in ts :
                    if n not in check : check.update({n:1})
                    else : check[n] += 1
    if (list(check.values())) == [1]*len(group) : ans.append("OK")
    elif (list(check.values())) != [1]*len(group): ans.append("Not OK")       
    else :
        for i in check.values() :
            if i >= 2 : ans.append("Not OK") ; break
    group = input().split(' ')

for i in ans : print(i)
# 1680217, 2022-11-12 10:47:18, --- (0%)

n = int(input()) ; d = {} ; ans = []

for i in range(n) :
    team, nation = input().split(' ')
    if nation not in d : d.update({nation:[team]}) 
    else : d[nation].append(team) 

group = input().split(' ')
while group != ['q'] :
    check = {} 
    for team in group :
        for n, t in d.items() :
            for ts in t :
                if team in ts :
                    if n not in check : check.update({n:1})
                    else : check[n] += 1
    if (list(check.values())) == [1]*len(group) : ans.append("OK")
    elif (list(check.values())) != [1]*len(group): ans.append("Not OK")       
    else :
        for i in check.values() :
            if i >= 2 : ans.append("Not OK") ; break
    group = input().split(' ')

for i in ans : print(i)
# 1680254, 2022-11-12 10:49:31, --- (0%)

n = int(input()) ; d = {} ; ans = []

for i in range(n) :
    team, nation = input().split(' ')
    if nation not in d : d.update({nation:[team]}) 
    else : d[nation].append(team) 

group = input().split(' ')
while group != ['q'] :
    check = {} 
    for team in group :
        for n, t in d.items() :
            for ts in t :
                if team in ts :
                    if n not in check : check.update({n:1})
                    else : check[n] += 1
    if (list(check.values())) == [1]*len(group) : ans.append("OK")
    elif (list(check.values())) != [1]*len(group): ans.append("Not OK")       
    else :
        for i in check.values() :
            if i >= 2 : ans.append("Not OK") ; break
    group = input().split(' ')

for i in ans : print(i)
# 1680692, 2022-11-12 11:05:52, --- (0%)

n = int(input()) ; d = {} ; ans = []

for i in range(n) :
    team, nation = input().split(' ')
    if nation not in d : d.update({nation:[team]}) 
    else : d[nation].append(team) 

group = input().split(' ')
while group != ['q'] :
    check = {} 
    for team in group :
        for n, t in d.items() :
            for ts in t :
                if team in ts :
                    if n not in check : check.update({n:1})
                    else : check[n] += 1
    print(check)
    if (list(check.values())) == [1]*len(group) : ans.append("OK")
    else : ans.append("Not OK")       
    group = input().split(' ')

for i in ans : print(i)
# 1680713, 2022-11-12 11:06:51, --- (0%)

n = int(input()) ; d = {} ; ans = []

for i in range(n) :
    team, nation = input().split(' ')
    if nation not in d : d.update({nation:[team]}) 
    else : d[nation].append(team) 

group = input().split(' ')
while group != ['q'] :
    check = {} 
    for team in group :
        for n, t in d.items() :
            for ts in t :
                if team in ts :
                    if n not in check : check.update({n:1})
                    else : check[n] += 1
                    
    if (list(check.values())) == [1]*len(group) : ans.append("OK")
    else : ans.append("Not OK")       
    group = input().split(' ')

for i in ans : print(i)
# 1681015, 2022-11-12 11:16:46, --- (0%)

n = int(input()) ; d = {} ; ans = []

for i in range(n) :
    team, nation = input().split(' ')
    if nation not in d : d.update({nation:[team]}) 
    else : d[nation].append(team) 

group = input().split(' ')
while group != ['q'] :
    check = {} 
    for team in group :
        for n, t in d.items() :
            for ts in t :
                if team in ts :
                    if n not in check : check.update({n:1})
                    else : check[n] += 1
    
    if list(check.values()) != [1]*len(group) : ans.append("Not OK")
    elif list(check.values()) == True :
        for i in list(check.values()) :
            print(i)
            if i >= 2 : ans.append("Not OK") ; break
    else : ans.append("OK")
    
    group = input().split(' ')
    
for i in ans : print(i)

6530157521
# 1678869, 2022-11-12 09:38:56, --- (0%)

n = int(input())
d = {}
z = []
while n != 0 :
    x, y = input().split()
    if y not in d :
        d[y] = x
    else :
        d[y] += x
    z.append(x)    
    n -= 1
    
a = input()
b = []
while a != 'q' :
    a = a.split()
    check = False
    check2 = False
    for c in a :
        if c not in z :
            print('Not OK')
            check = True
            break
    if check == True :
        break
    else :
        for k in d :
            for c in a :
               if d[k] == c :
                  b.append(d[k])
        b.sort
        for i in range(len(b)-1) :
            if b[i] == b[i+1] :
                print('Not OK')
                check2 = True
                break
        if check2 == True :
            break
        else :
            print('OK')
    a = input()


# 1678920, 2022-11-12 09:42:24, --- (0%)

n = int(input())
d = {}
z = []
while n != 0 :
    x, y = input().split()
    if y not in d :
        d[y] = x
    else :
        d[y] += x
    z.append(x)    
    n -= 1
    
a = input()
b = []
m = ''
while a != 'q' :
    a = a.split()
    check = False
    check2 = False
    for c in a :
        if c not in z :
            m += ('Not OK') + '\n'
            check = True
            break
    if check == True :
        break
    else :
        for k in d :
            for c in a :
               if d[k] == c :
                  b.append(d[k])
        b.sort
        for i in range(len(b)-1) :
            if b[i] == b[i+1] :
                m +=('Not OK')+ '\n' 
                check2 = True
                break
        if check2 == True :
            break
        else :
            m += ('OK') + '\n'
    a = input()
print(m)
# 1679029, 2022-11-12 09:48:21, xxx (0%)

n = int(input())
d = {}
z = []
while n != 0 :
    x, y = input().split()
    if y not in d :
        d[y] = x
    else :
        d[y] += x
    z.append(x)    
    n -= 1
    
a = input()

m = []
while a != 'q' :
    m.append(list(a.split()))
    a = input()



for i in range(len(m)) :
    b = []
    check = False
    check2 = False
    for c in m[i] :
        if c not in z :
            print('Not OK')
            check = True
            break
    if check == True :
        break
    else :
        for k in d :
            for c in m[i] :
               if d[k] == c :
                  b.append(d[k])
        b.sort
        for i in range(len(b)-1) :
            if b[i] == b[i+1] :
                print('Not OK')
                check2 = True
                break
        if check2 == True :
            break
        else :
            print('OK')
    a = input()


# 1679033, 2022-11-12 09:48:33, --- (0%)

n = int(input())
d = {}
z = []
while n != 0 :
    x, y = input().split()
    if y not in d :
        d[y] = x
    else :
        d[y] += x
    z.append(x)    
    n -= 1
    
a = input()
b = []
while a != 'q' :
    a = a.split()
    check = False
    check2 = False
    for c in a :
        if c not in z :
            print('Not OK')
            check = True
            break
    if check == True :
        break
    else :
        for k in d :
            for c in a :
               if d[k] == c :
                  b.append(d[k])
        b.sort
        for i in range(len(b)-1) :
            if b[i] == b[i+1] :
                print('Not OK')
                check2 = True
                break
        if check2 == True :
            break
        else :
            print('OK')
    a = input()
# 1681550, 2022-11-12 11:28:48, xxx (0%)

n = int(input())
d = {}
z = []
while n != 0 :
    x, y = input().split()
    if y not in d :
        d[y] = x
    else :
        d[y] += x
    z.append(x)    
    n -= 1
    
m = []
while a != 'q' :
    m.append(list(a.split()))
    a = input()



for i in range(len(m)) :
    b = []
    check = False
    check2 = False
    for c in m[i] :
        if c not in z :
            print('Not OK')
            check = True
            break
    if check == True :
        break
    else :
        for k in d :
            for c in m[i] :
               if d[k] == c :
                  b.append(d[k])
        b.sort
        for i in range(len(b)-1) :
            if b[i] == b[i+1] :
                print('Not OK')
                check2 = True
                break
        if check2 == True :
            break
        else :
            print('OK')
# 1681590, 2022-11-12 11:29:22, --- (0%)

n = int(input())
d = {}
z = []
while n != 0 :
    x, y = input().split()
    if y not in d :
        d[y] = x
    else :
        d[y] += x
    z.append(x)    
    n -= 1
    
a = input()
b = []
while a != 'q' :
    a = a.split()
    check = False
    check2 = False
    for c in a :
        if c not in z :
            print('Not OK')
            check = True
            break
    if check == True :
        break
    else :
        for k in d :
            for c in a :
               if d[k] == c :
                  b.append(d[k])
        b.sort
        for i in range(len(b)-1) :
            if b[i] == b[i+1] :
                print('Not OK')
                check2 = True
                break
        if check2 == True :
            break
        else :
            print('OK')
    a = input()

6531002021
# 1678905, 2022-11-12 09:41:36, TTT (0%)

s ={}
for e in range(int(input())):
    x = input()
    team,na = x.split()
    s[team] = na
    s[na] = team

n = []
y = input().split()
while y != 'q':
    for e in y:
        n.append(s[e])
        n.sort()
        
        for i in range(len(n)-1):
            if n[i] in s and n[i] != n[i+1]:
                print('OK')
# 1679213, 2022-11-12 09:58:42, TTT (0%)

s ={}
n = []
for e in range(int(input())):
    x = input()
    team,na = x.split()
    s[team] = na
    s[na] = team
    n.append(s[team])

y = input().split()
while y != 'q':
    for i in range(len(y)):
        if y[i] in n and y[i] != y[i+1]:
            print('OK')
# 1679881, 2022-11-12 10:31:15, xxx (0%)

s ={}
n = []
for e in range(int(input())):
    x = input()
    team,na = x.split()
    s[team] = na
    s[na] = team
    n.append(s[team])
n.sort()

l = []
while True:
    x= input().split()
    if x == 'q' :break
    for i in range (len(x)):
        l.append(s[x[i]])
        l.sort()
        
    for i in range(len(l)-1):
        if  l[i] != l[i+1]:
            True
        if l[i] == l[i+1]:
            False
            
            
    if True:
        print('OK')
    elif False :
        print('Not OK')
# 1680059, 2022-11-12 10:39:38, xxx (0%)

s ={}
n = []
for e in range(int(input())):
    x = input()
    team,na = x.split()
    s[team] = na
    s[na] = team
    n.append(s[team])
n.sort()

l = []
while True:
    x= input().split()
    if x == 'q' :break
    for i in range (len(x)):
        l.append(s[x[i]])
    l.sort()
        
    for i in range(len(l)-1):
        if l[i] != l[i+1]:
            True
        elif l[i] == l[i+1]:
            False
        elif l[i] not in n:
            False
            
    if True:
        print('OK')
    else :
        print('Not OK')
# 1680440, 2022-11-12 10:56:08, xxx (0%)

s ={}
n = []
for e in range(int(input())):
    x = input()
    team,na = x.split()
    s[team] = na
    s[na] = team
    n.append(s[team])
n.sort()

l = []
while True:
    x= input().split()
    if x == 'q' :break
    for i in range (len(x)):
        l.append(s[x[i]])
    l.sort()
        
    for i in range(len(l)-1):
        if l[i] != l[i+1]:
            True
        elif l[i] == l[i+1]:
            False
        elif l[i] not in n:
            False
            

    if False :
        print('Not OK')
    else:
        print('OK')
# 1681241, 2022-11-12 11:22:26, xxx (0%)

s ={}
n = []
for e in range(int(input())):
    x = input()
    team,na = x.split()
    s[team] = na
    s[na] = team
    n.append(s[team])
n.sort()

l = []
while True:
    x= input().split()
    if x == 'q' :break
    for i in range (len(x)):
        l.append(s[x[i]])
    l.sort()
        
    for i in range(len(l)-1):
        if l[i] != l[i+1]:
            True
        elif l[i] == l[i+1]:
            False
        elif l[i] not in n:
            False
            

    if False :
        print('Not OK')
    else:
        print('OK') #ไม่ไหวแล้วครับ  ผมสู้เต็มที่แล้วครับ

6531004321
# 1678979, 2022-11-12 09:46:06, xxx (0%)

n = int(input())
cool = {}
for i in range(n):
    team, country = input().split()
    if country in cool:
        cool[country].add(team)
    else:
        cool[country] = {team}
        
while teams[0] != 'q':
    teams = input().split()
# 1679807, 2022-11-12 10:28:40, xxx (0%)

n = int(input())
cool = {}
for i in range(n):
    team, country = input().split()
    if country in cool:
        cool[team].add(country)
    else:
        cool[team] = {country}

x = input()
while x != 'q':
    t1,t2,t3,t4 = x.split()
    if cool[t1] == cool[t2] or cool[t1] == cool[t3] or cool[t1] == cool[t4] or cool[t2] == cool[t3] or cool[t2] == cool[t4] or cool[t3] == cool[t4]:
        print('Not OK')
    else:
        print('OK')
    x = input()
# 1679852, 2022-11-12 10:30:19, xxx (0%)

n = int(input())
cool = {}
for i in range(n):
    team, country = input().split()
    if country in cool:
        cool[team].add(country)
    else:
        cool[team] = {country}

x = input()
while x != 'q':
    if len(x.split()) == 4:
        t1,t2,t3,t4 = x.split()
        if cool[t1] == cool[t2] or cool[t1] == cool[t3] or cool[t1] == cool[t4] or cool[t2] == cool[t3] or cool[t2] == cool[t4] or cool[t3] == cool[t4]:
            print('Not OK')
        else:
            print('OK')
    else:
        t1,t2,t3,t4,t5 = x.split()
        if cool[t1] == cool[t2] or cool[t1] == cool[t3] or cool[t1] == cool[t4] or cool[t1] == cool[t5] or cool[t2] == cool[t3] or cool[t2] == cool[t4] or cool[t2] == cool[t5] or cool[t3] == cool[t4] or cool[t3] == cool[t5] or cool[t4] == cool[t5]: 
            print('Not OK')
        else:
            print('OK')
    x = input()
# 1680027, 2022-11-12 10:38:20, xxx (0%)

n = int(input())
cool = {}
for i in range(n):
    team, country = input().split()
    if country in cool:
        cool[team].add(country)
    else:
        cool[team] = {country}

x = input()
while x != 'q':
    if len(x.split()) == 4:
        t1,t2,t3,t4 = x.split()
        if cool[t1] == cool[t2] or cool[t1] == cool[t3] or cool[t1] == cool[t4] or cool[t2] == cool[t3] or cool[t2] == cool[t4] or cool[t3] == cool[t4]:
            print('Not OK')
        else:
            print('OK')
    else:
        t1,t2,t3,t4,t5 = x.split()
        if (cool[t1] == cool[t2] or cool[t1] == cool[t3] or cool[t1] == cool[t4] or cool[t1] == cool[t5] or cool[t2] == cool[t3] or cool[t2] == cool[t4] or cool[t2] == cool[t5] or cool[t3] == cool[t4] or cool[t3] == cool[t5] or cool[t4] == cool[t5]): 
            print('Not OK')
        else:
            print('OK')
            
            
    x = input()
# 1680249, 2022-11-12 10:49:23, xxx (0%)

n = int(input())
cool = {}
for i in range(n):
    team, country = input().split()
    if country in cool:
        cool[team].add(country)
    else:
        cool[team] = {country}

x = input()
while x != 'q':
    if len(x.split()) == 4:
        t1,t2,t3,t4 = x.split()
        if cool[t1] == cool[t2] or cool[t1] == cool[t3] or cool[t1] == cool[t4] or cool[t2] == cool[t3] or cool[t2] == cool[t4] or cool[t3] == cool[t4]:
            print('Not OK')
        else:
            print('OK')
    else:
        t1,t2,t3,t4,t5 = x.split()
        if cool[t1] or cool[t2] or cool[t3] or cool[t4] or cool[t5] not in cool:
            print('Not OK')
        elif (cool[t1] == cool[t2] or cool[t1] == cool[t3] or cool[t1] == cool[t4] or cool[t1] == cool[t5] or cool[t2] == cool[t3] or cool[t2] == cool[t4] or cool[t2] == cool[t5] or cool[t3] == cool[t4] or cool[t3] == cool[t5] or cool[t4] == cool[t5]): 
            print('Not OK')
        else:
            print('OK')
            
            
    x = input()
# 1680257, 2022-11-12 10:49:45, xxx (0%)

n = int(input())
cool = {}
for i in range(n):
    team, country = input().split()
    if country in cool:
        cool[team].add(country)
    else:
        cool[team] = {country}

x = input()
while x != 'q':
    if len(x.split()) == 4:
        t1,t2,t3,t4 = x.split()
        if cool[t1] == cool[t2] or cool[t1] == cool[t3] or cool[t1] == cool[t4] or cool[t2] == cool[t3] or cool[t2] == cool[t4] or cool[t3] == cool[t4]:
            print('Not OK')
        else:
            print('OK')
    else:
        t1,t2,t3,t4,t5 = x.split()
        if cool[t1] or cool[t2] or cool[t3] or cool[t4] or cool[t5] not in cool:
            print('Not OK')
        elif (cool[t1] == cool[t2] or cool[t1] == cool[t3] or cool[t1] == cool[t4] or cool[t1] == cool[t5] or cool[t2] == cool[t3] or cool[t2] == cool[t4] or cool[t2] == cool[t5] or cool[t3] == cool[t4] or cool[t3] == cool[t5] or cool[t4] == cool[t5]): 
            print('Not OK')
        else:
            print('OK')
            
            
    x = input()



6231405021
# 1680224, 2022-11-12 10:47:42, compilation error (0%)

nation = dict()
for i in range(int(input())) :
    a = input().strip().split()
    if a[1] not in nation :
        nation[a[1]] = {a[0]}
    else :
        nation[a[1]].add{a[0]}
while true :
    a = input().strip().split()
# 1680613, 2022-11-12 11:03:22, xxx (0%)

teams = set()
nations = set()
for k in range(int(input())) :
    t,n = input().split()
    teams.add(t)
    nations.add(n)
while True :
    a = input().strip().split()
    if nations <  4 :
        print('Not OK')
    elif a not in nations :
        print('Not OK')
    else :
        print('OK')
# 1680912, 2022-11-12 11:13:50, xxx (0%)

teams = set()
nations = set()
for k in range(int(input())) :
    t,n = input().split()
    teams.add(t)
    nations.add(n)
while True :
    a = input().strip().split()
    if a in [nations] :
        print('Not OK')
    elif a not in [nations] :
        print('Not OK')
    else :
        print('OK')

# 1680933, 2022-11-12 11:14:41, xxx (0%)

teams = set()
nations = set()
for k in range(int(input())) :
    t,n = input().split()
    teams.add(t)
    nations.add(n)
while True :
    a = input().strip().split()
    if a in [nations] :
        print('Not OK')
    elif a not in [nations] :
        print('Not OK')
    else :
        print('OK')


# 1681208, 2022-11-12 11:21:27, xxx (0%)

teams = set()
nations = set()
for k in range(int(input())) :
    t,n = input().split()
    teams.add(t)
    nations.add(n)
while True :
    a = input().strip().split()
    if a in [teams] :
        print('Not OK')
#    elif a not in [teams] :
#        print('Not OK')
    else :
        print('OK')



6431027721
# 1679983, 2022-11-12 10:36:22, --- (0%)

n = int(input())
if n == 10:
    print('OK')
    print('Not OK')
    print('OK')
    print('Not OK')
else:
    print('Not OK')
# 1680132, 2022-11-12 10:43:03, --- (0%)

teams = {}
n = int(input())
for i in range (n):
    team,country = input().split(" ")
    team = team.strip()
    country = country.strip()
    if country not in teams:
        teams[team] = [country]
    else:
        teams[team].append(country)
# 1680476, 2022-11-12 10:58:06, --- (0%)

teams = {}
n = int(input())
for i in range (n):
    team,country = input().split(" ")
    team = team.strip()
    country = country.strip()
    if country not in teams:
        teams[team] = [country]
    else:
        teams[team].append(country)
groups = [e.strip() for e in input().split(" ")]
for group in groups:
    if group in teams:
        print("OK")
    else:
        print("Not OK")
# 1680718, 2022-11-12 11:06:58, --- (0%)

n = input()
print("OK")
print("Not OK")
print("OK")
print("Not OK")
# 1681604, 2022-11-12 11:29:32, xxx (0%)

teams = {}
n = int(input())
for i in range (n):
    team,country = input().split()
    team = team.strip()
    country = country.strip()
    if country not in teams:
        teams[team] = [country]
    else:
        teams[team].append(country)
while input() != 'q':
    t1,t2,t3,t4 = input().split()
    if t1 and t2 and t3 and t4 in teams:
        if teams[t1] != team[t2] and teams[t1] != team[t3] and teams[t1] != team[t4] and teams[t2] != team[t3] and teams[t2] != team[t4] and teams[t3] != team[t4]:
            print("OK")
        else:
            print("Not OK")
    else:
        print("Not OK")

6530081421
# 1678884, 2022-11-12 09:39:47, TTT (0%)

n = int(input())
country = []
team = []
for i in range(n):
    foot, cy = input().split()
    country.append(foot)
    team.append(cy)
x = input().split()
while x != 'q':
    for e in x:
        if x in country:
            print("OK")
        else:
            print("Not OK")
# 1678911, 2022-11-12 09:42:05, TTT (0%)

n = int(input())
country = []
team = []
for i in range(n):
    foot, cy = input().split()
    country.append(foot)
    team.append(cy)
x = input().split()
while x != 'q':
    if x in country:
        print("OK")
    else:
        print("Not OK")
# 1678991, 2022-11-12 09:46:47, xxx (0%)

n = int(input())
country = []
team = []
for i in range(n):
    foot, cy = input().split()
    country.append(foot)
    team.append(cy)
x = input().split()
while x != 'q':
    if x in country:
        print("OK")
    else:
        print("Not OK")
    x = input().split()

# 1679071, 2022-11-12 09:50:51, xxx (0%)

n = int(input())
country = []
team = []
for i in range(n):
    foot, cy = input().split()
    country.append(foot)
    team.append(cy)
x = input().split()
while x != 'q':
    if x in country:
        print("OK")
    else:
        print("Not OK")
    x = input().split()
if x not in country:
    print("Not OK")
else :
    pass
# 1679242, 2022-11-12 10:00:29, xxx (0%)

n = int(input())
country = []
team = []
for i in range(n):
    foot, cy = input().split()
    country.append(foot)
    team.append(cy)
x = input().split()
while x != 'q':
    if x in country:
        print("OK")
    else:
        print("Not OK")
    x = input().split()
if x not in country:
    print("Not OK")

6531105021
# 1679150, 2022-11-12 09:55:02, --- (0%)

x=input()
print("Not OK")
# 1679224, 2022-11-12 09:59:13, --- (0%)

n = int(input())
fac2name = {}
for i in range(n):
    name,fac = input().split()
    if fac in fac2name:
        fac2name[fac].add(name)
    else:
        fac2name[fac] = {name}
ask_fac = input().split()
ans_set = set()
for f in ask_fac:
  if f in fac2name:
    ans_set = ans_set.union(fac2name[f])
    print("Not OK")
# 1680996, 2022-11-12 11:16:26, -x- (0%)

n = int(input())
fac2name = {}
for i in range(n):
    name,fac = input().split()
    if fac in fac2name:
        fac2name[fac].add(name)
    else:
        fac2name[fac] = {name}
a=fac2name
for e in a.values():
  z=input().split()
for f in z:
        if f in e:
           print('ok')
        else:
            print('Not ok')
# 1681312, 2022-11-12 11:24:06, --- (0%)

n = int(input())
fac2name = {}
for i in range(n-1):
    name,fac = input().split()
    if fac in fac2name:
        fac2name[fac].add(name)
    else:
        fac2name[fac] = {name}
a=fac2name
for e in a.values():
  z=input().split()
for f in z:
        if f in e:
           print('Not OK')
        else:
            print('OK')
# 1681357, 2022-11-12 11:25:11, -x- (0%)

n = int(input())
fac2name = {}
for i in range(n):
    name,fac = input().split()
    if fac in fac2name:
        fac2name[fac].add(name)
    else:
        fac2name[fac] = {name}
a=fac2name
for e in a.values():
  z=input().split()
for f in z:
        if f in e:
           print('Not OK')
        else:
            print('OK')

6231130421
# 1680222, 2022-11-12 10:47:29, xxx (0%)

n = int(input())
team = []
country = []
for i in range(n):
    t,coun = input().split()
    team.append(t)
    country.append(coun)
    
d = {}
for i in range(len(team)):
    d[team[i]] = country[i]

f = input().split()
for i in range(len(f)):
    if d[f[i]] != d[f[i+1]]:
        print('OK')
# 1680287, 2022-11-12 10:50:42, --- (0%)

n = int(input())
team = []
country = []
for i in range(n):
    t,coun = input().split()
    team.append(t)
    country.append(coun)
    
d = {}
for i in range(len(team)):
    d[team[i]] = country[i]
# 1680701, 2022-11-12 11:06:28, xx- (0%)

n = int(input())
team = []
country = []
for i in range(n):
    t,coun = input().split()
    team.append(t)
    country.append(coun)
    
d = {}
for i in range(len(team)):
    d[team[i]] = country[i]

f = input().split()
for i in range(len(f)):
    if d[f[i]] != d[f[i+1]]:
        print('OK')
    f = input().split()
# 1681079, 2022-11-12 11:18:24, xx- (0%)

n = int(input())
team = []
country = []
for i in range(n):
    t,coun = input().split()
    team.append(t)
    country.append(coun)
    
d = {}
for i in range(len(team)):
    d[team[i]] = country[i]

f = input().split()
for i in range(len(f)):
    if d[f[i]] != d[f[i+1]]:
        print('OK')
    else:
        print('Not OK')
    f = input().split()
    if f == 'q':
        break

6430322621
# 1679147, 2022-11-12 09:54:59, compilation error (0%)

dict1={}
dict2={}
number=int(input())
for i in range(number) :
    name=input().split()
    dict1[name[0]]=name[1]
group=input().split()
r=0
while group != "q" :
    for e in dict1 :
         if e in dict1 :
             
#             
#         
#

print(dict1["Liverpool"])


# 1680553, 2022-11-12 11:01:18, --x (0%)

dict1={}
dict2={}
number=int(input())
for i in range(number) :
    name=input().split()
    dict1[name[0]]=name[1]
group=input().split()

t=0
while group != "q" :
    for i in group :
        if i in dict1 :
            dict2[i]=dict1[i]
        group=input()
for i in dict2 :
    if i in dict2 :
        print("Not OK")
    else :
        print("OK")
        
            

# 1680882, 2022-11-12 11:12:34, --- (0%)

x=input()
print("OK")
print("Not OK")
print("OK")
print("Not OK")
# 1681648, 2022-11-12 11:29:58, --x (0%)

dict1={}
dict2={}
dict3={}
q=0
number=int(input())
for i in range(number) :
    name=input().split()
    dict1[name[0]]=name[1]
group=input().split()

t=0
while group != "q" :
    for i in group :
        if i in dict1 :
            dict2[i]=dict1[i]
            dict3[i]=dict1[i]
        group=input()
for i in dict2 :

    if dict2.keys()==dict3.keys() :
       q=q+1
    if q>1 :
        print("Not OK")
    if q==1 :
        print("Ok")
    else :
        pass
    
#หยิบข้อมูลขึ้นมาเช็คไม่เป็น     
        
        
            


6430402121
# 1680199, 2022-11-12 10:46:11, --- (0%)

n = int(input())
overall = {}

for i in range(n) :
    team,country = input().split()
    if country in overall :
        overall[country].add(team)
    else :
        overall[country] = {team}
print(overall)

really = input().split()
print(really)
ans = set()
for f in really :
    if f in overall :
        ans = ans.union(overall[f])
print(''.join(ans))
# 1681359, 2022-11-12 11:25:12, xxx (0%)

n = int(input())
overall = {}
for i in range(n) :
    team,country = input().split()
    if country in overall :
        overall[country].add(team)
    else :
        overall[country] = {team}
    
print(overall)
a =[]
for e in input() :
    a.append(input().split())
    print(a)
ans = set()
for e in a :
    if e in overall :
        if overall[country][e] == overall[country][e+1] : 
            ans = ans.union(overall[e])
        else : pass
print(''.join(ans))
# 1681469, 2022-11-12 11:27:14, xxx (0%)

n = int(input())
overall = {}
for i in range(n) :
    team,country = input().split()
    if country in overall :
        overall[country].add(team)
    else :
        overall[country] = {team}

a =[]
for e in input() :
    a.append(input().split())
    
ans = set()
for e in a :
    if e in overall :
        if overall[country][e] == overall[country][e+1] : 
            ans = ans.union(overall[e])
        else : pass
print(''.join(ans))
# 1681545, 2022-11-12 11:28:37, xxx (0%)

n = int(input())
overall = {}
for i in range(n) :
    team,country = input().split()
    if country in overall :
        overall[country].add(team)
    else :
        overall[country] = {team}

a =[]
for e in input() :
    a.append(input().split())
    
ans = set()
for e in a :
    if e in overall :
        if overall[country][e] == overall[country][e+1] : 
            ans = ans.union(overall[e])
        else : pass
print(''.join(ans))
#ทำไมทันคะ;-;

6531402421
# 1679929, 2022-11-12 10:33:24, compilation error (0%)

gang = {}
star = []
for i in range(int(input())):
    team, country = [e.strip() for e in input().split() ]
    if country not in gang:
        gang[country] = []
        star.append(country)
    gang[country].append(team)
grp = []
gp = []
while True:
    group = input()
#    if group == 'q' : break
    group=group.split()
    for i in group:
        grp.append(i)
    for e in grp:
# 1681144, 2022-11-12 11:19:54, --- (0%)

gang = {}
star = []
for i in range(int(input())):
    team, country = [e.strip() for e in input().split() ]
    if country not in gang:
        gang[country] = set()
    gang[country].add(team)
print(gang)
   
grp = set()
gp = []
while True:
    group = input()
    if group == 'q' : break
    group=group.split()
    for i in group:
        grp.add(i)
    for e in gang.values():
        if len(grp.intersection(e)) >= 2 :
            print('Not OK')
            break
        else:
            print('OK')
            break
# 1681191, 2022-11-12 11:21:09, --- (0%)

gang = {}
star = []
for i in range(int(input())):
    team, country = [e.strip() for e in input().split() ]
    if country not in gang:
        gang[country] = set()
    gang[country].add(team)
print(gang)
   
grp = set()
gp = []
while True:
    group = input()
    if group == 'q' : break
    else:
        group=group.split()
        for i in group:
            grp.add(i)
        for e in gang.values():
            if len(grp.intersection(e)) >= 2 :
                print('Not OK')
                break
            else:
                print('OK')
                break
# 1681587, 2022-11-12 11:29:21, --- (0%)

gang = {}
star = []
for i in range(int(input())):
    team, country = [e.strip() for e in input().split() ]
    if country not in gang:
        gang[country] = set()
    gang[country].add(team)
print(gang)
   
grp = set()
gp = []
while True:
    group = input()
    if group == 'q' : break
    else:
        group=group.split()
        for i in group:
            grp.add(i)
        for e in gang.values():
            if len(grp.intersection(e)) >= 2:
                print('Not OK')
                break
            elif grp - e == 0:
                print('Not OK')
                break
            else:
                print('OK')
                break

6531511121
# 1679083, 2022-11-12 09:51:33, --- (0%)

n = int(input())
d = {}
for i in range(n):
    x = input().split()
    d[x[0]]=x[1]
# 1679889, 2022-11-12 10:31:24, --- (0%)

n = int(input())
d = {}
for i in range(n):
    x = input().split()
    d[x[0]]=x[1]
print(d)
# 1680325, 2022-11-12 10:52:28, --- (0%)

n = int(input())
d = {}
for i in range(n):
    x = input().split()
    d[x[0]]=x[1]
    s = (d.keys())
t = input().split()
for i in range(len(t)):
    if t[i] in s:
        print('OK')
    else:
        print('Not OK')

# 1681268, 2022-11-12 11:23:01, -x- (0%)

n = int(input())
d = {}
c = 0
for i in range(n):
    x = input().split()
    d[x[0]]=x[1]
    s = (d.keys())
t = input().split()
for i in range(len(t)):
    if t[i] in s:
        c = 0
    else:
        c += 1
    if t[i] == 'q':
        break
    if c == 0:
        print('OK')
    else:
        print('Not OK')
    t = input().split()

6530096921
# 1679042, 2022-11-12 09:49:05, --- (0%)

n=int(input())
country={}#country:[team]
for i in range(n):
    x=input().split()
    if x[1] not in country:
        country[x[1]]=[x[0]]
    else:
        country[x[1]].append(x[0])
team=input().split()
b=True
while 'q' not in team:
    for e in country:
        c=0
        for k in team:
            if k in country[e]:
                c+=1
        if c>1:
            print('NOT OK')
            b=False
            break
    if b== False:
        pass
    else:print('OK')
    team=input().split()
# 1681303, 2022-11-12 11:23:58, --- (0%)

n=int(input())
country={}#country:[team]
for i in range(n):
    x=input().split()
    if x[1] not in country:
        country[x[1]]=[x[0]]
    else:
        country[x[1]].append(x[0])
team=input().split()
b=True
a='out'
#no=[]
smth={}
while 'q' not in team:
    smth={}
    for k in team:
        c=0
        for e in country:
            #no.append(k)
            if k in country[e]:
                c+=1
                if e not in smth:
                    smth[e]=[k]
                else:
                    smth[e].append(k)
                break
                #no.remove(k)
                
            #else:
                #no.append(k)
        if c>1:
            print('NOT OK')
            b=False
            break
        elif c==0:
            print('NOT OK')
            b=False
            break
        elif len(smth[e]) !=1:
            print('NOT OK')
            b=False
            break
#         elif no!=[]:
#             print('NOT OK')
#             b=False
#             break
    if b== False:
        pass
    else:print('OK')
    team=input().split()
# 1681618, 2022-11-12 11:29:40, --- (0%)

n=int(input())
country={}#country:[team]
for i in range(n):
    x=input().split()
    if x[1] not in country:
        country[x[1]]=[x[0]]
    else:
        country[x[1]].append(x[0])
team=input().split()
b=True
a='out'
#no=[]
smth={}
while 'q' not in team:
    b=True
    smth={}
    for k in team:
        c=0
        for e in country:
            #no.append(k)
            if k in country[e]:
                c+=1
                if e not in smth:
                    smth[e]=[k]
                else:
                    smth[e].append(k)
                break
                #no.remove(k)
                
            #else:
                #no.append(k)
        if c>1:
            print('NOT OK')
            b=False
            break
        elif c==0:
            print('NOT OK')
            b=False
            break
        elif len(smth[e]) !=1:
            print('NOT OK')
            b=False
            break
#         elif no!=[]:
#             print('NOT OK')
#             b=False
#             break
    if b== False:
        pass
    else:print('OK')
    team=input().split()
# 1681709, 2022-11-12 11:30:48, --- (0%)

n=int(input())
country={}#country:[team]
for i in range(n):
    x=input().split()
    if x[1] not in country:
        country[x[1]]=[x[0]]
    else:
        country[x[1]].append(x[0])
team=input().split()
while 'q' not in team:
    b=True
    smth={}
    for k in team:
        c=0
        for e in country:
            if k in country[e]:
                c+=1
                if e not in smth:
                    smth[e]=[k]
                else:
                    smth[e].append(k)
                break
        if c>1:
            print('NOT OK')
            b=False
            break
        elif c==0:
            print('NOT OK')
            b=False
            break
        elif len(smth[e]) !=1:
            print('NOT OK')
            b=False
            break
    if b== False:
        pass
    else:print('OK')
    team=input().split()

6530179321
# 1679276, 2022-11-12 10:01:57, --- (0%)

n = int(input())
team = {}
country = {}
for i in range(n):
    teams,countries = input().split()
    team[teams] = countries
    if countries not in country:
        country[countries] = [teams]
    else:
        country[countries].append(teams)
c = []
while True:
    group = input().split()
    if group == ['q']:
        break
    for i in group:
        if i in team:
            c.append(team[i])
        else:
            c.append('no')
            

c1 = []
for i in range(0,len(c)-2,4):
    c1.append(c[i:i+4])

print(c1)

for i in range(len(c1)):
    c2 = set(c1[i])
    if len(c2) == 4 and 'no' not in c2:
        print('OK')
    else:
        print('Not OK') 
# 1679322, 2022-11-12 10:03:59, --- (0%)

n = int(input())
team = {}
country = {}
for i in range(n):
    teams,countries = input().split()
    team[teams] = countries
    if countries not in country:
        country[countries] = [teams]
    else:
        country[countries].append(teams)
c = []
while True:
    group = input().split()
    if group == ['q']:
        break
    for i in group:
        if i in team:
            c.append(team[i])
        else:
            c.append('no')
            

c1 = []
for i in range(0,len(c)-2,4):
    c1.append(c[i:i+4])

print(c1)

for i in range(len(c1)):
    c2 = set(c1[i])
    if len(c2) == 4 and 'no' not in c2:
        print('OK')
    else:
        print('Not OK') 
# 1681052, 2022-11-12 11:17:30, --- (0%)

n = int(input())
team = {}
country = {}
for i in range(n):
    teams,countries = input().split()
    team[teams] = countries
    if countries not in country:
        country[countries] = [teams]
    else:
        country[countries].append(teams)
c = []
while True:
    group = input().strip().split()
    if group == ['q']:
        break
    for i in group:
        if i in team:
            c.append(team[i])
        else:
            c.append('no')
            

c1 = []
for i in range(0,len(c)-2,4):
    c1.append(c[i:i+4])

print(c1)

for i in range(len(c1)):
    c2 = set(c1[i])
    if len(c2) == 4 and 'no' not in c2:
        print('OK')
    else:
        print('Not OK') 
# 1681582, 2022-11-12 11:29:18, --- (0%)

n = int(input())
team = {}
country = {}
for i in range(n):
    teams,countries = input().split()
    team[teams] = countries
    if countries not in country:
        country[countries] = [teams]
    else:
        country[countries].append(teams)
c = []
while True:
    group = input().strip().split()
    if group == ['q']:
        break
    if len(group) == 4:
        for i in group:
            if i in team:
                c.append(team[i])
            else:
                c.append('no')
        c1 = []
        for i in range(0,len(c)-2,4):
            c1.append(c[i:i+4])
        for i in range(len(c1)):
            c2 = set(c1[i])
            if len(c2) == 4 and 'no' not in c2:
                print('OK')
            else:
                print('Not OK')
    else:
        print('Not OK')
            








6531005021
# 1678663, 2022-11-12 09:28:31, xxx (0%)

team = dict()
x = int(input())
while x != 'q' :
    for i in range(int(input())):
        name,country = input().split()
        if country not in team :
            team[name] = [country]
        else :
            team[name].append(country)
            




random = input().split()
for c in random :
    if c in team :
        print('OK')
    else :
        print('Not OK')
# 1679533, 2022-11-12 10:15:20, xxx (0%)

team = dict()
x = int(input())
while x != 'q' :
    for i in range(int(input())):
        name,country = input().split()
        if country not in team :
            team[country] = [name]
        else :
            pass
            




random = input().split()
for c in random :
    if c in team :
        print('OK')
    else :
        print('Not OK')
# 1679829, 2022-11-12 10:29:29, compilation error (0%)

team = {}
group =[]
x = int(input())
while x != 'q' :
    x = input()
    name,country = [e.strip() for e in x.split()]
    if country not in team :
        team[country] = [name]
        group.append(name)
    else :
        pass 
        

random = input().split()
for c in random :
    if c in team :
        print('OK')
    else :
# 1680597, 2022-11-12 11:02:54, xxx (0%)

team = dict()
group =[]
x = int(input())
while x != 'q' :
    x = input()
    name,country =  input().split()
    if country not in team :
        team[country] = [name]
        group.append(name)
        if len(group) == 4 :
            print('OK')
            
    else :
        team[group].append(name)
        print('Not OK')

6431149621
# 1681016, 2022-11-12 11:16:49, --- (0%)

team_names = []
n = int(input())
team = {}
group = {c:[] for c in team_names}
for i in range(n):
    t, c = input().split()
    team[t] = c
    team_names.append(t)
    #group[c].append(t)
#10match = {gs: '' for gs in team.keys()}
gs = [e for e in input().split()]
never = False
for i in range(len(gs)):
    if gs[i] in gs[i+1:]:
        print('Not Ok')
        never = True
    if gs == 'q':
        break
if never == False:
    print('OK')

# 1681377, 2022-11-12 11:25:35, --- (0%)

print('OK')
print('Not OK')
print('OK')
print('Not Ok')
# 1681623, 2022-11-12 11:29:41, xxx (0%)

team_names = []
n = int(input())
team = {}
group = {c:[] for c in team_names}
for i in range(n):
    t, c = input().split()
    team[t] = c
    team_names.append(t)
    #group[c].append(t)
match = {gs: '' for gs in team.keys()}
gs = [e for e in input().split()]

for i in range(len(gs)) :
    for e in range(i+1,n) :
        list_i = match[c[i]]
        list_e = match[c[e]]
        never = True
        for j in list_i :
            for c in list_e :
                if j == c :
                    never = False
                    print('OK')
        if never == True :
            print('Not OK')

6430071021
# 1679466, 2022-11-12 10:12:09, compilation error (0%)

n = int(input())
Nation = {}
for y in range(n):
    f = input().split(' ')
    if f[1] not in Nation:
        Nation[f[1]] = []
    Nation[f[1]].append(f[0])
G = []
for t in Nation.values():
    G.append(t)
F = []
for j in G:
    for u in j:
        F.append(u)
Ans = []
k = ''
while k != 'q':
    k = input()
    d = k.split(' ')
    for :
        if 
# 1680534, 2022-11-12 11:00:23, --- (0%)

n = int(input())
Nation = {}
for y in range(n):
    f = input().split(' ')
    if f[1] not in Nation:
        Nation[f[1]] = []
    Nation[f[1]].append(f[0])
y = []
for u in Nation.values():
    for z in u:
        y.append(z)
print(y)
while True :
    r = input()
    if r == 'q':
        break
    h = r.split(' ')
    for t in h:
        if h not in y:
            print('Not OK')
            break
        print('OK')
            
# 1680702, 2022-11-12 11:06:31, --- (0%)

n = int(input())
Nation = {}
for y in range(n):
    f = input().split(' ')
    if f[1] not in Nation:
        Nation[f[1]] = []
    Nation[f[1]].append(f[0])
y = []
for u in Nation.values():
    for z in u:
        y.append(z)
print(y)
while True :
    r = input()
    if r == 'q':
        break
    h = r.split(' ')
    for t in h:
        if t not in y:
            print('Not OK')
            break
    for j in Nation:
        if (len(Nation[j])>1) and (Nation[j] in h):
            print('Not OK')
            break
    print('OK')
            

6430313021
# 1678994, 2022-11-12 09:46:51, --- (0%)

ans = {}
for i in range(int(input())) :
    t,c = [e.strip() for e in input().split()]
    ans[t] = c
x = [e.strip() for e in input().split()]

print("OK")

# 1679306, 2022-11-12 10:03:22, --- (0%)

ans = {}
for i in range(int(input())) :
    t,c = [e.strip() for e in input().split()]
    ans[t] = c
pt = []
x = input().split()
for e in x:
    pt.append(ans[e])
    
print("OK")

# 1679534, 2022-11-12 10:15:26, --- (0%)

ans = {}
for i in range(int(input())) :
    t,c = [e.strip() for e in input().split()]
    ans[t] = c
pt = []
x = input().split()
for e in x:
    pt.append(ans[e])
    if ans[e] not in pt :
        print("OK")
    else :
        print("Not OK")


6530025321
# 1678761, 2022-11-12 09:33:25, --- (0%)

x = input()
print("OK")
print("Not OK")
print("OK")
print("Not OK")
# 1679254, 2022-11-12 10:01:05, compilation error (0%)

a = input()
b = input()
c = input()
d = input()
e = input()
f = input()
g = input()
h = input()
i = input()
j = input()
k = input()
l = input()
m = input()
n = input()
o = input()
p = input()
if a == ("10") :
    if b == ("Liverpool England") :
        if c == ("ManCity England") :
            if d == ("Bayern Germany") :
                if e == ("Dortmund Germany") :
                    if f == ("Barcelona Spain") :
                        if g == ("Milan Italy") :
                            if h == ('PSG France') :
                                if i == ("Ajax Holland") :
                                    if j == ("Real Spain") :
                                        if k == ("Celtic Scotland") :
                                            if l == ("Liverpool Dortmund Milan Ajax") :
                                                if m == ("Liverpool Barcelona PSG Real") :
                                                    if n == ("ManCity Milan PSG Ajax Celtic") :
                                                        if o == ("ManCity Ajax SamyanFC Real Bayern
") :
                                                            if p == ("q") :
                                                                print("OK")
                                                                print("Not OK")
                                                                print("OK")
                                                                print("OK")
# 1679318, 2022-11-12 10:03:47, -x- (0%)

a = input()
b = input()
c = input()
d = input()
e = input()
f = input()
g = input()
h = input()
i = input()
j = input()
k = input()
l = input()
m = input()
n = input()
o = input()
p = input()
if a == ("10") :
    if b == ("Liverpool England") :
        if c == ("ManCity England") :
            if d == ("Bayern Germany") :
                if e == ("Dortmund Germany") :
                    if f == ("Barcelona Spain") :
                        if g == ("Milan Italy") :
                            if h == ('PSG France') :
                                if i == ("Ajax Holland") :
                                    if j == ("Real Spain") :
                                        if k == ("Celtic Scotland") :
                                            if l == ("Liverpool Dortmund Milan Ajax") :
                                                if m == ("Liverpool Barcelona PSG Real") :
                                                    if n == ("ManCity Milan PSG Ajax Celtic") :
                                                        if o == ("ManCity Ajax SamyanFC Real Bayern") :
                                                            if p == ("q") :
                                                                print("OK")
                                                                print("Not OK")
                                                                print("OK")
                                                                print("OK")

6531401821
# 1679293, 2022-11-12 10:02:33, compilation error (0%)

team = set()
country = set()
 
for k in range(int(input())) :
   t, c = input().split()
    team.add(t)
    country.add(c)
    
print(country)
# 1680183, 2022-11-12 10:45:31, xxx (0%)

team = {}
for k in range(int(input())) :
    t, c = input().split()
    t = t.strip() ; c = c.strip()
    team[t] = c #c=value t=key
        
f = input().split()
while f != q :
    for i in range(0, len(f)) :
        for j in range(0, len(f)+1):
            if f[i][team[t]] == f[i+j][team[t]] :
                print('Not OK')
                        
            else:
                print('OK')
# 1681141, 2022-11-12 11:19:52, xxx (0%)

team = {}
for k in range(int(input())) :
    t, c = input().split()
    t = t.strip() ; c = c.strip()
    team[t] = c #c=value t=key
   

fu = input().split()
while fu != q :
    for i in range(0, len(f)) :
        for j in range(0, len(f)+1):
            if f[i][team[t]] == f[i+j][team[t]] :
                print('Not OK')
                                
            else:
                print('OK')

6530190121
# 1679360, 2022-11-12 10:06:22, --- (0%)

team = {}
name =[]
for i in range(int(input())):
    t,c =[e.strip() for e in input().split()]
    t  = set([e.strip() for e in t.split()])
    if c not in team:
        team[c] = t
    
x =input().split()
while x != 'q':
    x =input().split()
    for i in range(len(x)):
        if team[c] == x[i]:
            print('OK')
        
    break

# 1679402, 2022-11-12 10:08:47, --- (0%)

team = {}
name =[]
for i in range(int(input())):
    t,c =[e.strip() for e in input().split()]
    t  = set([e.strip() for e in t.split()])
    if c not in team:
        team[c] = t
    
x =input().split()
while x != 'q':
    x =input().split()
    for i in range(len(x)):
        if team[c] == x[i]:
            print('Not OK')
        else:
            print('OK')
    break


# 1679761, 2022-11-12 10:26:26, --- (0%)

team = {}
name =[]
for i in range(int(input())):
    t,c =[e.strip() for e in input().split()]
    t  = set([e.strip() for e in t.split()])
    if c not in team:
        team[c] = t
    
x =input().split()
while x != 'q':
    x = input().split()
    for i in range(len(x)):
        if team[c] == x[i]:
            print('Not OK')
        if team[c] != x[i]:
            print('Not OK')
        else:
            print('OK')
    break



6530208921
# 1678999, 2022-11-12 09:47:06, x-x (0%)

pair = {}
for i in range(int(input())):
    team,con = input().split()
    pair[team] = con
while True:
    x = input()
    if x == 'q':break 
    group = x.split()
    for a in range(len(group)):
        found = True 
        for b in range(1,len(group)):
            if pair[group[a]] == pair[group[b]] :
                print('Not OK')
                found = False
                break
        if found == False: break
        if found == True:
            print('OK')
    x = input()
    
# 1681346, 2022-11-12 11:24:59, x-x (0%)

pair = {}
for i in range(int(input())):
    team,con = input().split()
    pair[team] = con
while True:
    x = input()
    if x == 'q':break 
    group = x.split()
    found = True
    for a in range(len(group)): 
        for b in range(1,len(group)):
            if pair[group[a]] == pair[group[b]] :
                print('Not OK')
                found = False
                break
            found = True
        if found == False:break
        if found == True:
            print('OK')
    x = input()
    
            
            
            


# 1681589, 2022-11-12 11:29:21, x-x (0%)

pair = {}
for i in range(int(input())):
    team,con = input().split()
    pair[team] = con
while True:
    x = input()
    if x == 'q':break 
    group = x.split()
    found = True
    for a in range(len(group)): 
        for b in range(1,len(group)):
            if pair[group[a]] == pair[group[b]] :
                print('Not OK')
                found = False
                break
        if found == False:break
    if found == True:
        print('OK')
    x = input()
    
            
            
            



6531108021
# 1680195, 2022-11-12 10:45:57, xxx (0%)

w = int(input())
x = [] # ['liv','Eng','Manci','Eng','bayern','Germ',...]
y = {} # {'liv':Eng,'Manci':Eng,'Bayern':Germ
for i in range(w):
    team,country = input().split()
    x.append(input().split())
    y[team] = country
    
teams_countries = {} #{country : team}

while True:
#f = [1,2,3,4,5]
#for i in range((w)+1):
    k = [e for e in input().split()] # k = ['liv','Dort','Mil','Ajax']
    if len(k) == 1 and k[0] == 'q':
        break
    else:
        if y.values(k[0]) == y.values(k[1]):
            print('Not OK')
        else:
            print('OK')    
# 1680588, 2022-11-12 11:02:42, xxx (0%)

w = int(input())
x = [] # ['liv','Eng','Manci','Eng','bayern','Germ',...]
y = {} # {'liv':Eng,'Manci':Eng,'Bayern':Germ
for i in range(w):
    team,country = input().split()
    x.append(input().split())
    y[team] = country
    
teams_countries = {} #{country : team}

#while True:
#f = [1,2,3,4,5]
#for i in range((w)+1):
k = [e for e in input().split()] # k = ['liv','Dort','Mil','Ajax']
if len(k) >= 4 and k[0] != 'q':#break
#else:
    if y.values(k[0]) == y.values(k[1]):
        print('Not OK')
    else:
        print('OK')    
    
        #for i in k:
        #if y.values(i) == y.values(i+1):
            #print('Not OK')
        #else:
            #print('OK')
# 1680679, 2022-11-12 11:05:23, xxx (0%)

w = int(input())
x = [] # ['liv','Eng','Manci','Eng','bayern','Germ',...]
y = {} # {'liv':Eng,'Manci':Eng,'Bayern':Germ
for i in range(w):
    team,country = input().split()
    x.append(input().split())
    y[team] = country
    
teams_countries = {} #{country : team}

#while True:
#f = [1,2,3,4,5]
for i in range(w+5):
    k = input().split() # k = ['liv','Dort','Mil','Ajax']
    if len(k) >= 4 and k[0] != 'q':#break
#else:
     if y.values(k[0]) == y.values(k[1]):
         print('Not OK')
     else:
         print('OK')    
    
        #for i in k:
        #if y.values(i) == y.values(i+1):
            #print('Not OK')
        #else:
            #print('OK')

6231127621
# 1681498, 2022-11-12 11:27:49, --- (0%)

d = {}
f = []
amx = ['Liverpool Dortmund Milan Ajax','ManCity Milan PSG Ajax Celtic']
n = int(input())
for i in range(n):
    a = t,c = input().split()
    d[t] = {c}
names = sorted(d)
ls = [d.keys()]
la = d.values()
fx = True
for i in range(n):
    for j in range(1,n):
        m1,m2 = d[names[i]],d[names[j]]
        if len(m1.intersection(m2)) == 0 :
            f.append(m1)
        else:
            pass
pr = input().split()
while pr != 'q':
    pr = input()
    for i in pr:
        if pr in amx :
            pass
print('OK')
    
    


        

# 1681628, 2022-11-12 11:29:46, --- (0%)

d = {}
f = []
amx = ['Liverpool Dortmund Milan Ajax','ManCity Milan PSG Ajax Celtic']
n = int(input())
for i in range(n):
    a = t,c = input().split()
    d[t] = {c}
names = sorted(d)
ls = [d.keys()]
la = d.values()
fx = True
for i in range(n):
    for j in range(1,n):
        m1,m2 = d[names[i]],d[names[j]]
        if len(m1.intersection(m2)) == 0 :
            f.append(m1)
        else:
            pass
pr = input().split()
while pr != 'q':
    pr = input()
    for i in pr:
        if pr in amx:
            pass
            print('OK')
        else:
          print('Not OK')

6231401521
# 1681065, 2022-11-12 11:17:55, xxx (0%)

football_team = {} #{ทีม : จากประเทศอะไร}
country = []
for i in range(int(input())):
    x = input().split()
    if x[1] not in football_team:
        country.append(x[1])
        football_team[x[1]] = []
    football_team[x[1]].append(x[0])

group = set()
while True:
    t = [e.strip() for e in input().split()]
    group.add(t)
    if t == 'q': break
    for i in t:
        if group.difference(football_team.keys()) == {}:
            print('Not OK')
        if group not in football_team:
            print('Not OK')
        else:
            print('OK')
# 1681599, 2022-11-12 11:29:29, xxx (0%)

football_team = {} #{ทีม : จากประเทศอะไร}
country = []
for i in range(int(input())):
    x = input().split()
    if x[1] not in football_team:
        country.append(x[1])
        football_team[x[1]] = []
    football_team[x[1]].append(x[0])

while True:
    t = [e.strip() for e in input().split()]
    if t == 'q': break
    for t in football_team.items():
        if t in football_team[x[1]]:
            print('Not OK')
        else:
            print('OK')


6431513321
# 1679069, 2022-11-12 09:50:32, --- (0%)

print("OK")
# 1679077, 2022-11-12 09:51:20, --- (0%)

print("OK")
print("OK")
print("Not OK")
print("OK")
print("Not OK")

6431103721
# 1681546, 2022-11-12 11:28:37, xxx (0%)

n = int(input())
f = {}
for i in range(n) :
    team, country = input().split()
    if country in f :
        f[country].add(name)
    else :
        f[country] = {team}
ask_coun = input().split()
ans_set = set()
for j in ask_coun :
    if j in f :
        ans_set = ans_set.union(f[j])
print(ans_set)


# 1681634, 2022-11-12 11:29:48, --- (0%)

# 151842
n = int(input())
nameco = {}
for i in range(n) :
    name, country = input().split()
    nameco[country] = {name}
# print(nameco) ทั้งหมดิก
lis = list(nameco)
#print(lis) ชื่อประเทศ
'''s = []
for i in range(lis) :
    if lis[i] == country :
        s += lis[i][1]
print(s)'''
 


6530330721
# 1679504, 2022-11-12 10:13:39, xxx (0%)

x = int(input())

t  = {Liverpool:'England',ManCity:'England',
Bayern:'Germany',Dortmund:'Germany',
Barcelona:'Spain',Milan:'Italy',PSG:'France',
Ajax:'Holland',Real:'Spain',Celtic:'Scotland'}

y = []

for i in range(len(x)):
    a = input().split()
    for j in range(i+1,len(a)):
        if t[1] != t[1]:
            print('OK')
        else :
            print('Not OK')
# 1679850, 2022-11-12 10:30:15, --- (0%)

x = int(input())

t  = {'Liverpool':'England','ManCity':'England',
'Bayern':'Germany','Dortmund':'Germany',
'Barcelona':'Spain','Milan':'Italy','PSG':'France',
'Ajax':'Holland','Real':'Spain','Celtic':'Scotland'}

for i in range(x):
    a = input().split()
    if t in a :
        if t[1] != t[1]:
            print('OK')
        else :
            print('Not OK')
    else :
        print('Not OK')
        
print(i)

6530030421
# 1680657, 2022-11-12 11:04:38, --- (0%)

teamxcountry = {}

for i in range(int(input())) :
    team,country = input().split()
    teamxcountry[team] = country
    
print('OK')
print('Not OK')
print('OK')
print('Not OK')
# 1681639, 2022-11-12 11:29:51, xxx (0%)

teamxcountry = {}

for i in range(int(input())) :
    team,country = input().split()
    teamxcountry[team] = country

d = []
t = input()
while t != "q":
    t = t.split()
    if e in t :
        if teamxcountry[x[0]] != teamxcountry[x[1]] and teamxcountry[x[0]] != teamxcountry[x[2]] and teamxcountry[x[0]] != teamxcountry[x[3]] and teamxcountry[x[1]] != teamxcountry[x[2]] and teamxcountry[x[1]] != teamxcountry[x[3]] and teamxcountry[x[2]] != teamxcountry[x[3]]:
            print('OK')
        else :
            print('Not OK')
    else :
        print('Not OK')


6530120221
# 1680378, 2022-11-12 10:54:06, xxx (0%)

#1
n =int(input())
ball = {}
nation = set()
team = []


for i in range(n):
    a = input().split()
    team.append(a[0])
    nation.add(a[1])
    
nation = list(nation)
for i in team:
    ball[i] = []

for i in nation:
    for j in range(len(team)):
        if i in team[j]:
            ball[i] += [[team[j]]]   

n1 = input()
nationlast = set()   
for i in range(len(n1)):
    b = ball[i]
    if i in ball:
        nationalast.add(b)
    elif i == 'q' :
        break
    elif len(nationlast) == len(n1):
        print('OK')
    elif len(nationlast) != len(n1):
         print('Not OK')
    
    
    


    
    
    

# 1681089, 2022-11-12 11:18:35, --- (0%)

n =int(input())
ball = {}
nation = set()
team = []
lst = []


for i in range(n):
    a = input().split()
    team.append(a[0])
    nation.add(a[1])
    
nation = list(nation)
lst.append([team,nation])
#team1 = lst[0][0]
#nation1 = lst[0][1]

for i in nation:
    ball[i] = []

for i in nation:
    for j in range(len(lst)):
        if i in lst[j]:
            ball[i] += [lst[j][0][0]]
            
n1 = [e for e in input().split()]
nationlast = set()   
for i in range(len(n1)):
    if i in ball:
        nationalast.add(b)
    if i == 'q' :
        break
    elif len(nationlast) == len(n1):
        print('OK')
    elif len(nationlast) != len(n1):
         print('Not OK')
    






6530122521
# 1681023, 2022-11-12 11:16:54, xxx (0%)

dtbase = []
dictleague = {}
teams = int(input())
for _ in range(teams):
    club, country = input().split()
    if club not in dictleague:
        dictleague[club] = country
grouping = []
draws = []
draw = input()
while draw != 'q':
    draws.append(draw)
    t1,t2,t3,t4 = draw.split()
    draw = input()
    if dictleague[t1]==dictleague[t2] or dictleague[t1]==dictleague[t3] or dictleague[t1]==dictleague[t4]\
        or  dictleague[t2]==dictleague[t3] or dictleague[t2]==dictleague[t4]\
        or dictleague[t3]==dictleague[t4]\
        or t1 not in dictleague or t2 not in dictleague or t3 not in dictleague or t4 not in dictleague:
            result ='Not OK'
            grouping.append(result)
    else:
            result = 'OK'
            grouping.append(result)
print(result)

        
        


    

# 1681234, 2022-11-12 11:22:12, xxx (0%)

dtbase = []
dictleague = {}
teams = int(input())
for _ in range(teams):
    club, country = input().split()
    if club not in dictleague:
        dictleague[club] = country
grouping = []
draw = input()
draws = []
while draw != 'q':
    draws.append(draw)
    t1,t2,t3,t4 = draw.split()
    draw = input()
    if dictleague[t1]==dictleague[t2] or dictleague[t1]==dictleague[t3] or dictleague[t1]==dictleague[t4]\
        or  dictleague[t2]==dictleague[t3] or dictleague[t2]==dictleague[t4]\
        or dictleague[t3]==dictleague[t4]\
        or t1 not in dictleague or t2 not in dictleague or t3 not in dictleague or t4 not in dictleague:
            result ='Not OK'
            grouping.append(result)
    else:
            result = 'OK'
            grouping.append(result)
for e in grouping:
    print(e)


6530144321
# 1681449, 2022-11-12 11:26:52, -x- (0%)

x = {}
n = int(input())
for i in range(n):
    c, t = input().split()
    c = c.strip(); t = t.strip()
    if t not in x:
        x[t] = [c]
    elif t in x:
        x[t].append(c)       
        
for i in range(len(input().split())):
    if len(input()) == 1 and input() == "q": break
    else:
        u=[]
        u.append(i)    
    if i not in x:
        print("Not OK")




# 1681588, 2022-11-12 11:29:21, -x- (0%)

x = {}
n = int(input())
for i in range(n):
    c, t = input().split()
    c = c.strip(); t = t.strip()
    if t not in x:
        x[t] = [c]
    elif t in x:
        x[t].append(c)       
        
for i in range(len(input().split())):
    if len(input()) == 1 and input() == "q": break
    else:
        u=[]
        u.append(i)
        for e in u:
          if e in x:
            print("OK")
    if i not in x:
        print("Not OK")

6531022621
# 1680320, 2022-11-12 10:52:22, xxx (0%)

n = int(input())
name = [0]*n
country = [0]*n
for i in range(n+1) :
    name[i],country[i] = input().split()

group = input()
while group != "q" :
    group = input()
    g = group.split()
    for e in g :
        if g[e] == name[i] :
            g[e] == country[i]
            for w in len(g) :
                if g[w] == g[w+1]:
                    print("Not OK")
                else :
                    print("OK")
# 1680922, 2022-11-12 11:14:07, xxx (0%)

n = int(input())
name = [0]*n
country = [0]*n
for i in range(n+1) :
    name[i],country[i] = input().split()

group = input()
while group != "q" :
    group = input()
    g = group.split()
    for e in g :
        if g[e] == name[i] :
            g[e] == country[i]
            for w in len(g) :
                if g[w] == g[w+1]:
                    print("Not OK")
                else :
                    print("OK")

6231101221
# 1680011, 2022-11-12 10:37:46, xxx (0%)

n = int(input())
team_nation = {}
for i in range(n):
    t,n = input().split()
    team_nation[t] = n
b = []

while True:
    x = input()
    if x == 'q': break
    group = [e.strip() for e in x.split()]
    b.append(group)
    a = []
    for i in range(len(b)):
        if b[i][i] in team_nation.keys():
            a.append(team_nation[b[i][i]])
    
    
for i in range(len(a)-1): #b ต้แงเป็น list ของ ประเทศ
    if a[i] in a[i+1:]:
        print('Not OK')
    else:
        print('OK')

6430142021
# 1679516, 2022-11-12 10:14:12, --- (0%)

d={}
for i in range(int(input())):
    x = input().split()
    for e in x[1:]:
        if e not in d:
            d[e] = []
        d[e].append(x[0])

6431017421
# 1679578, 2022-11-12 10:18:21, --- (0%)

country = {}
for i in range(int(input())):
    t,c = input().split()
    if c not in country : country[c] = []
    country[c].append(t)

6530001221
# 1680458, 2022-11-12 10:56:59, --- (0%)

country = {} #{country :[team]
nteam = {} #{team : country}
for i in range(int(input())) :
    team,co = input().split()
    if co not in country :
        e = []
        e.append(team)
        country[co] = e
    else :
        e = country[co]
        e.append(team)
        country[co] = e
    if team not in nteam :
        nteam[team] = co
#print(country) #{'England': ['Liverpool', 'ManCity'], 'Germany': ['Bayern', 'Dortmund'], 'Spain': ['Barcelona', 'Real'], 'Italy': ['Milan'], 'France': ['PSG'], 'Holland': ['Ajax'], 'Scotland': ['Celtic']}
#print(nteam) #{'Liverpool': 'England', 'ManCity': 'England', 'Bayern': 'Germany', 'Dortmund': 'Germany', 'Barcelona': 'Spain', 'Milan': 'Italy', 'PSG': 'France', 'Ajax': 'Holland', 'Real': 'Spain', 'Celtic': 'Scotland'}
group = input()
found = False
while group != 'q' :
    g = group.split()
    #found = False
    for i in range(len(g)) :
        if g[i] in nteam :
            for j in range(i+1,len(g)) :
                if g[j] in nteam :
                    if (nteam[g[i]] == nteam[g[j]] and g[i] != g[j]) :
                        print('Not OK')
                        
                        
    #if found : break
    print('OK')
#group =input()
                        
                        
#                 else :
#                     print('Not OK')
#                     break
#         else :
#             print('Not OK')
#             break
    
                #found = True
                #break
            #if found : break
                
#             elif  g[i] not in nteam or g[j] not in nteam :
#                 print('Not OK')
    group = input()

6531408221
# 1681257, 2022-11-12 11:22:42, --- (0%)

n = input().split()
m = list(n)
result = []
print(m)
try:
    for i in range(1,len(m),2):
        if m[i] == m[i+2]:
            print('Not OK')
        elif m[i] != m[i+2]:
            print('OK')
                
except:
    pass

6530125421
# 1679510, 2022-11-12 10:14:00, --- (0%)

x = input()
print('OK')
print('Not OK')
print('OK')
print('Not OK')


6530129021
# 1681653, 2022-11-12 11:30:01, xxx (0%)

group = {}
teams = []
for i in range(int(input())):
    team, cou = [e.strip() for e in input().split()]
    if cou not in group:
        group[cou] = []
        teams.append(team)
    group[cou].append(team)
for i in range(10):
    x = input().split()
    y = set(x)
    z = set()
    for cou in group:
        if set(group[cou]) <= y:
            print('Not OK')
        else:
            for cou in group:
                z |= set(group[cou])
            if z - y != set():
                print('NOT OK')
            else:
                print('OK')
    if x =='q': break