2565_1_Quiz_3_3

Max Score = 100


6531343021
# 1679204, 2022-11-12 09:58:03, PP-P-- (50%)

allies = list()
enemies = dict()
while True:
    s = input().strip().split()
    if s == ['End']:
        break
    if s[0] == 'Ally':
        allies.append(set(s[1:]))
    elif s[0] == 'Enemy':
        enemies[s[1]] = [s[2]]
        enemies[s[2]] = [s[1]]
        for alliance in allies:
            if s[1] in alliance:
                for nation in alliance:
                    if nation not in enemies:
                        enemies[nation] = [s[2]]
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
                    else:
                        enemies[nation].append(s[2])
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
    elif s[0] == 'Table':
        position = [s[-1]] + s[1:]
        ok = True
        for i in range(len(position) - 1):
            if position[i] in enemies:
                if position[i+1] in enemies[position[i]]:
                    ok = False
        if ok:
            print('Okay')
        else:
            print('No')

# 1679444, 2022-11-12 10:11:16, P----- (17%)

alliances = list()
enemies = list()
while True:
    s = input().strip().split()
    if s[0] == 'End':
        break
    if s[0] == 'Ally':
        alliances.append(s[1:])
    elif s[0] == 'Enemy':
        for alliance in alliances:
            if s[1] in alliance:
                for i in alliance:
                    enemies.append({i, s[2]})
            if s[2] in alliance:
                for i in alliance:
                    enemies.append({i, s[1]})
    elif s[0] == 'Table':
        ok = True
        test = [s[-1]] + s[1:]
        for i in range(len(test) - 1):
            if {test[i], test[i+1]} in enemies:
                ok = False
        if ok:
            print('Okay')
        else:
            print('No')
# 1679448, 2022-11-12 10:11:21, P----- (17%)

alliances = list()
enemies = list()
while True:
    s = input().strip().split()
    if s[0] == 'End':
        break
    if s[0] == 'Ally':
        alliances.append(s[1:])
    elif s[0] == 'Enemy':
        for alliance in alliances:
            if s[1] in alliance:
                for i in alliance:
                    enemies.append({i, s[2]})
            if s[2] in alliance:
                for i in alliance:
                    enemies.append({i, s[1]})
    elif s[0] == 'Table':
        ok = True
        test = [s[-1]] + s[1:]
        for i in range(len(test) - 1):
            if {test[i], test[i+1]} in enemies:
                ok = False
        if ok:
            print('Okay')
        else:
            print('No')
# 1679462, 2022-11-12 10:11:53, PP-P-- (50%)

allies = list()
enemies = dict()
while True:
    s = input().strip().split()
    if s == ['End']:
        break
    if s[0] == 'Ally':
        allies.append(set(s[1:]))
    elif s[0] == 'Enemy':
        enemies[s[1]] = [s[2]]
        enemies[s[2]] = [s[1]]
        for alliance in allies:
            if s[1] in alliance:
                for nation in alliance:
                    if nation not in enemies:
                        enemies[nation] = [s[2]]
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
                    else:
                        enemies[nation].append(s[2])
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
    elif s[0] == 'Table':
        position = [s[-1]] + s[1:]
        ok = True
        for i in range(len(position) - 1):
            if position[i] in enemies:
                if position[i+1] in enemies[position[i]]:
                    ok = False
        if ok:
            print('Okay')
        else:
            print('No')
# 1679558, 2022-11-12 10:16:52, PP-P-- (50%)

allies = list()
enemies = dict()
while True:
    ok = True
    s = input().strip().split()
    if s == ['End']:
        break
    if s[0] == 'Ally':
        allies.append(set(s[1:]))
    elif s[0] == 'Enemy':
        enemies[s[1]] = [s[2]]
        enemies[s[2]] = [s[1]]
        for alliance in allies:
            if s[1] in alliance:
                for nation in alliance:
                    if nation not in enemies:
                        enemies[nation] = [s[2]]
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
                    else:
                        enemies[nation].append(s[2])
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
    elif s[0] == 'Table':
        position = [s[-1]] + s[1:]
        for i in range(len(position) - 1):
            if position[i] in enemies:
                if position[i+1] in enemies[position[i]]:
                    ok = False
        if ok:
            print('Okay')
        else:
            print('No')
# 1679587, 2022-11-12 10:18:50, PP-P-- (50%)

allies = list()
enemies = dict()
while True:
    ok = True
    s = input().strip().split()
    if s == ['End']:
        break
    if s[0] == 'Ally':
        allies.append(set(s[1:]))
    elif s[0] == 'Enemy':
        enemies[s[1]] = [s[2]]
        enemies[s[2]] = [s[1]]
        for alliance in allies:
            if s[1] in alliance:
                for nation in alliance:
                    if nation not in enemies:
                        enemies[nation] = [s[2]]
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
                    else:
                        enemies[nation].append(s[2])
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
    elif s[0] == 'Table':
        position = [s[-1]] + s[1:]
        for i in range(len(position) - 1):
            if position[i] in enemies:
                if position[i+1] in enemies[position[i]]:
                    ok = False
            if position[i+1] in enemies:
                if position[i] in enemies[position[i+1]]:
                    ok = False
        if ok:
            print('Okay')
        else:
            print('No')
# 1679598, 2022-11-12 10:19:32, PP-P-- (50%)

allies = list()
enemies = dict()
while True:
    ok = True
    s = input().strip().split()
    if s == ['End']:
        break
    if s[0] == 'Ally':
        allies.append(set(s[1:]))
    elif s[0] == 'Enemy':
        enemies[s[1]] = [s[2]]
        enemies[s[2]] = [s[1]]
        for alliance in allies:
            if s[1] in alliance:
                for nation in alliance:
                    if nation not in enemies:
                        enemies[nation] = [s[2]]
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
                    else:
                        enemies[nation].append(s[2])
                        if s[2] not in enemies:
                            enemies[s[2]] = [nation]
                        else:
                            enemies[s[2]].append(nation)
    elif s[0] == 'Table':
        position = s[1:] * 2
        for i in range(len(position) - 1):
            if position[i] in enemies:
                if position[i+1] in enemies[position[i]]:
                    ok = False
        if ok:
            print('Okay')
        else:
            print('No')
# 1679654, 2022-11-12 10:22:10, PP-P-- (50%)

allies = list()
enemies = dict()
while True:
    ok = True
    s = input().strip().split()
    if s == ['End']:
        break
    if s[0] == 'Ally':
        allies.append(set(s[1:]))
    elif s[0] == 'Enemy':
        enemies[s[1]] = [s[2]]
        enemies[s[2]] = [s[1]]
        for alliance in allies:
            if s[1] in alliance:
                for nation in alliance:
                    if nation not in enemies:
                        enemies[nation] = [s[2]]
                    else:
                        enemies[nation].append(s[2])
                    if s[2] not in enemies:
                        enemies[s[2]] = [nation]
                    else:
                        enemies[s[2]].append(nation)
    elif s[0] == 'Table':
        position = [s[-1]] + s[1:]
        for i in range(len(position) - 1):
            if position[i] in enemies:
                if position[i+1] in enemies[position[i]]:
                    ok = False
        if ok:
            print('Okay')
        else:
            print('No')
# 1680482, 2022-11-12 10:58:23, xxxxxx (0%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1,len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies += [set[nation[s[1]],nation[s[2]]], set[nation[s[2]],nation[s[1]]]]
    elif s[0] == 'Table':
        z = True
        for i in range(1,len(s)-1):
            if s[i] not in nation or s[i+1] not in nation:
                continue
            else:
                theset = set[nation[s[i]],nation[s[i+1]]]
                if theset in enemies :
                    print('No')
                    z = False
                    break
        if z:
            if s[1] not in nation:
                print('Okay')
            elif s[-1] not in nation:
                print('Okay')
            else:
                theset = set[nation[s[1]],nation[s[-1]]]
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
# 1680492, 2022-11-12 10:58:46, xxxxxx (0%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1,len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies += [set[nation[s[1]],nation[s[2]]], set[nation[s[2]],nation[s[1]]]]
    elif s[0] == 'Table':
        z = True
        for i in range(1,len(s)-1):
            if s[i] not in nation or s[i+1] not in nation:
                continue
            else:
                theset = set[nation[s[i]],nation[s[i+1]]]
                if theset in enemies :
                    print('No')
                    z = False
                    break
        if z:
            if s[1] not in nation:
                print('Okay')
            elif s[-1] not in nation:
                print('Okay')
            else:
                theset = set[nation[s[1]],nation[s[-1]]]
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
    else: break
# 1680527, 2022-11-12 11:00:06, xxxxxx (0%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1,len(s)) :
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append(set[nation[s[1]],nation[s[2]]])
        enemies.append(set[nation[s[2]],nation[s[1]]])
    elif s[0] == 'Table':
        already = False
        for i in range(1,len(s)-1):
            if s[i] not in nation or s[i+1] not in nation:
                continue
            else:
                theset = set[nation[s[i]],nation[s[i+1]]]
                if theset in enemies :
                    print('No')
                    already = True
                    break
        if not already :
            if s[1] not in nation:
                print('Okay')
            if s[-1] not in nation:
                print('Okay')
            else:
                theset = set[nation[s[1]],nation[s[-1]]]
                if theset in enemies :
                    print('No')
                else: 
                    print('Okay')
# 1680601, 2022-11-12 11:03:07, P-PPPP (83%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1,len(s)) :
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]],nation[s[2]]))
        enemies.append((nation[s[2]],nation[s[1]]))
    elif s[0] == 'Table':
        already = False
        for i in range(1, len(s)-1):
            if s[i] not in nation or s[i+1] not in nation:
                continue
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies :
                    print('No')
                    already = True
                    break
        if not already :
            if s[1] not in nation:
                print('Okay')
            if s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies :
                    print('No')
                else: 
                    print('Okay')
    else:
        break

# 1680632, 2022-11-12 11:03:56, PPPPPP (100%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1,len(s)) :
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]],nation[s[2]]))
        enemies.append((nation[s[2]],nation[s[1]]))
    elif s[0] == 'Table':
        already = False
        for i in range(1, len(s)-1):
            if s[i] not in nation or s[i+1] not in nation:
                continue
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies :
                    print('No')
                    already = True
                    break
        if not already :
            if s[1] not in nation or s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies :
                    print('No')
                else: 
                    print('Okay')
    else:
        break
# 1680739, 2022-11-12 11:07:35, xxxxxx (0%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1, len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]], nation[s[2]]))
        enemies.append((nation[s[2]], nation[s[1]]))
    elif s[0] == 'Table':
        already = False
        for i in range(1, len(s) - 1):
            if s[i] not in nation or s[i+1] not in nation:
                pass
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies:
                    print('No')
                    already = True
                    break
        if not already:
            if s[1] not in nation or s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
# 1680749, 2022-11-12 11:07:50, xxxxxx (0%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1, len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]], nation[s[2]]))
        enemies.append((nation[s[2]], nation[s[1]]))
    elif s[0] == 'Table':
        already = False
        for i in range(1, len(s) - 1):
            if s[i] not in nation or s[i+1] not in nation:
                continue
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies:
                    print('No')
                    already = True
                    break
        if not already:
            if s[1] not in nation or s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
# 1680762, 2022-11-12 11:08:18, PPPPPP (100%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1, len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]], nation[s[2]]))
        enemies.append((nation[s[2]], nation[s[1]]))
    elif s[0] == 'Table':
        already = False
        for i in range(1, len(s) - 1):
            if s[i] not in nation or s[i+1] not in nation:
                continue
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies:
                    print('No')
                    already = True
                    break
        if not already:
            if s[1] not in nation or s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
    else:
      break
# 1680772, 2022-11-12 11:08:45, PPPPPP (100%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1, len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]], nation[s[2]]))
        enemies.append((nation[s[2]], nation[s[1]]))
    elif s[0] == 'Table':
        already = False
        for i in range(1, len(s) - 1):
            if s[i] not in nation or s[i+1] not in nation:
                pass
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies:
                    print('No')
                    already = True
                    break
        if not already:
            if s[1] not in nation or s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
    else:
      break
# 1680797, 2022-11-12 11:09:36, PPPPPP (100%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1, len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]], nation[s[2]]))
        enemies.append((nation[s[2]], nation[s[1]]))
    elif s[0] == 'Table':
        already = False
        for i in range(1, len(s) - 1):
            if s[i + 1] not in nation or s[i] not in nation:
                pass
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies:
                    print('No')
                    already = True
                    break
        if not already:
            if s[1] not in nation or s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
    else:
      break
# 1680845, 2022-11-12 11:11:16, PPPPPP (100%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1, len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]], nation[s[2]]))
        enemies.append((nation[s[2]], nation[s[1]]))
    elif s[0] == 'Table':
        already = False
        for i in range(1, len(s) - 1):
            if s[i + 1] not in nation or s[i] not in nation:
                pass
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies:
                    print('No')
                    already = True
                    break
        if not already:
            if s[1] not in nation or s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
    else: break
# 1680899, 2022-11-12 11:13:16, P-PPPP (83%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1,len(s)) :
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]],nation[s[2]]))
        enemies.append((nation[s[2]],nation[s[1]]))
    elif s[0] == 'Table':
        z = True
        for i in range(1, len(s)-1):
            if s[i] not in nation or s[i+1] not in nation:
                continue
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies :
                    print('No')
                    z = False
                    break
        if z :
            if s[1] not in nation:
                print('Okay')
            if s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies :
                    print('No')
                else: 
                    print('Okay')
    else:
        break

# 1680911, 2022-11-12 11:13:48, P-PPPP (83%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1,len(s)) :
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]],nation[s[2]]))
        enemies.append((nation[s[2]],nation[s[1]]))
    elif s[0] == 'Table':
        z = False
        for i in range(1, len(s)-1):
            if s[i] not in nation or s[i+1] not in nation:
                continue
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies :
                    print('No')
                    z = True
                    break
        if not z :
            if s[1] not in nation:
                print('Okay')
            if s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies :
                    print('No')
                else: 
                    print('Okay')
    else:
        break

# 1680932, 2022-11-12 11:14:41, PPPPPP (100%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1, len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]], nation[s[2]]))
        enemies.append((nation[s[2]], nation[s[1]]))
    elif s[0] == 'Table':
        z = False
        for i in range(1, len(s) - 1):
            if s[i + 1] not in nation or s[i] not in nation:
                pass
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies:
                    print('No')
                    z = True
                    break
        if not z:
            if s[1] not in nation or s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
    else: break
# 1680950, 2022-11-12 11:15:16, PPPPPP (100%)

u = 1
alliances = dict()
enemies = list()
nation = dict()

while True:
    s = input().split()
    if s == 'End': break
  
    elif s[0] == 'Ally':
        alliances[u] = list()
        for i in range(1, len(s)):
            alliances[u].append(s[i])
            nation[s[i]] = u
        u += 1
        
    elif s[0] == 'Enemy':
        if s[1] not in nation:
            nation[s[1]] = u
            alliances[u] = s[1]
            u += 1
        if s[2] not in nation:
            nation[s[2]] = u
            alliances[u] = s[2]
            u += 1 
        enemies.append((nation[s[1]], nation[s[2]]))
        enemies.append((nation[s[2]], nation[s[1]]))
        
    elif s[0] == 'Table':
        z = False
        for i in range(1, len(s) - 1):
            if s[i + 1] not in nation or s[i] not in nation:
                pass
            else:
                theset = (nation[s[i]], nation[s[i+1]])
                if theset in enemies:
                    print('No')
                    z = True
                    break
                  
        if not z:
            if s[1] not in nation or s[-1] not in nation:
                print('Okay')
            else:
                theset = (nation[s[1]], nation[s[-1]])
                if theset in enemies:
                    print('No')
                else: 
                    print('Okay')
                    
    else: break

6530024721
# 1679617, 2022-11-12 10:20:31, compilation error (0%)

x = input()
ntable = 0
while x != 'End' :
    x = s.strip().split()
    p = x[0]
    if p == 'Ally' :
    
    elif p == 'Enemy' :
        
    elif p == 'Table' :
        ntable += 1

for i in range(ntable) :
    print('Okay')
# 1679621, 2022-11-12 10:20:42, xxxxxx (0%)

x = input()
ntable = 0
while x != 'End' :
    x = s.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1

for i in range(ntable) :
    print('Okay')
# 1679649, 2022-11-12 10:22:03, P----- (17%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable) :
    print('Okay')
# 1679667, 2022-11-12 10:22:47, ------ (0%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable) :
    print('No')
# 1679683, 2022-11-12 10:23:17, ------ (0%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable//2) :
    print('Okey')
    print('No')
# 1679698, 2022-11-12 10:23:34, ------ (0%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable) :
    print('Okey')
    
# 1679707, 2022-11-12 10:23:49, P----- (17%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable) :
    print('Okay')
# 1679804, 2022-11-12 10:28:34, ------ (0%)

x = input()
gang = []
vs = []
tab = []
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable-1) :
    print('Okay')
    
print('No')
# 1679812, 2022-11-12 10:28:49, -P---- (17%)

x = input()
gang = []
vs = []
tab = []
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable-1) :
    print('No')
    
print('Okay')
# 1679867, 2022-11-12 10:30:42, ------ (0%)

x = input()
gang = []
vs = []
tab = []
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    
if ntable % 2 == 0 :
    for i in range(ntable-1) :
        print('Okay')
    print('No')
else :
    for i in range(ntable) :
        print('Okay')
    
# 1679874, 2022-11-12 10:30:53, P----- (17%)

x = input()
gang = []
vs = []
tab = []
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    
if ntable % 2 == 1 :
    for i in range(ntable-1) :
        print('Okay')
    print('No')
else :
    for i in range(ntable) :
        print('Okay')
# 1679931, 2022-11-12 10:33:31, ------ (0%)

x = input()
gang = []
vs = []
tab = []
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    
if ntable % 2 == 0 :
    for i in range(ntable//2) :
        print('Okay')
        print('No')
else :
    for i in range(ntable) :
        print('Okay')
# 1679939, 2022-11-12 10:33:53, P----- (17%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable) :
    print('Okay')

# 1680034, 2022-11-12 10:38:25, ------ (0%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable-1) :
    print('Okay')
print('No')    
# 1680037, 2022-11-12 10:38:41, -P---- (17%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable-1) :
    print('No')
print('Okay')
# 1680281, 2022-11-12 10:50:32, ------ (0%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    
if ntable % 2 == 0 : #คู่
    for i in range(ntable//2) :
        print('No')
        print('Okay')
else :
    for i in range(ntable//2) :
        print('No')
        print('Okay')
    print('No') 
# 1680292, 2022-11-12 10:51:02, ------ (0%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    
if ntable % 2 == 0 : #คู่
    for i in range(ntable//2) :
        print('Okay')
        print('No')
else :
    for i in range(ntable//2) :
        print('Okay')
        print('No')
    print('Okay')
# 1680298, 2022-11-12 10:51:21, P----- (17%)

x = input()
ntable = 0
while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
      pass
    elif p == 'Enemy' :
      pass  
    elif p == 'Table' :
        ntable += 1
    x = input()    

for i in range(ntable) :
    print('Okay')
# 1681255, 2022-11-12 11:22:40, P-PPP- (67%)

def fA (x) :
    out = set()
    for i in range(1,len(x)) :
        out.add(x[i])
    return out

def fE (ver,pan) :
    v1 = ver[0]
    v2 = ver[1]
    out = []
    for e in pan :
        if v1 in e :
            t1 = e
        if v2 in e :
            t2 = e
    out = [t1,t2]
    return out

def f3(v1,v2,vs) :
    for e in vs :
        k = e
        if v1 in k[0] and v2 in k[1] :
            return False
        if v1 in k[1] and v2 in k[0] :
            return False
    return True        
    
    
tab = []   
havepan =[]    
pan = []
vs = []
x = input()
ntable = 0

while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
        k = fA(x)
        pan.append(k)
        for i in range(1,len(x)) :
            havepan.append(x[i])
    elif p == 'Enemy' :
        if x[1] not in havepan :
            havepan.append(x[1])
            pan.append({x[1]})
        if x[2] not in havepan :
            havepan.append(x[2])
            pan.append({x[2]})
        ver = [x[1],x[2]]    
        k = fE(ver,pan)
        vs.append(k)
    elif p == 'Table' :
        ntable += 1
        tt = []
        for e in x :
            if e != 'Table' :
                tt.append(e)
        tab.append(tt)        
    x = input()    
c = True
for e in tab :
    c = True
    k = e
    for i in range(len(k)-1) :
        c = f3(k[i],k[i+1],vs)
        if not c :
            print('No')
            break
        if not c :
            break
    if c :
        print('Okay')
# 1681288, 2022-11-12 11:23:39, PPPPPP (100%)

def fA (x) :
    out = set()
    for i in range(1,len(x)) :
        out.add(x[i])
    return out

def fE (ver,pan) :
    v1 = ver[0]
    v2 = ver[1]
    out = []
    for e in pan :
        if v1 in e :
            t1 = e
        if v2 in e :
            t2 = e
    out = [t1,t2]
    return out

def f3(v1,v2,vs) :
    for e in vs :
        k = e
        if v1 in k[0] and v2 in k[1] :
            return False
        if v1 in k[1] and v2 in k[0] :
            return False
    return True        
    
    
tab = []   
havepan =[]    
pan = []
vs = []
x = input()
ntable = 0

while x != 'End' :
    x = x.strip().split()
    p = x[0]
    if p == 'Ally' :
        k = fA(x)
        pan.append(k)
        for i in range(1,len(x)) :
            havepan.append(x[i])
    elif p == 'Enemy' :
        if x[1] not in havepan :
            havepan.append(x[1])
            pan.append({x[1]})
        if x[2] not in havepan :
            havepan.append(x[2])
            pan.append({x[2]})
        ver = [x[1],x[2]]    
        k = fE(ver,pan)
        vs.append(k)
    elif p == 'Table' :
        ntable += 1
        tt = []
        for e in x :
            if e != 'Table' :
                tt.append(e)
        tt.append(tt[0])        
        tab.append(tt)        
    x = input()    
c = True
for e in tab :
    c = True
    k = e
    for i in range(len(k)-1) :
        c = f3(k[i],k[i+1],vs)
        if not c :
            print('No')
            break
        if not c :
            break
    if c :
        print('Okay')

6530007021
# 1679787, 2022-11-12 10:27:53, PPxxxx (33%)

Al = []
En = dict()
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally':
        Al.append(set(n[1:]))
    elif n[0] == 'Enemy':
        me = False
        for i in Al:
            if n[1] in i:
                te1 = i.copy()
                me = True
                break
        if not me:
            te1 = {n[1]}
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break
        if not me:
            fu = {n[2]}
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu
        for e in fu:
            if e in En:
               En[e] = En[e] | t1
            else:
                En[e] = te1
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680051, 2022-11-12 10:39:26, --xxxx (0%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in Al:
            if n[1] in i:
                te1 = i.copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu #
        for e in fu:
            if e in En:
               En[e] = En[e] | t1
            else:
                En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
# for i in Ta:
#     OK = True
#     for j in range(len(i)-1):
#         if i[j] in En:
#             if i[j+1] in En[i[j]]:
#                 print('No')
#                 OK = False
#                 break
#     if OK:
#         print('Okay')
# 1680088, 2022-11-12 10:41:00, ------ (0%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
#     elif n[0] == 'Enemy':
#         me = False
#         for i in Al:
#             if n[1] in i:
#                 te1 = i.copy()
#                 me = True
#                 break #
#         if not me:
#             te1 = {n[1]} #
#         me = False
#         for j in Al:
#             if n[2] in j:
#                 fu = j.copy()
#                 me = True
#                 break #
#         if not me:
#             fu = {n[2]} #
#         for e in te1:
#             if e in En:
#                 En[e] = En[e] | fu
#             else:
#                 En[e] = fu #
#         for e in fu:
#             if e in En:
#                En[e] = En[e] | t1
#             else:
#                 En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
# for i in Ta:
#     OK = True
#     for j in range(len(i)-1):
#         if i[j] in En:
#             if i[j+1] in En[i[j]]:
#                 print('No')
#                 OK = False
#                 break
#     if OK:
#         print('Okay')
# 1680097, 2022-11-12 10:41:41, P----- (17%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
#     elif n[0] == 'Enemy':
#         me = False
#         for i in Al:
#             if n[1] in i:
#                 te1 = i.copy()
#                 me = True
#                 break #
#         if not me:
#             te1 = {n[1]} #
#         me = False
#         for j in Al:
#             if n[2] in j:
#                 fu = j.copy()
#                 me = True
#                 break #
#         if not me:
#             fu = {n[2]} #
#         for e in te1:
#             if e in En:
#                 En[e] = En[e] | fu
#             else:
#                 En[e] = fu #
#         for e in fu:
#             if e in En:
#                En[e] = En[e] | t1
#             else:
#                 En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680149, 2022-11-12 10:43:41, PPxxxx (33%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        if len(n) == 3:
            for i in Al:
                if n[1] in i:
                    te1 = i.copy()
                    me = True
                    break #
            if not me:
                te1 = {n[1]} #
            me = False
            for j in Al:
                if n[2] in j:
                    fu = j.copy()
                    me = True
                    break #
            if not me:
                fu = {n[2]} #
            for e in te1:
                if e in En:
                    En[e] = En[e] | fu
                else:
                    En[e] = fu #
            for e in fu:
                if e in En:
                   En[e] = En[e] | t1
                else:
                    En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680202, 2022-11-12 10:46:19, P----- (17%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in Al:
            if n[1] in i:
                te1 = i.copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
#         for e in te1:
#             if e in En:
#                 En[e] = En[e] | fu
#             else:
#                 En[e] = fu #
#         for e in fu:
#             if e in En:
#                En[e] = En[e] | t1
#             else:
#                 En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680219, 2022-11-12 10:47:19, compilation error (0%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in Al:
            if n[1] in i:
                te1 = i.copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
         for e in te1:
#             if e in En:
#                 En[e] = En[e] | fu
#             else:
#                 En[e] = fu #
         for e in fu:
#             if e in En:
#                En[e] = En[e] | t1
#             else:
#                 En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680261, 2022-11-12 10:49:47, compilation error (0%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in Al:
            if n[1] in i:
                te1 = i.copy()
                me = True
                break #
        if not mAl = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in Al:
            if n[1] in i:
                te1 = i.copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:e:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu #
#        for e in fu:
#             if e in En:
#                En[e] = En[e] | t1
#             else:
#                 En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680350, 2022-11-12 10:53:15, P---PP (50%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in Al:
            if n[1] in i:
                te1 = i.copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu #
#         for e in fu:
#             if e in En:
#                En[e] = En[e] | t1
#             else:
#                 En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680590, 2022-11-12 11:02:47, PPxxxx (33%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in range(len(Al)):
            if n[1] in Al[i]:
                te1 = Al[i].copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu #
        for f in fu:
            if f in En:
                En[f] = En[f] | t1
            else:
                En[f] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680623, 2022-11-12 11:03:48, P-xxxx (17%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in range(len(Al)):
            if n[1] in Al[i]:
                te1 = Al[i].copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
#         for e in te1:
#             if e in En:
#                 En[e] = En[e] | fu
#             else:
#                 En[e] = fu #
        for f in fu:
            if f in En:
                En[f] = En[f] | t1
            else:
                En[f] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680918, 2022-11-12 11:13:57, --xxxx (0%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in range(len(Al)):
            if n[1] in Al[i]:
                te1 = Al[i].copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu #
        for e in fu:
            if e in En:
               En[e] = En[e] | t1
            else:
                En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
print(Al)
print(En)
# 1680923, 2022-11-12 11:14:08, PPxxxx (33%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in range(len(Al)):
            if n[1] in Al[i]:
                te1 = Al[i].copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu #
        for e in fu:
            if e in En:
               En[e] = En[e] | t1
            else:
                En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1680938, 2022-11-12 11:14:51, P-PPPP (83%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in range(len(Al)):
            if n[1] in Al[i]:
                te1 = Al[i].copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu #
#         for e in fu:
#             if e in En:
#                En[e] = En[e] | t1
#             else:
#                 En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1681187, 2022-11-12 11:21:05, P-PPPP (83%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in range(len(Al)):
            if n[1] in Al[i]:
                te1 = Al[i].copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu #
#         for e in fu:
#             if e in En:
#                En[e] = En[e] | t1
#             else:
#                 En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')
# 1681297, 2022-11-12 11:23:53, PPPPPP (100%)

Al = []
En = dict() #//
Ta = []
n = input().split()
while n[0] != 'End':
    if n[0] == 'Ally': #
        Al.append(set(n[1:])) #
    elif n[0] == 'Enemy':
        me = False
        for i in range(len(Al)):
            if n[1] in Al[i]:
                te1 = Al[i].copy()
                me = True
                break #
        if not me:
            te1 = {n[1]} #
        me = False
        for j in Al:
            if n[2] in j:
                fu = j.copy()
                me = True
                break #
        if not me:
            fu = {n[2]} #
        for e in te1:
            if e in En:
                En[e] = En[e] | fu
            else:
                En[e] = fu #
        for e in fu:
            if e in En:
               En[e] = En[e] | te1
            else:
                En[e] = te1 #
    elif n[0] == 'Table':
        Ta.append(n[1:]+[n[1]])
    n = input().split()
for i in Ta:
    OK = True
    for j in range(len(i)-1):
        if i[j] in En:
            if i[j+1] in En[i[j]]:
                print('No')
                OK = False
                break
    if OK:
        print('Okay')

6532193421
# 1679132, 2022-11-12 09:54:05, PP-PP- (67%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        a=s[1:]
        for i in range(len(a)):
            countries1=set()
            if a[i] in allies:
                countries1=allies[a[i]]
            countries1.add(a[i])
            for country in countries1:
                for j in range(len(a)):
                    if i!=j:
                        countries2=set()
                        if a[j] in allies:
                            countries2=allies[a[j]]
                        countries2.add(a[j])
                        enemies[country]=countries2
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1679284, 2022-11-12 10:02:11, PPPP-P (83%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        a=s[1:]
        for i in range(len(a)):
            countries1=set()
            if a[i] in allies:
                countries1=allies[a[i]]
            countries1.add(a[i])
            for country in countries1:
                for j in range(len(a)):
                    if i!=j:
                        countries2=set()
                        if a[j] in allies:
                            countries2=allies[a[j]]
                        countries2.add(a[j])
                        if country not in enemies:
                            enemies[country]=countries2
                        else:
                            for country2 in countries2:
                                enemies[country].add(country2)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1679853, 2022-11-12 10:30:22, PPPPPP (100%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        country1=s[1]
        country2=s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1]
        group1.add(country1)
        group2=set()
        if country2 in allies:
            group2=allies[country2]
        group2.add(country2)
        for country1 in group1:
            if country1 not in enemies:
                enemies[country1]=set()
            for country2 in group2:
                if country2 not in enemies:
                    enemies[country2]=set()
                enemies[country1].add(country2)
                enemies[country2].add(country1)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680023, 2022-11-12 10:38:13, PPxPxx (50%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        a=s[1:]
        for i in range(len(a)):
            countries1=set()
            if a[i] in allies:
                countries1=allies[a[i]]
            countries1.add(a[i])
            for country in countries1:
                for j in range(len(a)):
                    if i!=j:
                        countries2=set()
                        if a[j] in allies:
                            countries2=allies[a[j]]
                        countries2.add(a[j])
                        if country not in enemies:
                            enemies[country]=countries2
                        else:
                            for country2 in countries2:
                                enemies[country].add(country2)
                                enemies[country2].add(country)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680028, 2022-11-12 10:38:20, PPPPPP (100%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        country1=s[1]
        country2=s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1]
        group1.add(country1)
        group2=set()
        if country2 in allies:
            group2=allies[country2]
        group2.add(country2)
        for country1 in group1:
            if country1 not in enemies:
                enemies[country1]=set()
            for country2 in group2:
                if country2 not in enemies:
                    enemies[country2]=set()
                enemies[country1].add(country2)
                enemies[country2].add(country1)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680065, 2022-11-12 10:39:57, P-PP-P (67%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        a=s[1:]
        countries1=set()
        if a[0] in allies:
            countries1=allies[a[0]]
        countries1.add(a[0])
        for country in countries1:
            countries2=set()
            if a[1] in allies:
                countries2=allies[a[1]]
            countries2.add(a[1])
            if country not in enemies:
                enemies[country]=countries2
            else:
                for country2 in countries2:
                    enemies[country].add(country2)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680078, 2022-11-12 10:40:41, PPPP-P (83%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        a=s[1:]
        countries1=set()
        if a[0] in allies:
            countries1=allies[a[0]]
        countries1.add(a[0])
        for country in countries1:
            countries2=set()
            if a[1] in allies:
                countries2=allies[a[1]]
            countries2.add(a[1])
            if country not in enemies:
                enemies[country]=countries2
            else:
                for country2 in countries2:
                    enemies[country].add(country2)
        countries1=set()
        if a[1] in allies:
            countries1=allies[a[1]]
        countries1.add(a[1])
        for country in countries1:
            countries2=set()
            if a[0] in allies:
                countries2=allies[a[0]]
            countries2.add(a[0])
            if country not in enemies:
                enemies[country]=countries2
            else:
                for country2 in countries2:
                    enemies[country].add(country2)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680200, 2022-11-12 10:46:11, PPPPPP (100%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        country1=s[1]
        country2=s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1]
        group1.add(country1)

        group2=set()
        if country2 in allies:
            group2=allies[country2]
        group2.add(country2)
        for cuntry1 in group1:
            if cuntry1 not in enemies:
                enemies[cuntry1]=set()
            for cuntry2 in group2:
                if cuntry2 not in enemies:
                    enemies[cuntry2]=set()
                enemies[cuntry1].add(cuntry2)
                enemies[cuntry2].add(cuntry1)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680260, 2022-11-12 10:49:47, compilation error (0%)


        country1 = s[1]
        country2 = s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1]
        group1.add(country1)
        group2=set()
        if country2 in allies:
            group2=allies[country2]
        group2.add(country2)
        for country in group1:
            if country not in enemies:
                enemies[country]=group2
            else:
                for cuntry2 in group2:
                    enemies[country].add(cuntry2)

        group1=set()
        if country2 in allies:
            group1=allies[country2]
        group1.add(country2)
        group2=set()
        if country1 in allies:
            group2=allies[country1]
        group2.add(country1)
        
        for country in group1:
            if country not in enemies:
                enemies[country]=group2
            else:
                for cuntry2 in group2:
                    enemies[country].add(cuntry2)
# 1680272, 2022-11-12 10:50:09, PPPP-P (83%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        country1 = s[1]
        country2 = s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1]
        group1.add(country1)
        group2=set()
        if country2 in allies:
            group2=allies[country2]
        group2.add(country2)
        for country in group1:
            if country not in enemies:
                enemies[country]=group2
            else:
                for cuntry2 in group2:
                    enemies[country].add(cuntry2)

        group1=set()
        if country2 in allies:
            group1=allies[country2]
        group1.add(country2)
        group2=set()
        if country1 in allies:
            group2=allies[country1]
        group2.add(country1)
        
        for country in group1:
            if country not in enemies:
                enemies[country]=group2
            else:
                for cuntry2 in group2:
                    enemies[country].add(cuntry2)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680322, 2022-11-12 10:52:23, P-xPxx (33%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        country1 = s[1]
        country2 = s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1]
        group1.add(country1)
        group2=set()
        if country2 in allies:
            group2=allies[country2]
        group2.add(country2)
        
        for cuntry in group1:
            if cuntry not in enemies:
                enemies[cuntry]=group2
            else:
                for cuntry2 in group2:
                    enemies[cuntry].add(cuntry2)
                    enemies[cuntry2].add(cuntry)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680358, 2022-11-12 10:53:29, P-PP-P (67%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        country1 = s[1]
        country2 = s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1]
        group1.add(country1)
        group2=set()
        if country2 in allies:
            group2=allies[country2]
        group2.add(country2)
        
        for cuntry in group1:
            if cuntry not in enemies:
                enemies[cuntry]=group2
            else:
                for cuntry2 in group2:
                    if cuntry2 not in enemies:
                        enemies[cuntry2] = group1
                    enemies[cuntry].add(cuntry2)
                    enemies[cuntry2].add(cuntry)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680389, 2022-11-12 10:54:24, P-PPPP (83%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        country1 = s[1]
        country2 = s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1]
        group1.add(country1)
        group2=set()
        if country2 in allies:
            group2=allies[country2]
        group2.add(country2)
        
        for cuntry in group1:
            if cuntry not in enemies:
                enemies[cuntry]=group2.copy()
            else:
                for cuntry2 in group2:
                    if cuntry2 not in enemies:
                        enemies[cuntry2] = group1.copy()
                    enemies[cuntry].add(cuntry2)
                    enemies[cuntry2].add(cuntry)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1680397, 2022-11-12 10:54:38, PPPPPP (100%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        country1=s[1]
        country2=s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1]
        group1.add(country1)
        group2=set()
        if country2 in allies:
            group2=allies[country2]
        group2.add(country2)
        
        for cuntry1 in group1:
            if cuntry1 not in enemies:
                enemies[cuntry1]=set()
            for cuntry2 in group2:
                if cuntry2 not in enemies:
                    enemies[cuntry2]=set()
                enemies[cuntry1].add(cuntry2)
                enemies[cuntry2].add(cuntry1)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break
# 1681045, 2022-11-12 11:17:24, PPPPPP (100%)

allies={}
enemies={}
while True:
    s=input().split()
    if s[0]=="Ally":
        countries=s[1:]
        for i in range(len(countries)):
            country=countries[i]
            if country not in allies:
                allies[country]=set()
            for j in range(len(countries)):
                ally=countries[j]
                if i!=j:
                    allies[country].add(ally)
    elif s[0]=="Enemy":
        country1=s[1]
        country2=s[2]
        group1=set()
        if country1 in allies:
            group1=allies[country1].copy()
        group1.add(country1)
        group2=set()
        if country2 in allies:
            group2=allies[country2].copy()
        group2.add(country2)
        
        for cuntry1 in group1:
            if cuntry1 not in enemies:
                enemies[cuntry1]=set()
            for cuntry2 in group2:
                if cuntry2 not in enemies:
                    enemies[cuntry2]=set()
                enemies[cuntry1].add(cuntry2)
                enemies[cuntry2].add(cuntry1)
    elif s[0]=="Table":
        a=s[1:]
        ok=True
        for i in range(len(a)):
            if a[i] not in enemies:
                continue
            if a[(i+1)%len(a)] in enemies[a[i]]:
                ok=False
                break
        if ok:
            print("Okay")
        else:
            print("No")
    else:
        break

6531313221
# 1679311, 2022-11-12 10:03:26, P-PP-- (50%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        for country in countries:
            if country not in enemyOf:
                free += 1
                continue
            conflict = enemyOf[country].intersection(countries)
            for pair in conflict:
                if pair not in done:
                    need += 1
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
            if len(conflict) == 0:
                free += 1
        if free >= need:
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1679530, 2022-11-12 10:15:10, P-PP-- (50%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        for country in countries:
            if country not in enemyOf:
                free += 1
                continue
            conflict = enemyOf[country].intersection(countries)
            for pair in conflict:
                if pair not in done:
                    need += 1
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
            if len(conflict) == 0:
                free += 1
        if free > need:
            print("Okay")
        else:
            print("No")
    else:
        pass
# 1679554, 2022-11-12 10:16:42, P----- (17%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        for country in countries:
            if country not in enemyOf:
                free += 1
                continue
            conflict = enemyOf[country].intersection(countries)
            for pair in conflict:
                if pair not in done:
                    need += 1
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
            if len(conflict) == 0:
                free += 1
        if free >= need -1:
            print("Okay")
        else:
            print("No")
    else:
        pass
# 1679562, 2022-11-12 10:17:06, P-PP-- (50%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        for country in countries:
            if country not in enemyOf:
                free += 1
                continue
            conflict = enemyOf[country].intersection(countries)
            for pair in conflict:
                if pair not in done:
                    need += 1
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
            if len(conflict) == 0:
                free += 1
        if free >= need:
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1679580, 2022-11-12 10:18:30, xxxx-- (0%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        for country in countries:
            if country in done:
                continue
            if country not in enemyOf:
                free += 1
                done = done.union(allyOf[pair])
                continue
            conflict = enemyOf[country].intersection(countries)
            for pair in conflict:
                if pair not in done:
                    need += 1
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
            if len(conflict) == 0:
                free += 1
        if free >= need:
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1679597, 2022-11-12 10:19:27, P-PP-- (50%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        for country in countries:
            if country in done:
                continue
            if country not in enemyOf:
                free += 1
                done.add(country)
                continue
            conflict = enemyOf[country].intersection(countries)
            for pair in conflict:
                if pair not in done:
                    need += 1
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
            if len(conflict) == 0:
                free += 1
        if free >= need:
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1679626, 2022-11-12 10:20:59, P-PP-- (50%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        for country in countries:
            if country in done:
                continue
            if country not in enemyOf:
                free += 1
                if country not in allyOf:
                    done.add(country)
                else:
                    done = done.union(allyOf[country])
                continue
            conflict = enemyOf[country].intersection(countries)
            for pair in conflict:
                if pair not in done:
                    need += 1
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
            if len(conflict) == 0:
                free += 1
        if free >= need:
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1679818, 2022-11-12 10:29:07, P----- (17%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        for country in list(allAlly):
            allyOf[country] = allAlly

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        skip = False
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = [enemy2]
        else:
            enemyOf[enemy1] += [enemy2]

        if enemy2 not in enemyOf:
            enemyOf[enemy2] = [enemy1]
        else:
            enemyOf[enemy2] += [enemy1]

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        for country in countries:
            if country in done:
                continue
            if country not in enemyOf:
                free += 1
                done.add(country)
                continue
            for enemy in enemyOf[country]:
                conflict = allyOf[enemy].intersection(countries)
                for pair in conflict:
                    if pair not in done:
                        need += 1
                        done = done.union(allyOf[pair])
                        done = done.union(allyOf[country])
                if len(conflict) == 0:
                    free += 1
        if free >= need:
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1679925, 2022-11-12 10:33:01, P----- (17%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        for country in list(allAlly):
            allyOf[country] = allAlly

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        skip = False
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = [enemy2]
        else:
            enemyOf[enemy1] += [enemy2]

        if enemy2 not in enemyOf:
            enemyOf[enemy2] = [enemy1]
        else:
            enemyOf[enemy2] += [enemy1]

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        for country in countries:
            if country in done:
                continue
            if country not in enemyOf:
                free += 1
                done.add(country)
                continue
            for enemy in enemyOf[country]:
                conflict = allyOf[enemy].intersection(countries)
                for pair in conflict:
                    if pair not in done:
                        need += 1
                        done = done.union(allyOf[pair])
                        done = done.union(allyOf[country])
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
                    # print(free, need, country, pair)
                if len(conflict) == 0:
                    free += 1
        if free >= need:
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1680196, 2022-11-12 10:45:58, P----- (17%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        for country in list(allAlly):
            allyOf[country] = allAlly

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        skip = False
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = [enemy2]
        else:
            enemyOf[enemy1] += [enemy2]

        if enemy2 not in enemyOf:
            enemyOf[enemy2] = [enemy1]
        else:
            enemyOf[enemy2] += [enemy1]

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        mul = 1
        for country in countries:

            if country in done:
                continue
            if country not in enemyOf:
                free += 1
                done.add(country)
                continue
            for enemy in enemyOf[country]:
                conflict = allyOf[enemy].intersection(countries)
                for pair in conflict:
                    if pair not in done:
                        need += 1 * (-1)**mul
                        done = done.union(allyOf[pair])
                        done = done.union(allyOf[country])
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
                if len(conflict) == 0:
                    free += 1
            mul += 1
        # print(free, need, done)
        if free >= abs(need):
            print("Okay")
        else:
            print("No")
    else:
        pass
# Enemy a b
# Enemy b c
# Enemy c d
# Table a b c d

# 1680239, 2022-11-12 10:48:33, P-PP-- (50%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        free = 0
        need = 0
        mul = 1
        for country in countries:
            if country in done:
                continue
            if country not in enemyOf:
                free += 1
                if country not in allyOf:
                    done.add(country)
                else:
                    done = done.union(allyOf[country])
                continue
            conflict = enemyOf[country].intersection(countries)
            for pair in conflict:
                if pair not in done:
                    need += 1 * (-1)**mul
                    done = done.union(allyOf[pair])
                    done = done.union(allyOf[country])
            if len(conflict) == 0:
                free += 1
            mul += 1
        if free >= abs(need):
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1680557, 2022-11-12 11:01:30, P-PPP- (67%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        done = set()
        countries = inputs[1:]
        yes = True
        for i in range(len(countries)-1):
            c1, c2 = countries[i], countries[i+1]
            if c1 not in allyOf:
                allyOf[c1] = set()
                allyOf[c1].add(c1)
            if c2 not in allyOf:
                allyOf[c2] = set()
                allyOf[c2].add(c2)
            if c1 in enemyOf:
                for enemy in enemyOf[c1]:
                    if enemy in allyOf[c2]:
                        yes = False
            if c2 in enemyOf:
                for enemy in enemyOf[c2]:
                    if enemy in allyOf[c1]:
                        yes = False

        if yes:
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1680647, 2022-11-12 11:04:24, PPPPPP (100%)

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        countries = inputs[1:]
        yes = True
        for i in range(len(countries)-1):
            c1, c2 = countries[i], countries[i+1]
            if c1 not in allyOf:
                allyOf[c1] = set()
                allyOf[c1].add(c1)
            if c2 not in allyOf:
                allyOf[c2] = set()
                allyOf[c2].add(c2)
            if c1 in enemyOf:
                for enemy in enemyOf[c1]:
                    if enemy in allyOf[c2]:
                        yes = False
            if c2 in enemyOf:
                for enemy in enemyOf[c2]:
                    if enemy in allyOf[c1]:
                        yes = False
        c1, c2 = countries[-1], countries[0]
        if c1 not in allyOf:
            allyOf[c1] = set()
            allyOf[c1].add(c1)
        if c2 not in allyOf:
            allyOf[c2] = set()
            allyOf[c2].add(c2)
        if c1 in enemyOf:
            for enemy in enemyOf[c1]:
                if enemy in allyOf[c2]:
                    yes = False
        if c2 in enemyOf:
            for enemy in enemyOf[c2]:
                if enemy in allyOf[c1]:
                    yes = False
        if yes:
            print("Okay")
        else:
            print("No")
    else:
        pass

# 1681317, 2022-11-12 11:24:10, PPPPPP (100%)

# ตอนแรกเข้าใจโจทย์ผิดว่า สามารถเรียงประเทศอย่างไรก็ได้ตาม list ที่ให้มา ทำให้ code อาจดูยุ่งๆ หน่อย

allyOf = {}
enemyOf = {}
while True:
    inputs = input().split()
    q = inputs[0]
    if len(inputs) == 1:
        break
    if q == 'Ally':
        countries = inputs[1:]
        allAlly = set()
        for country in countries:
            if country in allyOf:
                allAlly = allAlly.union(allyOf[country])
        allAlly = allAlly.union(set(countries))

        allEnemy = set()
        for country in countries:
            if country in enemyOf:
                allEnemy = allEnemy.union(enemyOf[country])

        for country in list(allAlly):
            allyOf[country] = allAlly
            enemyOf[country] = allEnemy

    elif q == 'Enemy':
        enemy1, enemy2 = inputs[1:]
        if enemy1 not in allyOf:
            allyOf[enemy1] = set()
            allyOf[enemy1].add(enemy1)
        if enemy2 not in allyOf:
            allyOf[enemy2] = set()
            allyOf[enemy2].add(enemy2)
        if enemy1 not in enemyOf:
            enemyOf[enemy1] = set()
            enemyOf[enemy1].add(enemy2)
        if enemy2 not in enemyOf:
            enemyOf[enemy2] = set()
            enemyOf[enemy2].add(enemy1)

        countries1 = allyOf[enemy1]
        countries2 = allyOf[enemy2]
        for country1 in countries1:
            enemyOf[country1] = enemyOf[country1].union(countries2)
        for country2 in countries2:
            enemyOf[country2] = enemyOf[country2].union(countries1)

    elif q == 'Table':
        countries = inputs[1:]
        yes = True
        for i in range(len(countries)-1):
            c1, c2 = countries[i], countries[i+1]
            if c1 not in allyOf:
                allyOf[c1] = set()
                allyOf[c1].add(c1)
            if c2 not in allyOf:
                allyOf[c2] = set()
                allyOf[c2].add(c2)
            if c1 in enemyOf:
                for enemy in enemyOf[c1]:
                    if enemy in allyOf[c2]:
                        yes = False
            if c2 in enemyOf:
                for enemy in enemyOf[c2]:
                    if enemy in allyOf[c1]:
                        yes = False
        c1, c2 = countries[-1], countries[0]
        if c1 not in allyOf:
            allyOf[c1] = set()
            allyOf[c1].add(c1)
        if c2 not in allyOf:
            allyOf[c2] = set()
            allyOf[c2].add(c2)
        if c1 in enemyOf:
            for enemy in enemyOf[c1]:
                if enemy in allyOf[c2]:
                    yes = False
        if c2 in enemyOf:
            for enemy in enemyOf[c2]:
                if enemy in allyOf[c1]:
                    yes = False
        if yes:
            print("Okay")
        else:
            print("No")
    else:
        pass


6531306921
# 1679388, 2022-11-12 10:08:01, PP-P-- (50%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
        if airline:
            alist[j]=alist[j].intersection(set(y))
        else:
            alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in alist:
            if a in j:
                anotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(b)
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            elist[a].add(b)
            
        for j in alist:
            if b in j:
                bnotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(a)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            elist[b].add(a)            
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1679461, 2022-11-12 10:11:51, PPPP-- (67%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
        if airline:
            alist[j]=alist[j].intersection(set(y))
        else:
            alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in alist:
            if a in j:
                anotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(b)
        for j in alist:
            if b in j:
                bnotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(a)
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            if bnotinalist:
                elist[a].add(b)
            else:
                for j in alist:
                    if b in j:
                        for i in j:
                            elist[a].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            if anotinalist:
                elist[b].add(a)
            else:
                for j in alist:
                    if a in j:
                        for i in j:
                            elist[b].add(i)           
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1679513, 2022-11-12 10:14:05, ------ (0%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
        if airline:
            alist[j]=alist[j].intersection(set(y))
        else:
            alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in alist:
            if a in j:
                anotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(b)
        for j in alist:
            if b in j:
                bnotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(a)
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            if bnotinalist:
                elist[a].add(b)
            else:
                for j in alist:
                    if b in j:
                        for i in j:
                            elist[a].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            if anotinalist:
                elist[b].add(a)
            else:
                for j in alist:
                    if a in j:
                        for i in j:
                            elist[b].add(i)           
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
            if y[i] in elist and y[i+1] in elist[y[i]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        if y[0] in elist and y[-1] in elist[y[0]]:
            cantable="No"
        print(cantable)
    x=input().split()
print(elist)
# 1679518, 2022-11-12 10:14:17, PPPP-- (67%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
        if airline:
            alist[j]=alist[j].intersection(set(y))
        else:
            alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in alist:
            if a in j:
                anotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(b)
        for j in alist:
            if b in j:
                bnotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(a)
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            if bnotinalist:
                elist[a].add(b)
            else:
                for j in alist:
                    if b in j:
                        for i in j:
                            elist[a].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            if anotinalist:
                elist[b].add(a)
            else:
                for j in alist:
                    if a in j:
                        for i in j:
                            elist[b].add(i)           
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
            if y[i] in elist and y[i+1] in elist[y[i]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        if y[0] in elist and y[-1] in elist[y[0]]:
            cantable="No"
        print(cantable)
    x=input().split()

# 1679585, 2022-11-12 10:18:44, xPxxxx (17%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
        if airline:
            alist[j]=alist[j].intersection(set(y))
        else:
            alist.append(set(y))
        for i in alist:
            for j in range(len(i)):
                elist[j]=elist[0]
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in alist:
            if a in j:
                anotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(b)
        for j in alist:
            if b in j:
                bnotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(a)
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            if bnotinalist:
                elist[a].add(b)
            else:
                for j in alist:
                    if b in j:
                        for i in j:
                            elist[a].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            if anotinalist:
                elist[b].add(a)
            else:
                for j in alist:
                    if a in j:
                        for i in j:
                            elist[b].add(i)           
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1679969, 2022-11-12 10:35:36, xP-P-x (33%)

x=input().split()
alist=[]
allist={}
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
        if airline:
            alist[j]=alist[j].intersection(set(y))
        else:
            alist.append(set(y))
        
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for i in range(len(alist)):
            if a in alist[i]:
                anotinalist=False
                if i not in elist:
                    elist[i]=set()
                elist[i].add(b)
            if b in alist[i]:
                bnotinalist=False
                if i not in elist:
                    elist[i]=set()
                elist[i].add(a)
        if anotinalist:
            alist.append(set([a]))
            
            elist[len(alist)-1]=set([b])
            
        if bnotinalist:
            alist.append(set([b]))
            elist[len(alist)-1]=set([a])
    if x[0]=="Table":
        for i in range(len(alist)):
            for j in alist[i]:
                allist[j]=i
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in allist and y[i] in elist[allist[y[i+1]]]:
                cantable="No"
        if y[-1] in allist and y[0] in elist[allist[y[-1]]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1680136, 2022-11-12 10:43:17, PPPP-- (67%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
        if airline:
            alist[j]=alist[j].union(set(y))
        else:
            alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in alist:
            if a in j:
                anotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(b)
        for j in alist:
            if b in j:
                bnotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(a)
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            if bnotinalist:
                elist[a].add(b)
            else:
                for j in alist:
                    if b in j:
                        for i in j:
                            elist[a].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            if anotinalist:
                elist[b].add(a)
            else:
                for j in alist:
                    if a in j:
                        for i in j:
                            elist[b].add(i)           
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
            if y[i] in elist and y[i+1] in elist[y[i]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        if y[0] in elist and y[-1] in elist[y[0]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1680214, 2022-11-12 10:47:07, PPPP-- (67%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
            
                    alist[j]=alist[j].union(set(y))
        if not airline:
                alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in alist:
            if a in j:
                anotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(b)
        for j in alist:
            if b in j:
                bnotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(a)
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            if bnotinalist:
                elist[a].add(b)
            else:
                for j in alist:
                    if b in j:
                        for i in j:
                            elist[a].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            if anotinalist:
                elist[b].add(a)
            else:
                for j in alist:
                    if a in j:
                        for i in j:
                            elist[b].add(i)           
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
            if y[i] in elist and y[i+1] in elist[y[i]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        if y[0] in elist and y[-1] in elist[y[0]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1680346, 2022-11-12 10:53:00, PxxxP- (33%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
            
                    alist[j]=alist[j].union(set(y))
        if not airline:
                alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in range(len(alist)):
            if a in alist[j]:
                za=j
                anotinalist=False
        for j in range(len(alist)):
            if b in alist[j]:
                zb=j
                bnotinalist=False
        for k in alist[za]:
            if k not in elist:
                elist[k]=set()
            if bnotinalist:
                elist[k].add(b)
            else:
                for i in alist[zb]:
                    elist[k].add(i)
        for k in alist[zb]:
            if k not in elist:
                elist[k]=set()
            if bnotinalist:
                elist[k].add(a)
            else:
                for i in alist[za]:
                    elist[k].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            if anotinalist:
                elist[b].add(a)
            else:
                for j in alist:
                    if a in j:
                        for i in j:
                            elist[b].add(i)           
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
            if y[i] in elist and y[i+1] in elist[y[i]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        if y[0] in elist and y[-1] in elist[y[0]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1680439, 2022-11-12 10:55:51, PxxxP- (33%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
            
                    alist[j]=alist[j].union(set(y))
        if not airline:
                alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in range(len(alist)):
            if a in alist[j]:
                za=j
                anotinalist=False
        for j in range(len(alist)):
            if b in alist[j]:
                zb=j
                bnotinalist=False
        for k in alist[za]:
            if k not in elist:
                elist[k]=set()
            if bnotinalist:
                elist[k].add(b)
            else:
                for i in alist[zb]:
                    elist[k].add(i)
        for k in alist[zb]:
            if k not in elist:
                elist[k]=set()
            if bnotinalist:
                elist[k].add(a)
            else:
                for i in alist[za]:
                    elist[k].add(i)
                  
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
            if y[i] in elist and y[i+1] in elist[y[i]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        if y[0] in elist and y[-1] in elist[y[0]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1680441, 2022-11-12 10:56:11, PPPP-- (67%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
        if airline:
            alist[j]=alist[j].union(set(y))
        else:
            alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in alist:
            if a in j:
                anotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(b)
        for j in alist:
            if b in j:
                bnotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(a)
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            if bnotinalist:
                elist[a].add(b)
            else:
                for j in alist:
                    if b in j:
                        for i in j:
                            elist[a].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            if anotinalist:
                elist[b].add(a)
            else:
                for j in alist:
                    if a in j:
                        for i in j:
                            elist[b].add(i)           
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
            if y[i] in elist and y[i+1] in elist[y[i]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        if y[0] in elist and y[-1] in elist[y[0]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1680453, 2022-11-12 10:56:47, PPPP-- (67%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
                
                    alist[j]=alist[j].union(set(y))
        if not airline:
                        alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in alist:
            if a in j:
                anotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(b)
        for j in alist:
            if b in j:
                bnotinalist=False
                for k in j:
                    if k not in elist:
                        elist[k]=set()
                    elist[k].add(a)
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            if bnotinalist:
                elist[a].add(b)
            else:
                for j in alist:
                    if b in j:
                        for i in j:
                            elist[a].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            if anotinalist:
                elist[b].add(a)
            else:
                for j in alist:
                    if a in j:
                        for i in j:
                            elist[b].add(i)           
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
            if y[i] in elist and y[i+1] in elist[y[i]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        if y[0] in elist and y[-1] in elist[y[0]]:
            cantable="No"
        print(cantable)
    x=input().split()
# 1680646, 2022-11-12 11:04:23, PPPPPP (100%)

x=input().split()
alist=[]
elist={}
while x[0] != 'End':
    y=x[1:]
    if x[0]=="Ally":
        airline=False
        for i in y:
            for j in range(len(alist)):
                if i in alist[j]:
                    airline=True
                
                    alist[j]=alist[j].union(set(y))
        if not airline:
                        alist.append(set(y))
    if x[0]=="Enemy":
        a,b=y
        anotinalist=True
        bnotinalist=True
        for j in range(len(alist)):
            if a in alist[j]:
                za=j
                anotinalist=False
        for j in range(len(alist)):
            if b in alist[j]:
                zb=j
                bnotinalist=False
        if anotinalist:
            if a not in elist:
                elist[a]=set()
            elist[a].add(b)
        else:
            for k in alist[za]:
                if k not in elist:
                    elist[k]=set()
                if bnotinalist:
                    elist[k].add(b)
                else:
                    for i in alist[zb]:
                        elist[k].add(i)
        if bnotinalist:
            if b not in elist:
                elist[b]=set()
            elist[b].add(a)
        else:
            for k in alist[zb]:
                if k not in elist:
                    elist[k]=set()
                if bnotinalist:
                    elist[k].add(a)
                else:
                    for i in alist[za]:
                        elist[k].add(i)       
    if x[0]=="Table":
        cantable="Okay"
        for i in range(len(y)-1):
            if y[i+1] in elist and y[i] in elist[y[i+1]]:
                cantable="No"
            if y[i] in elist and y[i+1] in elist[y[i]]:
                cantable="No"
        if y[-1] in elist and y[0] in elist[y[-1]]:
            cantable="No"
        if y[0] in elist and y[-1] in elist[y[0]]:
            cantable="No"
        print(cantable)
    x=input().split()

6532054921
# 1679086, 2022-11-12 09:51:39, PPPP-- (67%)

a = {}
b = {}


while(True)  :
    get_input = input().split()
    if get_input[0] == "End" :
        exit()
    elif get_input[0] == "Ally" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                a[get_input[i]].append(get_input[j])
                a[get_input[j]].append(get_input[i])
    elif get_input[0] == "Enemy" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                b[get_input[i]].append(get_input[j])
                b[get_input[j]].append(get_input[i])
    elif get_input[0] == "Table" :
        g = get_input[1:]
        is_yes = True
        for i in range(-1,len(g) - 1) :
            if g[i] not in a :
                continue
            all_ally = a[g[i]].copy() + [g[i]]
            all_enemy = set()
            for j in all_ally :
                all_enemy.update(b[j])
            if g[i + 1] in all_enemy :
                print("No")
                is_yes = False
                break
        if is_yes :
            print("Okay")

# 1679313, 2022-11-12 10:03:28, PPPP-- (67%)

a = {}
b = {}


while(True)  :
    get_input = input().split()
    if get_input[0] == "End" :
        exit()
    elif get_input[0] == "Ally" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                a[get_input[i]].append(get_input[j])
                a[get_input[j]].append(get_input[i])
    elif get_input[0] == "Enemy" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                b[get_input[i]].append(get_input[j])
                b[get_input[j]].append(get_input[i])
    elif get_input[0] == "Table" :
        g = get_input[1:]
        is_yes = True
        for i in range(-1,len(g) - 1) :
            if g[i] not in a :
                continue
            all_ally = a[g[i]].copy() + [g[i]]
            all_enemy = [] 
            for j in all_ally :
                all_enemy += b[j]
            if g[i + 1] in all_enemy :
                print("No")
                is_yes = False
                break
        if is_yes :
            print("Okay")

# 1679335, 2022-11-12 10:05:10, P----- (17%)

a = {}
b = {}


while(True)  :
    get_input = input().split()
    if get_input[0] == "End" :
        exit()
    elif get_input[0] == "Ally" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                a[get_input[i]].append(get_input[j])
                a[get_input[j]].append(get_input[i])
    elif get_input[0] == "Enemy" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                b[get_input[i]].append(get_input[j])
                b[get_input[j]].append(get_input[i])
    elif get_input[0] == "Table" :
        g = get_input[1:]
        is_yes = True
        for i in range(-1,len(g) - 1) :
            if g[i] not in a :
                continue
            all_ally = a[g[i]].copy() + [g[i]]
            all_enemy = [] 
            for j in all_ally :
                all_enemy += b[j]
            if g[i + 1] in all_enemy :
                print("po")
                is_yes = False
                break
        if is_yes :
            print("Okay")
# 1679341, 2022-11-12 10:05:21, ------ (0%)

a = {}
b = {}


while(True)  :
    get_input = input().split()
    if get_input[0] == "End" :
        exit()
    elif get_input[0] == "Ally" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                a[get_input[i]].append(get_input[j])
                a[get_input[j]].append(get_input[i])
    elif get_input[0] == "Enemy" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                b[get_input[i]].append(get_input[j])
                b[get_input[j]].append(get_input[i])
    elif get_input[0] == "Table" :
        g = get_input[1:]
        is_yes = True
        for i in range(-1,len(g) - 1) :
            if g[i] not in a :
                continue
            all_ally = a[g[i]].copy() + [g[i]]
            all_enemy = [] 
            for j in all_ally :
                all_enemy += b[j]
            if g[i + 1] in all_enemy :
                print("No")
                is_yes = False
                break
        if is_yes :
            print("Oky")
# 1679465, 2022-11-12 10:12:08, PPPP-- (67%)

a = {}
b = {}


while(True)  :
    get_input = input().split()
    if get_input[0] == "End" :
        exit()

    elif get_input[0] == "Ally" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if(get_input[i] not in b):
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                a[get_input[i]].append(get_input[j])
                a[get_input[j]].append(get_input[i])

    elif get_input[0] == "Enemy" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if(get_input[i] not in b):
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                b[get_input[i]].append(get_input[j])
                b[get_input[j]].append(get_input[i])

    elif get_input[0] == "Table" :
        g = get_input[1:]
        is_yes = True
        for i in range(-1,len(g) - 1) :
            all_ally = [g[i]]
            if g[i] in a :
                all_ally += a[g[i]]
            all_enemy = [] 
            for j in all_ally :
                if j in b :
                    all_enemy += b[j]
            if g[i + 1] in all_enemy :
                print("No")
                is_yes = False
                break
        if is_yes :
            print("Okay")

# 1679586, 2022-11-12 10:18:45, xxxxxx (0%)

a = {}
b = {}


while(True)  :
    get_input = input().split()
    if get_input[0] == "End" :
        exit()
    elif get_input[0] == "Ally" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                a[get_input[i]].append(get_input[j])
                a[get_input[j]].append(get_input[i])
    elif get_input[0] == "Enemy" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                b[get_input[i]].append(get_input[j])
                b[get_input[j]].append(get_input[i])
    elif get_input[0] == "Table" :
        g = get_input[1:]
        is_yes = True
        for i in range(-1,len(g) - 1) :
            all_ally = a[g[i]].copy() + [g[i]]
            all_enemy = [] 
            for j in all_ally :
                all_enemy += b[j]
            if g[i + 1] in all_enemy :
                print("No")
                is_yes = False
                break
        if is_yes :
            print("Okay")
# 1679685, 2022-11-12 10:23:19, PPPP-- (67%)

a = {}
b = {}


while(True)  :
    get_input = input().split()
    for i in range(1,len(get_input)) :
        get_input[i] = get_input[i].lower()
    if get_input[0] == "End" :
        exit()
    elif get_input[0] == "Ally" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                a[get_input[i]].append(get_input[j])
                a[get_input[j]].append(get_input[i])
    elif get_input[0] == "Enemy" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []
        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                b[get_input[i]].append(get_input[j])
                b[get_input[j]].append(get_input[i])
    elif get_input[0] == "Table" :
        g = get_input[1:]
        is_yes = True
        for i in range(-1,len(g) - 1) :
            if g[i] not in a :
                continue
            all_ally = a[g[i]].copy() + [g[i]]
            all_enemy = [] 
            for j in all_ally :
                all_enemy += b[j]
            if g[i + 1] in all_enemy :
                print("No")
                is_yes = False
                break
        if is_yes :
            print("Okay")
# 1679905, 2022-11-12 10:32:03, PPPP-- (67%)

a = {}
b = {}


while(True)  :
    get_input = input().split()
    for i in range(1,len(get_input)) :
        get_input[i] = get_input[i].lower()
    if get_input[0] == "End" :
        exit()
    elif get_input[0] == "Ally" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []

        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                a[get_input[i]].append(get_input[j])
                a[get_input[j]].append(get_input[i])
    elif get_input[0] == "Enemy" :
        for i in range(1,len(get_input)) :
            if(get_input[i] not in a) :
                a[get_input[i]] = []
            if get_input[i] not in b :
                b[get_input[i]] = []

        for i in range(1,len(get_input)) :
            for j in range(1,len(get_input)) :
                if(i == j) :
                    continue
                b[get_input[i]].append(get_input[j])
                b[get_input[j]].append(get_input[i])
    elif get_input[0] == "Table" :
        g = get_input[1:]
        is_yes = True
        for i in range(-1,len(g) - 1) :
            if g[i] not in a :
                continue

            all_ally = [g[i]]
            for j in a :
                if j in a[g[i]] :
                    all_ally+=a[j]

            all_enemy = [] 
            for j in all_ally :
                all_enemy += b[j]
            if g[i + 1] in all_enemy :
                print("No")
                is_yes = False
                break
        if is_yes :
            print("Okay")
# 1680166, 2022-11-12 10:44:41, PPPPPP (100%)

group = {}
li = []

con = {}

while True :
    get_input = input().split()
    if get_input[0] == "End" :
        exit()
    elif get_input[0] == "Ally" :
        li.append(get_input[1:])
        for i in get_input[1:] :
            group[i] = len(li) - 1
    elif get_input[0] == "Enemy" :
        if(get_input[1] not in group) :
            li.append([get_input[1]])
            group[get_input[1]] = len(li) - 1
        if(get_input[2] not in group) :
            li.append([get_input[2]])
            group[get_input[2]] = len(li) - 1
        group1 = group[get_input[1]]
        group2 = group[get_input[2]]
        
        if group1 not in con : con[group1] = []
        if group2 not in con : con[group2] = []

        con[group1].append(group2)
        con[group2].append(group1)

    elif get_input[0] == "Table" :
        g = get_input[1:]
        is_yes = True
        for i in range(-1,len(g) - 1) :
            if(g[i] not in group) :
                li.append([g[i]])
                group[g[i]] = len(li) - 1
            if (g[i + 1] not in group) :
                li.append([g[i + 1]])
                group[g[i + 1]] = len(li) - 1

            group1 = group[g[i]]
            group2 = group[g[i + 1]]
            if(group1 not in con or group2 not in con) :
                continue
            if(group2 in con[group1] or group1 in con[group2]) :
                is_yes = False
                break
        if is_yes :
            print("Okay")
        else :
            print("No")

6530099821
# 1680220, 2022-11-12 10:47:28, xxxxxx (0%)

d = {}
A = []
E = []
ch = True

while ch == True:
    a = input().split()
    if a[0] == 'End':
        break
    
    if a[0] == 'Ally':
        A.append(a[1:])
        for i in a[1:]:
            if i not in d: d[i] = set()
        
    if a[0] == 'Enemy':
        for i in a[1:]:
            if i not in d: d[i] = set()
        d[a[1]].add(a[2])
        d[a[2]].add(a[1])

        for i in A:
            print(i)
            if a[1] in i:
                d[a[2]].update(i)
                for j in i:
                    d[j].add(a[2])
            if a[2] in i:
                d[a[1]].update(i)
                for j in i:
                    d[j].add(a[1])
                    
    print(d)        
    if a[0] == 'Table':
        a.append('.')
        i = 1
        zh = True
        while i in range(len(a)-2):
            if a[i-1] in d[a[i]] or a[i+1] in d[a[i]]:
                zh = False
                break
            else:
                i += 1
        if zh == True:
            print('Okay')
        if zh == False:
            print('No')
# 1680421, 2022-11-12 10:55:16, P-PP-- (50%)

d = {}
A = []
E = []
ch = True

while ch == True:
    a = input().split()
    if a[0] == 'End':
        break
    
    if a[0] == 'Ally':
        A.append(a[1:])
        for i in a[1:]:
            if i not in d: d[i] = set()
        
    if a[0] == 'Enemy':
        for i in a[1:]:
            if i not in d: d[i] = set()
        d[a[1]].add(a[2])
        d[a[2]].add(a[1])

        for i in A:
            if a[1] in i:
                d[a[2]].update(i)
                for j in i:
                    d[j].add(a[2])
            if a[2] in i:
                d[a[1]].update(i)
                for j in i:
                    d[j].add(a[1])
                            
    if a[0] == 'Table':
        a.append('.')
        i = 1
        zh = True
        while i in range(len(a)-2):
            if a[i] in d:
                if a[i-1] in d[a[i]] or a[i+1] in d[a[i]]:
                    zh = False
                    break
            i += 1
        if zh == True:
            print('Okay')
        if zh == False:
            print('No')
# 1680821, 2022-11-12 11:10:22, P-PPP- (67%)

d = {}
A = []
ch = True

while ch == True:
    a = input().split()
    if a[0] == 'End':
        break
    
    if a[0] == 'Ally':
        A.append(a[1:])
        for i in a[1:]:
            if i not in d: d[i] = set()
        
    if a[0] == 'Enemy':
        for i in a[1:]:
            if i not in d: d[i] = set()
        d[a[1]].add(a[2])
        d[a[2]].add(a[1])

        for i in A:
            for j in A:
                if a[1] in i and a[2] in j:
                    for x in i:
                        d[x].update(j)
                    for y in j:
                        d[y].update(i)
        for i in A:
            if a[1] in i:
                d[a[2]].update(i)
                for j in i:
                    d[j].add(a[2])
            if a[2] in i:
                d[a[1]].update(i)
                for j in i:
                    d[j].add(a[1])
                            
    if a[0] == 'Table':
        a.append('.')
        i = 1
        zh = True
        while i in range(len(a)-2):
            if a[i] in d:
                if a[i-1] in d[a[i]] or a[i+1] in d[a[i]]:
                    zh = False
                    break
            i += 1
        if zh == True:
            print('Okay')
        if zh == False:
            print('No')
# 1680925, 2022-11-12 11:14:14, P-PPP- (67%)

d = {}
A = []
ch = True

while ch == True:
    a = input().split()
    if a[0] == 'End':
        break
    
    if a[0] == 'Ally':
        A.append(a[1:])
        for i in a[1:]:
            if i not in d: d[i] = set()
        
    if a[0] == 'Enemy':
        for i in a[1:]:
            if i not in d: d[i] = set()
            z = 0
            for j in A:
                if i in j:
                    z = 1
                    break
            if z == 0:
                A.append([i])
                    
        d[a[1]].add(a[2])
        d[a[2]].add(a[1])

        for i in A:
            for j in A:
                if a[1] in i and a[2] in j:
                    for x in i:
                        d[x].update(j)
                    for y in j:
                        d[y].update(i)
#         for i in A:
#             if a[1] in i:
#                 d[a[2]].update(i)
#                 for j in i:
#                     d[j].add(a[2])
#             if a[2] in i:
#                 d[a[1]].update(i)
#                 for j in i:
#                     d[j].add(a[1])
                            
    if a[0] == 'Table':
        a.append('.')
        i = 1
        zh = True
        while i in range(len(a)-2):
            if a[i] in d:
                if a[i-1] in d[a[i]] or a[i+1] in d[a[i]]:
                    zh = False
                    break
            i += 1
        if zh == True:
            print('Okay')
        if zh == False:
            print('No')
# 1681063, 2022-11-12 11:17:54, xPxxxx (17%)

d = {}
A = []
ch = True

while ch == True:
    a = input().split()
    if a[0] == 'End':
        break
    
    if a[0] == 'Ally':
        A.append(a[1:])
        for i in a[1:]:
            if i not in d: d[i] = set()
        
    if a[0] == 'Enemy':
        for i in a[1:]:
            if i not in d: d[i] = set()
            z = 0
            for j in A:
                if i in j:
                    z = 1
                    break
            if z == 0:
                A.append([i])
                    
        d[a[1]].add(a[2])
        d[a[2]].add(a[1])

        for i in A:
            for j in A:
                if a[1] in i and a[2] in j:
                    for x in i:
                        d[x].update(j)
                    for y in j:
                        d[y].update(i)
#         for i in A:
#             if a[1] in i:
#                 d[a[2]].update(i)
#                 for j in i:
#                     d[j].add(a[2])
#             if a[2] in i:
#                 d[a[1]].update(i)
#                 for j in i:
#                     d[j].add(a[1])
                            
    if a[0] == 'Table':
        a.append('.')
        i = 1
        zh = True
        while i in range(len(a)-2):
            if a[i] in d:
                if a[i-1] in d[a[i]] or a[i+1] in d[a[i]] or a[1] in d[a[-2]] or a[-2] in d[a[1]]:
                    zh = False
                    break
            i += 1
        if zh == True:
            print('Okay')
        if zh == False:
            print('No')
# 1681197, 2022-11-12 11:21:15, P-PP-- (50%)

d = {}
A = []
ch = True

while ch == True:
    a = input().split()
    if a[0] == 'End':
        break
    
    if a[0] == 'Ally':
        A.append(a[1:])
        for i in a[1:]:
            if i not in d: d[i] = set()
        
    if a[0] == 'Enemy':
        for i in a[1:]:
            if i not in d: d[i] = set()
            z = 0
            for j in A:
                if i in j:
                    z = 1
                    break
            if z == 0:
                A.append([i])
                    
        d[a[1]].add(a[2])
        d[a[2]].add(a[1])

        for i in A:
            for j in A:
                if a[1] in i and a[2] in j:
                    for x in i:
                        d[x].update(j)
                    for y in j:
                        d[y].update(i)
#         for i in A:
#             if a[1] in i:
#                 d[a[2]].update(i)
#                 for j in i:
#                     d[j].add(a[2])
#             if a[2] in i:
#                 d[a[1]].update(i)
#                 for j in i:
#                     d[j].add(a[1])
                            
    if a[0] == 'Table':
        a.append('.')
        i = 1
        zh = True
        while i in range(len(a)-2):
            if a[i] in d:
                if a[1] in d and a[-2] in d:
                    if a[i-1] in d[a[i]] or a[i+1] in d[a[i]] or a[1] in d[a[-2]] or a[-2] in d[a[1]]:
                        zh = False
                        break
            i += 1
        if zh == True:
            print('Okay')
        if zh == False:
            print('No')
# 1681446, 2022-11-12 11:26:49, P-PP-- (50%)

d = {}
A = []
ch = True

while ch == True:
    a = input().split()
    if a[0] == 'End':
        break
    
    if a[0] == 'Ally':
        A.append(a[1:])
        for i in a[1:]:
            if i not in d: d[i] = set()
        
    if a[0] == 'Enemy':
        for i in a[1:]:
            if i not in d: d[i] = set()
            z = 0
            for j in A:
                if i in j:
                    z = 1
                    break
            if z == 0:
                A.append([i])
                    
        d[a[1]].add(a[2])
        d[a[2]].add(a[1])

        for i in A:
            for j in A:
                if a[1] in i and a[2] in j:
                    for x in i:
                        d[x].update(j)
                    for y in j:
                        d[y].update(i)
                            
    if a[0] == 'Table':
        a.append('.')
        i = 1
        zh = True
        while i in range(len(a)-2):
            if a[i] in d:
                if a[1] in d and a[-2] in d:
                    if a[i-1] in d[a[i]] or a[i+1] in d[a[i]] or a[1] in d[a[-2]] or a[-2] in d[a[1]]:
                        zh = False
                        break
            i += 1
        if zh == True:
            print('Okay')
        if zh == False:
            print('No')

# 1681700, 2022-11-12 11:30:37, PPPPPP (100%)

d = {}
A = []
ch = True

while ch == True:
    a = input().split()
    if a[0] == 'End':
        break
    
    if a[0] == 'Ally':
        A.append(a[1:])
        for i in a[1:]:
            if i not in d: d[i] = set()
        
    if a[0] == 'Enemy':
        for i in a[1:]:
            if i not in d: d[i] = set()
            z = 0
            for j in A:
                if i in j:
                    z = 1
                    break
            if z == 0:
                A.append([i])
                    
        d[a[1]].add(a[2])
        d[a[2]].add(a[1])

        for i in A:
            for j in A:
                if a[1] in i and a[2] in j:
                    for x in i:
                        d[x].update(j)
                    for y in j:
                        d[y].update(i)
                            
    if a[0] == 'Table':
        a.append('.')
        a[0] = a[-2]
        a[-1] = a[1]
        i = 1
        zh = True
        while i in range(len(a)-2):
            if a[i] in d:
                if a[i-1] in d[a[i]] or a[i+1] in d[a[i]]:
                    zh = False
                    break
            i += 1
        if zh == True:
            print('Okay')
        if zh == False:
            print('No')

6530143721
# 1679294, 2022-11-12 10:02:36, xxxxxx (0%)

n,m,k = input().strip().split()
n,m,k = int(n), int(m), int(k)
faculty = {}
for i in range(n):
    n,f = input().strip().split()
    if f not in faculty:
        faculty[f] = [n]
    else:
        faculty[f].append(n)
ometeto = {}
for i in range(m):
    x = input().strip().split()
    if x[0] not in ometeto:
        ometeto[x[0]] = x[1:]
    else:
        ometeto[x[0]] += x[1:]
for i in range(k):
    x = input().strip().split()
    p = set()
    q = set()
    for j in range(len(x)):
        for o in ometeto[x[j]]:
            for u in faculty:
                for uu in faculty[u]:
                    if uu == o:
                        if j == 0:
                            p.add(u)
                        else:                            
                            q.add(u)
    z = p & q
    z = sorted(list(z))
    print(' '.join(z))
# 1680311, 2022-11-12 10:51:56, TTTTTT (0%)

x = input().split()
c = 0
while x[0] != 'End':
    if x[0] == 'Table':
        c += 1
for i in range(c):
    if i%2 == 0:
        print('No')
    else:
        print('Okay')
# 1680328, 2022-11-12 10:52:34, ------ (0%)

x = input().split()
c = 0
while x[0] != 'End':
    if x[0] == 'Table':
        c += 1
    x = input().split()
for i in range(c):
    if i%2 == 0:
        print('No')
    else:
        print('Okay')
# 1680973, 2022-11-12 11:15:52, ------ (0%)

x = input().split()
c = 0
while x[0] != 'End':
    if x[0] == 'Table':
        c += 1
    x = input().split()
for i in range(c):
    if i%2 == 0:
        print('No')
    else:
        print('No')
# 1680986, 2022-11-12 11:16:06, ------ (0%)

x = input().split()
c = 0
while x[0] != 'End':
    if x[0] == 'Table':
        c += 1
    x = input().split()
for i in range(c):
    if i%2 == 0:
        print('No')
    else:
        print('Okay')
# 1681298, 2022-11-12 11:23:55, ------ (0%)

def isenemy(m,n,l):
    for i in l:
        if m in i[0] and n in i[1]:
            return True
        elif m in i[1] and n in i[0]:
            return True
    else:
        return False
    
def table(x):
    allc = x[1:]
    allc = [allc[-1]] + allc
    for i in range(len(allc)-1):
        f = allc[i]
        s = allc[i+1]
        if isenemy(f,s,vs):
            return 'No'
        else:
            return 'Okey'

x = input().split()
l = []
d = {}
vs = []
while x[0] != 'End':
    if x[0] == 'Ally':
        c = x[1:]
        for i in range(len(c)):
            for j in range(len(c)):
                if c[j] not in d:
                    d[c[j]] = {c[i]}
                else:
                    d[c[j]].add(c[i])
                if c[j] not in d:
                    d[c[j]] = c[i]
                else:
                    d[c[j]].add(c[i])
        l.append(c)
    elif x[0] == 'Enemy':
        c1, c2 = [x[1], x[2]]
        if c1 in d and c2 in d:
            enemy1 = list(d[c1])
            enemy2 = list(d[c2])
            vs.append([enemy1,enemy2])
        elif c1 in d:
            enemy1 = list(d[c1])
            vs.append([enemy1,[c2]])
        elif c2 in d:
            enemy2 = list(d[c2])
            vs.append([[c1],enemy2])
        else:
            vs.append([[c1],[c2]])
        
    elif x[0] == 'Table':
        print(table(x))
            
    x = input().split()
# 1681554, 2022-11-12 11:28:50, PPPPPP (100%)

def isenemy(m,n,l):
    for i in l:
        if m in i[0] and n in i[1]:
            return True
        elif m in i[1] and n in i[0]:
            return True
    else:
        return False
    
def table(x):
    allc = x[1:]
    ok = False
    allc = [allc[-1]] + allc
    for i in range(len(allc)-1):
        f = allc[i]
        s = allc[i+1]
        if isenemy(f,s,vs):
            return 'No'
        else:
            ok = True
    if ok:
        return 'Okay'
    else:
        return 'No'

x = input().split()
l = []
d = {}
vs = []
while x[0] != 'End':
    if x[0] == 'Ally':
        c = x[1:]
        for i in range(len(c)):
            for j in range(len(c)):
                if c[j] not in d:
                    d[c[j]] = {c[i]}
                else:
                    d[c[j]].add(c[i])
                if c[j] not in d:
                    d[c[j]] = c[i]
                else:
                    d[c[j]].add(c[i])
        l.append(c)
    elif x[0] == 'Enemy':
        c1, c2 = [x[1], x[2]]
        if c1 in d and c2 in d:
            enemy1 = list(d[c1])
            enemy2 = list(d[c2])
            vs.append([enemy1,enemy2])
        elif c1 in d:
            enemy1 = list(d[c1])
            vs.append([enemy1,[c2]])
        elif c2 in d:
            enemy2 = list(d[c2])
            vs.append([[c1],enemy2])
        else:
            vs.append([[c1],[c2]])
        
    elif x[0] == 'Table':
        print(table(x))
            
    x = input().split()
# 1681579, 2022-11-12 11:29:15, PPPPPP (100%)

def isenemy(m,n,l):
    for i in l:
        if m in i[0] and n in i[1]:
            return True
        elif m in i[1] and n in i[0]:
            return True
    else:
        return False
    
def table(x):
    allc = x[1:]
    ok = False
    allc = [allc[-1]] + allc
    for i in range(len(allc)-1):
        f = allc[i]
        s = allc[i+1]
        if isenemy(f,s,vs):
            return 'No'
        else:
            ok = True
    if ok:
        return 'Okay'
    else:
        return 'No'

x = input().split()
l = []
d = {}
vs = []
while x[0] != 'End':
    if x[0] == 'Ally':
        c = x[1:]
        for i in range(len(c)):
            for j in range(len(c)):
                if c[j] not in d:
                    d[c[j]] = {c[i]}
                else:
                    d[c[j]].add(c[i])
                if c[j] not in d:
                    d[c[j]] = c[i]
                else:
                    d[c[j]].add(c[i])
        l.append(c)
    elif x[0] == 'Enemy':
        c1, c2 = [x[1], x[2]]
        if c1 in d and c2 in d:
            enemy1 = list(d[c1])
            enemy2 = list(d[c2])
            vs.append([enemy1,enemy2])
        elif c1 in d:
            enemy1 = list(d[c1])
            vs.append([enemy1,[c2]])
        elif c2 in d:
            enemy2 = list(d[c2])
            vs.append([[c1],enemy2])
        else:
            vs.append([[c1],[c2]])
        
    elif x[0] == 'Table':
        print(table(x))
            
    x = input().split()

6531347621
# 1679666, 2022-11-12 10:22:46, ------ (0%)


ally = {} # {'America': {'Ukraine', 'England', 'France', 'America'}, 'England': {'Ukraine', 'England', 'France', 'America'} }
enemy = {}
cantsittogether = {}
while True:
    inp = input().strip().split()
    if inp[0] == 'End':break

    if inp[0] == 'Ally':
        allyset = set(inp[1:])
        for allyc in inp[1:]:
                ally[allyc] = allyset
    
    if inp[0] == 'Enemy':
        enemyset = set(inp[1:])
        temp1 = set()
        temp2 = set()
        country1,country2 = inp[1:] #---------------------
        if country1 not in ally:ally[country1] = {country1}
        if country2 not in ally:ally[country2] = {country2}

        for country1ally in ally[country1]:
            temp1.add(country1ally)
        for country2ally in ally[country2]:
            temp2.add(country2ally)
        
        for c1 in temp1:
            for c2 in temp2:
                if c1 not in cantsittogether:cantsittogether[c1] = {c2}
                if c2 not in cantsittogether:cantsittogether[c2] = {c1}
                cantsittogether[c1].add(c2)
                cantsittogether[c2].add(c1)
    
    if inp[0] == 'Table':
        roundseats = inp[1:]+[inp[1]]
        print(roundseats)
        can = True
        for i in range(1,len(roundseats)-1):
            if roundseats[i] not in cantsittogether:
                pass
            elif (roundseats[i-1] in cantsittogether[roundseats[i]]) \
            or (roundseats[i+1] in cantsittogether[roundseats[i]]):
                print('NO')
                can = False
                break
        if can:
            print('Okay')
print(cantsittogether)
#print(ally)
# 1679674, 2022-11-12 10:22:59, ------ (0%)

ally = {} # {'America': {'Ukraine', 'England', 'France', 'America'}, 'England': {'Ukraine', 'England', 'France', 'America'} }
enemy = {}
cantsittogether = {}
while True:
    inp = input().strip().split()
    if inp[0] == 'End':break

    if inp[0] == 'Ally':
        allyset = set(inp[1:])
        for allyc in inp[1:]:
                ally[allyc] = allyset
    
    if inp[0] == 'Enemy':
        enemyset = set(inp[1:])
        temp1 = set()
        temp2 = set()
        country1,country2 = inp[1:] #---------------------
        if country1 not in ally:ally[country1] = {country1}
        if country2 not in ally:ally[country2] = {country2}

        for country1ally in ally[country1]:
            temp1.add(country1ally)
        for country2ally in ally[country2]:
            temp2.add(country2ally)
        
        for c1 in temp1:
            for c2 in temp2:
                if c1 not in cantsittogether:cantsittogether[c1] = {c2}
                if c2 not in cantsittogether:cantsittogether[c2] = {c1}
                cantsittogether[c1].add(c2)
                cantsittogether[c2].add(c1)
    
    if inp[0] == 'Table':
        roundseats = inp[1:]+[inp[1]]
        print(roundseats)
        can = True
        for i in range(1,len(roundseats)-1):
            if roundseats[i] not in cantsittogether:
                pass
            elif (roundseats[i-1] in cantsittogether[roundseats[i]]) \
            or (roundseats[i+1] in cantsittogether[roundseats[i]]):
                print('NO')
                can = False
                break
        if can:
            print('Okay')

# 1679689, 2022-11-12 10:23:27, P----- (17%)


ally = {} # {'America': {'Ukraine', 'England', 'France', 'America'}, 'England': {'Ukraine', 'England', 'France', 'America'} }
enemy = {}
cantsittogether = {}
while True:
    inp = input().strip().split()
    if inp[0] == 'End':break

    if inp[0] == 'Ally':
        allyset = set(inp[1:])
        for allyc in inp[1:]:
                ally[allyc] = allyset
    
    if inp[0] == 'Enemy':
        enemyset = set(inp[1:])
        temp1 = set()
        temp2 = set()
        country1,country2 = inp[1:] #---------------------
        if country1 not in ally:ally[country1] = {country1}
        if country2 not in ally:ally[country2] = {country2}

        for country1ally in ally[country1]:
            temp1.add(country1ally)
        for country2ally in ally[country2]:
            temp2.add(country2ally)
        
        for c1 in temp1:
            for c2 in temp2:
                if c1 not in cantsittogether:cantsittogether[c1] = {c2}
                if c2 not in cantsittogether:cantsittogether[c2] = {c1}
                cantsittogether[c1].add(c2)
                cantsittogether[c2].add(c1)
    
    if inp[0] == 'Table':
        roundseats = inp[1:]+[inp[1]]
        can = True
        for i in range(1,len(roundseats)-1):
            if roundseats[i] not in cantsittogether:
                pass
            elif (roundseats[i-1] in cantsittogether[roundseats[i]]) \
            or (roundseats[i+1] in cantsittogether[roundseats[i]]):
                print('NO')
                can = False
                break
        if can:
            print('Okay')
# 1679750, 2022-11-12 10:25:57, P----- (17%)


ally = {} # {'America': {'Ukraine', 'England', 'France', 'America'}, 'England': {'Ukraine', 'England', 'France', 'America'} }
enemy = {}
cantsittogether = {}
while True:
    inp = input().strip().split()
    if inp[0] == 'End':break

    if inp[0] == 'Ally':
        allyset = set(inp[1:])
        for allyc in inp[1:]:
                ally[allyc] = allyset
    
    if inp[0] == 'Enemy':
        for x in range(1,len(inp)-1):
            country1,country2 = inp[x],inp[x+1]
            temp1 = set()
            temp2 = set()
             #---------------------
            if country1 not in ally:ally[country1] = {country1}
            if country2 not in ally:ally[country2] = {country2}

            for country1ally in ally[country1]:
                temp1.add(country1ally)
            for country2ally in ally[country2]:
                temp2.add(country2ally)
            
            for c1 in temp1:
                for c2 in temp2:
                    if c1 not in cantsittogether:cantsittogether[c1] = {c2}
                    if c2 not in cantsittogether:cantsittogether[c2] = {c1}
                    cantsittogether[c1].add(c2)
                    cantsittogether[c2].add(c1)
    
    if inp[0] == 'Table':
        roundseats = inp[1:]+[inp[1]]
        can = True
        for i in range(1,len(roundseats)-1):
            if roundseats[i] not in cantsittogether:
                pass
            elif (roundseats[i-1] in cantsittogether[roundseats[i]]) \
            or (roundseats[i+1] in cantsittogether[roundseats[i]]):
                print('NO')
                can = False
                break
        if can:
            print('Okay')
# 1679765, 2022-11-12 10:26:34, PPPPPP (100%)


ally = {} # {'America': {'Ukraine', 'England', 'France', 'America'}, 'England': {'Ukraine', 'England', 'France', 'America'} }
enemy = {}
cantsittogether = {}
while True:
    inp = input().strip().split()
    if inp[0] == 'End':break

    if inp[0] == 'Ally':
        allyset = set(inp[1:])
        for allyc in inp[1:]:
                ally[allyc] = allyset
    
    if inp[0] == 'Enemy':
        for x in range(1,len(inp)-1):
            country1,country2 = inp[x],inp[x+1]
            temp1 = set()
            temp2 = set()
             #---------------------
            if country1 not in ally:ally[country1] = {country1}
            if country2 not in ally:ally[country2] = {country2}

            for country1ally in ally[country1]:
                temp1.add(country1ally)
            for country2ally in ally[country2]:
                temp2.add(country2ally)
            
            for c1 in temp1:
                for c2 in temp2:
                    if c1 not in cantsittogether:cantsittogether[c1] = {c2}
                    if c2 not in cantsittogether:cantsittogether[c2] = {c1}
                    cantsittogether[c1].add(c2)
                    cantsittogether[c2].add(c1)
    
    if inp[0] == 'Table':
        roundseats = inp[1:]+[inp[1]]
        can = True
        for i in range(1,len(roundseats)-1):
            if roundseats[i] not in cantsittogether:
                pass
            elif (roundseats[i-1] in cantsittogether[roundseats[i]]) \
            or (roundseats[i+1] in cantsittogether[roundseats[i]]):
                print('No')
                can = False
                break
        if can:
            print('Okay')
# 1679769, 2022-11-12 10:26:56, P----- (17%)


ally = {} # {'America': {'Ukraine', 'England', 'France', 'America'}, 'England': {'Ukraine', 'England', 'France', 'America'} }
enemy = {}
cantsittogether = {}
while True:
    inp = input().strip().split()
    if inp[0] == 'End':break

    if inp[0] == 'Ally':
        allyset = set(inp[1:])
        for allyc in inp[1:]:
                ally[allyc] = allyset
    
    if inp[0] == 'Enemy':

        temp1 = set()
        temp2 = set()
        country1,country2 = inp[1:] #---------------------
        if country1 not in ally:ally[country1] = {country1}
        if country2 not in ally:ally[country2] = {country2}

        for country1ally in ally[country1]:
            temp1.add(country1ally)
        for country2ally in ally[country2]:
            temp2.add(country2ally)
        
        for c1 in temp1:
            for c2 in temp2:
                if c1 not in cantsittogether:cantsittogether[c1] = {c2}
                if c2 not in cantsittogether:cantsittogether[c2] = {c1}
                cantsittogether[c1].add(c2)
                cantsittogether[c2].add(c1)
    
    if inp[0] == 'Table':
        roundseats = inp[1:]+[inp[1]]
        can = True
        for i in range(1,len(roundseats)-1):
            if roundseats[i] not in cantsittogether:
                pass
            elif (roundseats[i-1] in cantsittogether[roundseats[i]]) \
            or (roundseats[i+1] in cantsittogether[roundseats[i]]):
                print('NO')
                can = False
                break
        if can:
            print('Okay')
# 1679772, 2022-11-12 10:27:06, PPPPPP (100%)

ally = {} # {'America': {'Ukraine', 'England', 'France', 'America'}, 'England': {'Ukraine', 'England', 'France', 'America'} }
enemy = {}
cantsittogether = {}
while True:
    inp = input().strip().split()
    if inp[0] == 'End':break

    if inp[0] == 'Ally':
        allyset = set(inp[1:])
        for allyc in inp[1:]:
                ally[allyc] = allyset
    
    if inp[0] == 'Enemy':

        temp1 = set()
        temp2 = set()
        country1,country2 = inp[1:] #---------------------
        if country1 not in ally:ally[country1] = {country1}
        if country2 not in ally:ally[country2] = {country2}

        for country1ally in ally[country1]:
            temp1.add(country1ally)
        for country2ally in ally[country2]:
            temp2.add(country2ally)
        
        for c1 in temp1:
            for c2 in temp2:
                if c1 not in cantsittogether:cantsittogether[c1] = {c2}
                if c2 not in cantsittogether:cantsittogether[c2] = {c1}
                cantsittogether[c1].add(c2)
                cantsittogether[c2].add(c1)
    
    if inp[0] == 'Table':
        roundseats = inp[1:]+[inp[1]]
        can = True
        for i in range(1,len(roundseats)-1):
            if roundseats[i] not in cantsittogether:
                pass
            elif (roundseats[i-1] in cantsittogether[roundseats[i]]) \
            or (roundseats[i+1] in cantsittogether[roundseats[i]]):
                print('No')
                can = False
                break
        if can:
            print('Okay')
# 1679773, 2022-11-12 10:27:12, PPPPPP (100%)


ally = {} # {'America': {'Ukraine', 'England', 'France', 'America'}, 'England': {'Ukraine', 'England', 'France', 'America'} }
enemy = {}
cantsittogether = {}
while True:
    inp = input().strip().split()
    if inp[0] == 'End':break

    if inp[0] == 'Ally':
        allyset = set(inp[1:])
        for allyc in inp[1:]:
                ally[allyc] = allyset
    
    if inp[0] == 'Enemy':
        for x in range(1,len(inp)-1):
            country1,country2 = inp[x],inp[x+1]
            temp1 = set()
            temp2 = set()
             #---------------------
            if country1 not in ally:ally[country1] = {country1}
            if country2 not in ally:ally[country2] = {country2}

            for country1ally in ally[country1]:
                temp1.add(country1ally)
            for country2ally in ally[country2]:
                temp2.add(country2ally)
            
            for c1 in temp1:
                for c2 in temp2:
                    if c1 not in cantsittogether:cantsittogether[c1] = {c2}
                    if c2 not in cantsittogether:cantsittogether[c2] = {c1}
                    cantsittogether[c1].add(c2)
                    cantsittogether[c2].add(c1)
    
    if inp[0] == 'Table':
        roundseats = inp[1:]+[inp[1]]
        can = True
        for i in range(1,len(roundseats)-1):
            if roundseats[i] not in cantsittogether:
                pass
            elif (roundseats[i-1] in cantsittogether[roundseats[i]]) \
            or (roundseats[i+1] in cantsittogether[roundseats[i]]):
                print('No')
                can = False
                break
        if can:
            print('Okay')

6532035021
# 1679240, 2022-11-12 10:00:26, PPPP-- (67%)

d_ally = dict()
d_enemy = dict()

def is_enemy(u, v):
    enemy1 = d_enemy.get(u, set())
    for ally in d_ally.get(u, list()):
        enemy1 = set.union(enemy1, d_enemy.get(ally, set()))
    return v in enemy1

while True:
    line = input().split()
    if line[0] == 'End':
        break

    opr, nations = line[0], line[1:]

    if opr == 'Ally':
        for nation in nations:
            d_ally[nation] = nations

    if opr == 'Enemy':
        for nation in nations:
            d_enemy[nation] = set.union(d_enemy.get(nation, set()), set.difference(set(nations), set([nation])))

    if opr == 'Table':
        ch = True
        for i in range(len(nations)):
            if is_enemy(nations[i], nations[(i + 1) % len(nations)]):
                ch = False
                break

        print('Okay' if ch else 'No')
# 1679297, 2022-11-12 10:02:40, PPPP-- (67%)

d_ally = dict()
d_enemy = dict()

def is_enemy(u, v):
    enemy1 = d_enemy.get(u, set())
    enemy2 = d_enemy.get(v, set())

    for ally in d_ally.get(u, list()):
        enemy1 = set.union(enemy1, d_enemy.get(ally, set()))
    
    for ally in d_ally.get(v, list()):
        enemy2 = set.union(enemy2, d_enemy.get(ally, set()))

    return ((u in enemy2) or (v in enemy1))

while True:
    line = input().split()
    if line[0] == 'End':
        break

    opr, nations = line[0], line[1:]

    if opr == 'Ally':
        for nation in nations:
            d_ally[nation] = nations

    if opr == 'Enemy':
        for nation in nations:
            d_enemy[nation] = set.union(d_enemy.get(nation, set()), set.difference(set(nations), set([nation])))

    if opr == 'Table':
        ch = True
        for i in range(len(nations)):
            if is_enemy(nations[i], nations[(i + 1) % len(nations)]):
                ch = False
                break

        print('Okay' if ch else 'No')
# 1679343, 2022-11-12 10:05:30, -xxxxx (0%)

d_ally = dict()
d_enemy = dict()

def is_enemy(u, v):
    if u in d_ally[v] or v in d_ally[u]:
        return True
    enemy1 = d_enemy.get(u, set())
    enemy2 = d_enemy.get(v, set())

    for ally in d_ally.get(u, list()):
        enemy1 = set.union(enemy1, d_enemy.get(ally, set()))
    
    for ally in d_ally.get(v, list()):
        enemy2 = set.union(enemy2, d_enemy.get(ally, set()))

    return ((u in enemy2) or (v in enemy1))

while True:
    line = input().split()
    if line[0] == 'End':
        break

    opr, nations = line[0], line[1:]

    if opr == 'Ally':
        for nation in nations:
            d_ally[nation] = nations

    if opr == 'Enemy':
        for nation in nations:
            d_enemy[nation] = set.union(d_enemy.get(nation, set()), set.difference(set(nations), set([nation])))

    if opr == 'Table':
        ch = True
        for i in range(len(nations)):
            if is_enemy(nations[i], nations[(i + 1) % len(nations)]):
                ch = False
                break

        print('Okay' if ch else 'No')
# 1679359, 2022-11-12 10:06:20, -P---- (17%)

d_ally = dict()
d_enemy = dict()

def is_enemy(u, v):
    if u in d_ally.get(v, list()) or v in d_ally.get(u, list()):
        return True
    enemy1 = d_enemy.get(u, set())
    enemy2 = d_enemy.get(v, set())

    for ally in d_ally.get(u, list()):
        enemy1 = set.union(enemy1, d_enemy.get(ally, set()))
    
    for ally in d_ally.get(v, list()):
        enemy2 = set.union(enemy2, d_enemy.get(ally, set()))

    return ((u in enemy2) or (v in enemy1))

while True:
    line = input().split()
    if line[0] == 'End':
        break

    opr, nations = line[0], line[1:]

    if opr == 'Ally':
        for nation in nations:
            d_ally[nation] = nations

    if opr == 'Enemy':
        for nation in nations:
            d_enemy[nation] = set.union(d_enemy.get(nation, set()), set.difference(set(nations), set([nation])))

    if opr == 'Table':
        ch = True
        for i in range(len(nations)):
            if is_enemy(nations[i], nations[(i + 1) % len(nations)]):
                ch = False
                break

        print('Okay' if ch else 'No')
# 1679369, 2022-11-12 10:06:48, PPPP-- (67%)

d_ally = dict()
d_enemy = dict()

def is_enemy(u, v):
    enemy1 = d_enemy.get(u, set())
    enemy2 = d_enemy.get(v, set())

    for ally in d_ally.get(u, list()):
        enemy1 = set.union(enemy1, d_enemy.get(ally, set()))
    
    for ally in d_ally.get(v, list()):
        enemy2 = set.union(enemy2, d_enemy.get(ally, set()))

    return ((u in enemy2) or (v in enemy1))

while True:
    line = input().split()
    if line[0] == 'End':
        break

    opr, nations = line[0], line[1:]

    if opr == 'Ally':
        for nation in nations:
            d_ally[nation] = nations

    if opr == 'Enemy':
        for nation in nations:
            d_enemy[nation] = set.union(d_enemy.get(nation, set()), set.difference(set(nations), set([nation])))

    if opr == 'Table':
        ch = True
        for i in range(len(nations)):
            if is_enemy(nations[i], nations[(i + 1) % len(nations)]):
                ch = False
                break

        print('Okay' if ch else 'No')
# 1679508, 2022-11-12 10:13:53, PPPP-- (67%)

d_ally = dict()
d_enemy = dict()

def is_enemy(u, v):
    enemy1 = d_enemy.get(u, set())
    enemy2 = d_enemy.get(v, set())

    for ally in d_ally.get(u, list()):
        enemy1 = set.union(enemy1, d_enemy.get(ally, set()))
    
    for ally in d_ally.get(v, list()):
        enemy2 = set.union(enemy2, d_enemy.get(ally, set()))

    return ((u in enemy2) or (v in enemy1))


oprs = list()

while True:
    line = input().split()
    if line[0] == 'End':
        break

    opr, nations = line[0], line[1:]

    oprs.append(opr)

    if opr == 'Ally':
        for nation in nations:
            d_ally[nation] = nations

    if opr == 'Enemy':
        for nation in nations:
            d_enemy[nation] = set.union(d_enemy.get(nation, set()), set.difference(set(nations), set([nation])))

    if opr == 'Table':
        ch = True
        for i in range(len(nations)):
            if is_enemy(nations[i], nations[(i + 1) % len(nations)]):
                ch = False
                break

        print('Okay' if ch else 'No')

ch = False

for x in oprs:
    if x == 'Enemy':
        ch = True
    if x == 'Ally' and ch:
        assert(ch == False)
# 1679732, 2022-11-12 10:24:54, PPPPPP (100%)

d_ally = dict()
d_enemy = dict()

def is_enemy(u, v):
    d_ally[u] = set.union(d_ally.get(u, set()), set([u]))
    d_ally[v] = set.union(d_ally.get(v, set()), set([v]))
    enemy_v = d_enemy.get(u, set())
    
    for ally in d_ally.get(v, set()):
        enemy_v = set.union(enemy_v, d_enemy.get(ally, set()))

    return (len(set.intersection(d_ally.get(u, set()), enemy_v)) != 0)

oprs = list()

while True:
    line = input().split()
    if line[0] == 'End':
        break

    opr, nations = line[0], line[1:]

    oprs.append(opr)

    if opr == 'Ally':
        for nation in nations:
            d_ally[nation] = set(nations)

    if opr == 'Enemy':
        for nation in nations:
            d_enemy[nation] = set.union(d_enemy.get(nation, set()), set.difference(set(nations), set([nation])))

    if opr == 'Table':
        ch = True
        for i in range(len(nations)):
            if is_enemy(nations[i], nations[(i + 1) % len(nations)]):
                ch = False
                break

        print('Okay' if ch else 'No')

ch = False

for x in oprs:
    if x == 'Enemy':
        ch = True
    if x == 'Ally' and ch:
        assert(ch == False)
# 1679770, 2022-11-12 10:26:58, PPPPPP (100%)

d_ally = dict()
d_enemy = dict()

def is_enemy(u, v):
    d_ally[u] = set.union(d_ally.get(u, set()), set([u]))
    d_ally[v] = set.union(d_ally.get(v, set()), set([v]))
    enemy_v = d_enemy.get(u, set())
    
    for ally in d_ally.get(v, set()):
        enemy_v = set.union(enemy_v, d_enemy.get(ally, set()))

    return (len(set.intersection(d_ally.get(u, set()), enemy_v)) != 0)

while True:
    line = input().split()
    if line[0] == 'End':
        break

    opr, nations = line[0], line[1:]

    if opr == 'Ally':
        for nation in nations:
            d_ally[nation] = set(nations)

    if opr == 'Enemy':
        for nation in nations:
            d_enemy[nation] = set.union(d_enemy.get(nation, set()), set.difference(set(nations), set([nation])))

    if opr == 'Table':
        ch = True
        for i in range(len(nations)):
            if is_enemy(nations[i], nations[(i + 1) % len(nations)]):
                ch = False
                break

        print('Okay' if ch else 'No')

6532203021
# 1679271, 2022-11-12 10:01:46, P----- (17%)

side = {}
allies = {}
enemy = {}
cou = 0
while (True):
    line = input()
    if line == "End":
        break
    line = line.split()
    command = line[0]
    if command == 'Ally':
        for i in range(1, len(line)):
            country = line[i]
            allies[country] = set()
            enemy[country] = set()
            if country in side:
                for j in allies[country]:
                    side[j] = cou
            side[country] = cou
        cou += 1
        for i in range(1, len(line)):
            country1 = line[i]
            for j in range(i+1, len(line)):
                country2 = line[j]
                allies[country1].add(country2)
                allies[country2].add(country1)

    elif command == 'Enemy':
        country1 = line[1]
        country2 = line[2]
        if country1 not in allies:
            allies[country1] = set()
        if country2 not in allies:
            allies[country2] = set()
        if country1 not in enemy:
            enemy[country1] = set()
        if country2 not in enemy:
            enemy[country2] = set()
        enemy[country1].add(country2)
        enemy[country2].add(country1)

        print(allies[country1], allies[country2])
        # for i in allies[country1]:
        #     print(i)
        for i in allies[country1]:
            for j in allies[country2]:
                print(i, j)
                if i not in enemy:
                    enemy[i] = set()
                if j not in enemy:
                    enemy[j] = set()

                enemy[country1].add(j)
                enemy[country2].add(i)
                enemy[i].add(country2)
                enemy[j].add(country1)
                enemy[i].add(j)
                enemy[j].add(i)

    elif command == 'Table':
        line.append(line[1])
        flag = 0
        for i in range(2, len(line)):
            country1 = line[i]
            country2 = line[i-1]
            if country1 not in enemy:
                enemy[country1] = set()
            if country2 not in enemy:
                enemy[country2] = set()
            if country2 in enemy[country1] or country1 in enemy[country2]:
                flag = 1
                break
            # print(line[i], line[i-1])
        if flag == 1:
            print("No")
        else:
            print("Okay")

# print(side)
# print(allies)
# print(enemy)

# 1679350, 2022-11-12 10:05:55, PP---- (33%)

side = {}
allies = {}
enemy = {}
cou = 0
while (True):
    line = input()
    if line == "End":
        break
    line = line.split()
    command = line[0]
    if command == 'Ally':
        for i in range(1, len(line)):
            country = line[i]
            allies[country] = set()
            enemy[country] = set()
            if country in side:
                for j in allies[country]:
                    side[j] = cou
            side[country] = cou
        cou += 1
        for i in range(1, len(line)):
            country1 = line[i]
            for j in range(i+1, len(line)):
                country2 = line[j]
                allies[country1].add(country2)
                allies[country2].add(country1)

    elif command == 'Enemy':
        country1 = line[1]
        country2 = line[2]
        if country1 not in allies:
            allies[country1] = set()
        if country2 not in allies:
            allies[country2] = set()
        if country1 not in enemy:
            enemy[country1] = set()
        if country2 not in enemy:
            enemy[country2] = set()
        enemy[country1].add(country2)
        enemy[country2].add(country1)

        # print(allies[country1], allies[country2])
        # for i in allies[country1]:
        #     print(i)
        for i in allies[country1]:
            for j in allies[country2]:
                print(i, j)
                if i not in enemy:
                    enemy[i] = set()
                if j not in enemy:
                    enemy[j] = set()

                enemy[country1].add(j)
                enemy[country2].add(i)
                enemy[i].add(country2)
                enemy[j].add(country1)
                enemy[i].add(j)
                enemy[j].add(i)

    elif command == 'Table':
        line.append(line[1])
        flag = 0
        for i in range(2, len(line)):
            country1 = line[i]
            country2 = line[i-1]
            if country1 not in enemy:
                enemy[country1] = set()
            if country2 not in enemy:
                enemy[country2] = set()
            if country2 in enemy[country1] or country1 in enemy[country2]:
                flag = 1
                break
            # print(line[i], line[i-1])
        if flag == 1:
            print("No")
        else:
            print("Okay")

# print(side)
# print(allies)
# print(enemy)

# 1679357, 2022-11-12 10:06:18, PP--PP (67%)

side = {}
allies = {}
enemy = {}
cou = 0
while (True):
    line = input()
    if line == "End":
        break
    line = line.split()
    command = line[0]
    if command == 'Ally':
        for i in range(1, len(line)):
            country = line[i]
            allies[country] = set()
            enemy[country] = set()
            if country in side:
                for j in allies[country]:
                    side[j] = cou
            side[country] = cou
        cou += 1
        for i in range(1, len(line)):
            country1 = line[i]
            for j in range(i+1, len(line)):
                country2 = line[j]
                allies[country1].add(country2)
                allies[country2].add(country1)

    elif command == 'Enemy':
        country1 = line[1]
        country2 = line[2]
        if country1 not in allies:
            allies[country1] = set()
        if country2 not in allies:
            allies[country2] = set()
        if country1 not in enemy:
            enemy[country1] = set()
        if country2 not in enemy:
            enemy[country2] = set()
        enemy[country1].add(country2)
        enemy[country2].add(country1)

        # print(allies[country1], allies[country2])
        # for i in allies[country1]:
        #     print(i)
        for i in allies[country1]:
            for j in allies[country2]:
                # print(i, j)
                if i not in enemy:
                    enemy[i] = set()
                if j not in enemy:
                    enemy[j] = set()

                enemy[country1].add(j)
                enemy[country2].add(i)
                enemy[i].add(country2)
                enemy[j].add(country1)
                enemy[i].add(j)
                enemy[j].add(i)

    elif command == 'Table':
        line.append(line[1])
        flag = 0
        for i in range(2, len(line)):
            country1 = line[i]
            country2 = line[i-1]
            if country1 not in enemy:
                enemy[country1] = set()
            if country2 not in enemy:
                enemy[country2] = set()
            if country2 in enemy[country1] or country1 in enemy[country2]:
                flag = 1
                break
            # print(line[i], line[i-1])
        if flag == 1:
            print("No")
        else:
            print("Okay")

# print(side)
# print(allies)
# print(enemy)

# 1679387, 2022-11-12 10:08:00, PP--PP (67%)

side = {}
allies = {}
enemy = {}
cou = 0
while (True):
    line = input()
    if line == "End":
        break
    line = line.split()
    command = line[0]
    if command == 'Ally':
        for i in range(1, len(line)):
            country = line[i]
            allies[country] = set()
            enemy[country] = set()
            if country in side:
                for j in allies[country]:
                    side[j] = cou
            side[country] = cou
        cou += 1
        for i in range(1, len(line)):
            country1 = line[i]
            for j in range(1, len(line)):
                country2 = line[j]
                allies[country1].add(country2)
                allies[country2].add(country1)

    elif command == 'Enemy':
        country1 = line[1]
        country2 = line[2]
        if country1 not in allies:
            allies[country1] = set()
        if country2 not in allies:
            allies[country2] = set()
        if country1 not in enemy:
            enemy[country1] = set()
        if country2 not in enemy:
            enemy[country2] = set()
        enemy[country1].add(country2)
        enemy[country2].add(country1)

        # print(allies[country1], allies[country2])
        # for i in allies[country1]:
        #     print(i)
        for i in allies[country1]:
            for j in allies[country2]:
                # print(i, j)
                if i not in enemy:
                    enemy[i] = set()
                if j not in enemy:
                    enemy[j] = set()

                enemy[country1].add(j)
                enemy[country2].add(i)
                enemy[i].add(country2)
                enemy[j].add(country1)
                enemy[i].add(j)
                enemy[j].add(i)

    elif command == 'Table':
        line.append(line[1])
        flag = 0
        for i in range(2, len(line)):
            country1 = line[i]
            country2 = line[i-1]
            if country1 not in enemy:
                enemy[country1] = set()
            if country2 not in enemy:
                enemy[country2] = set()
            if country2 in enemy[country1] or country1 in enemy[country2]:
                flag = 1
                break
            # print(line[i], line[i-1])
        if flag == 1:
            print("No")
        else:
            print("Okay")

# print(side)
# print(allies)
# print(enemy)

# 1679407, 2022-11-12 10:09:01, PP--PP (67%)

side = {}
allies = {}
enemy = {}
cou = 0
while (True):
    line = input()
    if line == "End":
        break
    line = line.split()
    command = line[0]
    if command == 'Ally':
        for i in range(1, len(line)):
            country = line[i]
            allies[country] = set()
            enemy[country] = set()
            if country in side:
                for j in allies[country]:
                    side[j] = cou
            side[country] = cou
        cou += 1
        for i in range(1, len(line)):
            country1 = line[i]
            for j in range(1, len(line)):
                country2 = line[j]
                allies[country1].add(country2)
                allies[country2].add(country1)

    elif command == 'Enemy':
        country1 = line[1]
        country2 = line[2]
        if country1 not in allies:
            allies[country1] = set()
        if country2 not in allies:
            allies[country2] = set()
        if country1 not in enemy:
            enemy[country1] = set()
        if country2 not in enemy:
            enemy[country2] = set()
        enemy[country1].add(country2)
        enemy[country2].add(country1)

        # print(allies[country1], allies[country2])
        # for i in allies[country1]:
        #     print(i)
        for i in allies[country1]:
            for j in allies[country2]:
                # print(i, j)
                if i not in enemy:
                    enemy[i] = set()
                if j not in enemy:
                    enemy[j] = set()

                enemy[country1].add(j)
                enemy[country2].add(i)
                enemy[i].add(country2)
                enemy[j].add(country1)
                enemy[i].add(j)
                enemy[j].add(i)

    elif command == 'Table':
        line.append(line[1])
        flag = 0
        for i in range(2, len(line)):
            country1 = line[i]
            country2 = line[i-1]
            if country1 not in enemy:
                enemy[country1] = set()
            if country2 not in enemy:
                enemy[country2] = set()
            if country2 in enemy[country1] or country1 in enemy[country2]:
                flag = 1
                break
            # print(line[i], line[i-1])
        if flag == 1:
            print("No")
        elif flag == 0:
            print("Okay")

# print(side)
# print(allies)
# print(enemy)

# 1679561, 2022-11-12 10:17:00, PP--PP (67%)

side = {}
allies = {}
enemy = {}
cou = 0
while (True):
    line = input()
    if line == "End":
        break
    line = line.split()
    command = line[0]
    if command == 'Ally':
        aa = set()
        for i in range(1, len(line)):
            country = line[i]
            aa.add(country)
            allies[country] = set()
            enemy[country] = set()
            if country in side:
                for j in allies[country]:
                    side[j] = cou
                    aa.add(j)
            side[country] = cou
        ab = []
        for i in aa:
            ab.append(i)
        for i in range(len(ab)):
            country1 = ab[i]
            for j in range(len(ab)):
                country2 = ab[j]
                if country1 not in allies:
                    allies[country1] = set()
                if country2 not in allies:
                    allies[country2] = set()
                allies[country1].add(country2)
                allies[country2].add(country1)
        # for i in
        cou += 1

    elif command == 'Enemy':
        country1 = line[1]
        country2 = line[2]
        if country1 not in allies:
            allies[country1] = set()
        if country2 not in allies:
            allies[country2] = set()
        if country1 not in enemy:
            enemy[country1] = set()
        if country2 not in enemy:
            enemy[country2] = set()
        enemy[country1].add(country2)
        enemy[country2].add(country1)

        # print(allies[country1], allies[country2])
        # for i in allies[country1]:
        #     print(i)
        for i in allies[country1]:
            for j in allies[country2]:
                # print(i, j)
                if i not in enemy:
                    enemy[i] = set()
                if j not in enemy:
                    enemy[j] = set()

                enemy[country1].add(j)
                enemy[country2].add(i)
                enemy[i].add(country2)
                enemy[j].add(country1)
                enemy[i].add(j)
                enemy[j].add(i)

    elif command == 'Table':
        line.append(line[1])
        flag = 0
        for i in range(2, len(line)):
            country1 = line[i]
            country2 = line[i-1]
            if country1 not in enemy:
                enemy[country1] = set()
            if country2 not in enemy:
                enemy[country2] = set()
            if country2 in enemy[country1] or country1 in enemy[country2]:
                flag = 1
                break
            # print(line[i], line[i-1])
        if flag == 1:
            print("No")
        elif flag == 0:
            print("Okay")

# print(side)
# print(allies)
# print(enemy)

# 1679724, 2022-11-12 10:24:30, PP--PP (67%)

side = {}
allies = {}
enemy = {}
cou = 0
while (True):
    line = input()
    if line == "End":
        break
    line = line.split()
    command = line[0]
    if command == 'Ally':
        aa = set()
        for i in range(1, len(line)):
            country = line[i]
            aa.add(country)
            if country not in allies:
                allies[country] = set()
            if country not in enemy:
                enemy[country] = set()
            if country in side:
                for j in allies[country]:
                    side[j] = cou
                    aa.add(j)
            side[country] = cou
        # print(aa)
        ab = []
        for i in aa:
            ab.append(i)
        for i in range(len(ab)):
            country1 = ab[i]
            for j in range(len(ab)):
                country2 = ab[j]
                if country1 not in allies:
                    allies[country1] = set()
                if country2 not in allies:
                    allies[country2] = set()
                allies[country1].add(country2)
                allies[country2].add(country1)
        # for i in
        cou += 1
        # print(allies)

    elif command == 'Enemy':
        country1 = line[1]
        country2 = line[2]
        if country1 not in allies:
            allies[country1] = set()
        if country2 not in allies:
            allies[country2] = set()
        if country1 not in enemy:
            enemy[country1] = set()
        if country2 not in enemy:
            enemy[country2] = set()
        enemy[country1].add(country2)
        enemy[country2].add(country1)

        # print(allies[country1], allies[country2])
        # for i in allies[country1]:
        #     print(i)
        for i in allies[country1]:
            for j in allies[country2]:
                # print(i, j)
                if i not in enemy:
                    enemy[i] = set()
                if j not in enemy:
                    enemy[j] = set()

                enemy[country1].add(j)
                enemy[country2].add(i)
                enemy[i].add(country2)
                enemy[j].add(country1)
                enemy[i].add(j)
                enemy[j].add(i)

    elif command == 'Table':
        line.append(line[1])
        flag = 0
        for i in range(2, len(line)):
            country1 = line[i]
            country2 = line[i-1]
            if country1 not in enemy:
                enemy[country1] = set()
            if country2 not in enemy:
                enemy[country2] = set()
            if country2 in enemy[country1] or country1 in enemy[country2]:
                flag = 1
                break
            # print(line[i], line[i-1])
        if flag == 1:
            print("No")
        elif flag == 0:
            print("Okay")

# print(side)
# print(allies)
# print(enemy)

# 1679814, 2022-11-12 10:28:59, PPPPPP (100%)

side = {}
allies = {}
enemy = {}
cou = 0
while (True):
    line = input()
    if line == "End":
        break
    line = line.split()
    command = line[0]
    if command == 'Ally':
        aa = set()
        for i in range(1, len(line)):
            country = line[i]
            aa.add(country)
            if country not in allies:
                allies[country] = set()
            if country not in enemy:
                enemy[country] = set()
            if country in side:
                for j in allies[country]:
                    side[j] = cou
                    aa.add(j)
            side[country] = cou
        # print(aa)
        ab = []
        for i in aa:
            ab.append(i)
        for i in range(len(ab)):
            country1 = ab[i]
            for j in range(i+1, len(ab)):
                country2 = ab[j]
                if country1 not in allies:
                    allies[country1] = set()
                if country2 not in allies:
                    allies[country2] = set()
                allies[country1].add(country2)
                allies[country2].add(country1)
        # for i in
        cou += 1
        # print(allies)

    elif command == 'Enemy':
        country1 = line[1]
        country2 = line[2]
        if country1 not in allies:
            allies[country1] = set()
        if country2 not in allies:
            allies[country2] = set()
        if country1 not in enemy:
            enemy[country1] = set()
        if country2 not in enemy:
            enemy[country2] = set()
        enemy[country1].add(country2)
        enemy[country2].add(country1)

        # print(allies[country1], allies[country2])
        # for i in allies[country1]:
        #     print(i)
        # print(allies[country1])
        # print(allies[country2])
        for i in allies[country1]:
            enemy[i].add(country2)
            enemy[country2].add(i)
        for i in allies[country2]:
            enemy[i].add(country1)
            enemy[country1].add(i)
        for i in allies[country1]:
            for j in allies[country2]:
                # print(i, j)
                if i not in enemy:
                    enemy[i] = set()
                if j not in enemy:
                    enemy[j] = set()

                enemy[country1].add(j)
                enemy[country2].add(i)
                enemy[i].add(country2)
                enemy[j].add(country1)
                enemy[i].add(j)
                enemy[j].add(i)

    elif command == 'Table':
        line.append(line[1])
        flag = 0
        for i in range(2, len(line)):
            country1 = line[i]
            country2 = line[i-1]
            if country1 not in enemy:
                enemy[country1] = set()
            if country2 not in enemy:
                enemy[country2] = set()
            if country2 in enemy[country1] or country1 in enemy[country2]:
                flag = 1
                break
            # print(line[i], line[i-1])
        if flag == 1:
            print("No")
        elif flag == 0:
            print("Okay")

# print(side)
# print(allies)
# print(enemy)


6230065121
# 1679655, 2022-11-12 10:22:14, xxxxxx (0%)

country_ally_dict = {}
country_enemy_dict = {}

def get_all_enemies(country):
    enemies = set()
    if country in country_enemy_dict:
        enemies.update(country_enemy_dict[country])
    for ally in country_ally_dict[country]:
        if ally in country_enemy_dict:
            enemies.update(country_enemy_dict[ally])
    return enemies


inp = input()

while inp != "End":
    inp = inp.split()
    if inp[0] == "Ally":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_ally_dict:
                        country_ally_dict[country] = set()
                        country_ally_dict[country].add(other_country)
                    else:
                        country_ally_dict[country].add(other_country)
    elif inp[0] == "Enemy":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_enemy_dict:
                        country_enemy_dict[country] = set()
                        country_enemy_dict[country].add(other_country)
                    else:
                        country_enemy_dict[country].add(other_country)
    elif inp[0] == "Table":
        current_order = inp[1:]
        
        if len(current_order) == 1:
            print("OK")
            inp = input()
            continue

        # table is circular
        current_order.append(current_order[0])

        for i in range(len(current_order) - 1):
            all_enemies = get_all_enemies(current_order[i])
            if current_order[i + 1] in all_enemies:
                print("Not OK")
                break
        
        print("OK")
# 1680294, 2022-11-12 10:51:07, xxxxxx (0%)


# organize table which enemy country or enemy of ally country cannot sit with each other
# check if table is valid
country_ally_dict = {}
country_enemy_dict = {}

def get_all_enemies(country):
    enemies = set()
    if country in country_enemy_dict:
        enemies.update(country_enemy_dict[country])
    for ally in country_ally_dict[country]:
        if ally in country_enemy_dict:
            enemies.update(country_enemy_dict[ally])
    return enemies


inp = input()

while inp != "End":
    inp = inp.split()
    if inp[0] == "Ally":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_ally_dict:
                        country_ally_dict[country] = set()
                        country_ally_dict[country].add(other_country)
                    else:
                        country_ally_dict[country].add(other_country)
    elif inp[0] == "Enemy":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_enemy_dict:
                        country_enemy_dict[country] = set()
                        country_enemy_dict[country].add(other_country)
                    else:
                        country_enemy_dict[country].add(other_country)
    elif inp[0] == "Table":
        current_order = inp[1:]
        
        if len(current_order) == 1:
            print("OK")
            inp = input()
            continue

        # table is circular
        current_order.append(current_order[0])

        for i in range(len(current_order) - 1):
            all_enemies = get_all_enemies(current_order[i])
            if current_order[i + 1] in all_enemies:
                print("Not OK")
                break
        
        print("OK")
# 1680521, 2022-11-12 10:59:55, PPPP-- (67%)


# organize table which enemy country or enemy of ally country cannot sit with each other
# check if table is valid
country_ally_dict = {}
country_enemy_dict = {}

def get_all_enemies(country):
    enemies = set()

    if country in country_enemy_dict:
        enemies.update(country_enemy_dict[country])
    if country not in country_ally_dict:
        return enemies
    for ally in country_ally_dict[country]:
        if ally in country_enemy_dict:
            enemies.update(country_enemy_dict[ally])
    return enemies


inpp = input()

while inpp != "End":
    inp = inpp.split()
    # print(inp)
    if inp[0] == "Ally":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_ally_dict:
                        country_ally_dict[country] = set()
                        country_ally_dict[country].add(other_country)
                    else:
                        country_ally_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Enemy":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_enemy_dict:
                        country_enemy_dict[country] = set()
                        country_enemy_dict[country].add(other_country)
                    else:
                        country_enemy_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Table":
        status = False
        current_order = inp[1:]
        
        if len(current_order) == 1:
            print("OK")
            inpp = input()
            continue
        # print(country_ally_dict)
        # print(country_enemy_dict)
        # table is circular
        current_order.append(current_order[0])

        for i in range(len(current_order) - 1):
            all_enemies = get_all_enemies(current_order[i])
            # print(current_order[i], all_enemies)
            if current_order[i + 1] in all_enemies:
                print("No")
                status = True
                break
        if status:
            inpp = input()
            continue

        print("Okay")
        inpp = input()


# 1680781, 2022-11-12 11:09:02, PPPP-- (67%)


# organize table which enemy country or enemy of ally country cannot sit with each other
# check if table is valid
country_ally_dict = {}
country_enemy_dict = {}

def get_all_enemies(country):
    enemies = set()

    if country in country_enemy_dict:
        enemies.update(country_enemy_dict[country])
    if country not in country_ally_dict:
        return enemies
    for ally in country_ally_dict[country]:
        if ally in country_enemy_dict:
            enemies.update(country_enemy_dict[ally])
    return enemies


inpp = input()

while inpp != "End":
    inp = inpp.split()
    # print(inp)
    if inp[0] == "Ally":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_ally_dict:
                        country_ally_dict[country] = set()
                        country_ally_dict[country].add(other_country)
                    else:
                        country_ally_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Enemy":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_enemy_dict:
                        country_enemy_dict[country] = set()
                        country_enemy_dict[country].add(other_country)
                    else:
                        country_enemy_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Table":
        status = False
        current_order = inp[1:]
        
        if len(current_order) == 1:
            print("OK")
            inpp = input()
            continue
        # print(country_ally_dict)
        # print(country_enemy_dict)

        # table is circular
        current_order = [current_order[-1]] + current_order + [current_order[0]]
        # print(current_order)

        for i in range(1, len(current_order) - 1):
            all_enemies = get_all_enemies(current_order[i])
            # print(current_order[i], all_enemies)
            if current_order[i + 1] in all_enemies or current_order[i - 1] in all_enemies:
                print("No")
                status = True
                break
        if status:
            inpp = input()
            continue

        print("Okay")
        inpp = input()


# 1680993, 2022-11-12 11:16:20, PPPP-- (67%)


# organize table which enemy country or enemy of ally country cannot sit with each other
# check if table is valid
country_ally_dict = {}
country_enemy_dict = {}

def get_all_enemies(country):
    enemies = set()

    if country in country_enemy_dict:
        enemies.update(country_enemy_dict[country])
    for enemy in list(enemies):
        if enemy in country_ally_dict:
            enemies.update(country_ally_dict[enemy])
    if country not in country_ally_dict:
        return enemies
    for ally in country_ally_dict[country]:
        if ally in country_enemy_dict:
            enemies.update(country_enemy_dict[ally])
    return enemies


inpp = input()

while inpp != "End":
    inp = inpp.split()
    # print(inp)
    if inp[0] == "Ally":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_ally_dict:
                        country_ally_dict[country] = set()
                        country_ally_dict[country].add(other_country)
                    else:
                        country_ally_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Enemy":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_enemy_dict:
                        country_enemy_dict[country] = set()
                        country_enemy_dict[country].add(other_country)
                    else:
                        country_enemy_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Table":
        status = False
        current_order = inp[1:]
        
        if len(current_order) == 1:
            print("OK")
            inpp = input()
            continue
        # print(country_ally_dict)
        # print(country_enemy_dict)

        # table is circular
        current_order = [current_order[-1]] + current_order + [current_order[0]]
        # print(current_order)

        for i in range(1, len(current_order) - 1):
            all_enemies = get_all_enemies(current_order[i])
            # print(current_order[i], all_enemies)
            if current_order[i + 1] in all_enemies or current_order[i - 1] in all_enemies:
                print("No")
                status = True
                break
        if status:
            inpp = input()
            continue

        print("Okay")
        inpp = input()


# 1681171, 2022-11-12 11:20:43, PPPP-- (67%)


# organize table which enemy country or enemy of ally country cannot sit with each other
# check if table is valid
country_ally_dict = {}
country_enemy_dict = {}

def get_all_enemies(country):
    enemies = set()

    if country in country_enemy_dict:
        enemies.update(country_enemy_dict[country])
    temp_enemies = list(enemies)
    for enemy in temp_enemies:
        if enemy in country_ally_dict:
            enemies.update(country_ally_dict[enemy])
    if country in country_ally_dict:
        for ally in country_ally_dict[country]:
            if ally in country_enemy_dict:
                enemies.update(country_enemy_dict[ally])
    return enemies


inpp = input()

while inpp != "End":
    inp = inpp.split()
    # print(inp)
    if inp[0] == "Ally":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_ally_dict:
                        country_ally_dict[country] = set()
                        country_ally_dict[country].add(other_country)
                    else:
                        country_ally_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Enemy":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_enemy_dict:
                        country_enemy_dict[country] = set()
                        country_enemy_dict[country].add(other_country)
                    else:
                        country_enemy_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Table":
        status = False
        current_order = inp[1:]
        
        if len(current_order) == 1:
            print("OK")
            inpp = input()
            continue
        # print(country_ally_dict)
        # print(country_enemy_dict)

        # table is circular
        current_order = [current_order[-1]] + current_order + [current_order[0]]
        # print(current_order)

        for i in range(1, len(current_order) - 1):
            all_enemies = get_all_enemies(current_order[i])
            # print(current_order[i], all_enemies)
            if current_order[i + 1] in all_enemies or current_order[i - 1] in all_enemies:
                print("No")
                status = True
                break
        if status:
            inpp = input()
            continue

        print("Okay")
        inpp = input()


# 1681473, 2022-11-12 11:27:18, PPPPPP (100%)


# organize table which enemy country or enemy of ally country cannot sit with each other
# check if table is valid
country_ally_dict = {}
country_enemy_dict = {}

def get_all_enemies(country):
    enemies = set()
    
    if country in country_enemy_dict:
        enemies.update(country_enemy_dict[country])
     # enemy of ally is enemy
    if country in country_ally_dict:
        for ally in country_ally_dict[country]:
            if ally in country_enemy_dict:
                enemies.update(country_enemy_dict[ally])
    # ally of enemy is enemy
    temp_enemies = list(enemies)
    for enemy in temp_enemies:
        if enemy in country_ally_dict:
            enemies.update(country_ally_dict[enemy])
     # enemy of ally is enemy
    if country in country_ally_dict:
        for ally in country_ally_dict[country]:
            if ally in country_enemy_dict:
                enemies.update(country_enemy_dict[ally])
    # ally of enemy is enemy
    temp_enemies = list(enemies)
    for enemy in temp_enemies:
        if enemy in country_ally_dict:
            enemies.update(country_ally_dict[enemy])
   
    return enemies


inpp = input()

while inpp != "End":
    inp = inpp.split()
    # print(inp)
    if inp[0] == "Ally":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_ally_dict:
                        country_ally_dict[country] = set()
                        country_ally_dict[country].add(other_country)
                    else:
                        country_ally_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Enemy":
        for country in inp[1:]:
            for other_country in inp[1:]:
                if country != other_country:
                    if country not in country_enemy_dict:
                        country_enemy_dict[country] = set()
                        country_enemy_dict[country].add(other_country)
                    else:
                        country_enemy_dict[country].add(other_country)
        inpp = input()
    elif inp[0] == "Table":
        status = False
        current_order = inp[1:]
        
        if len(current_order) == 1:
            print("OK")
            inpp = input()
            continue
        # print(country_ally_dict)
        # print(country_enemy_dict)

        # table is circular
        current_order = [current_order[-1]] + current_order + [current_order[0]]
        # print(current_order)

        for i in range(1, len(current_order) - 1):
            all_enemies = get_all_enemies(current_order[i])
            # print(current_order[i], all_enemies)
            if current_order[i + 1] in all_enemies or current_order[i - 1] in all_enemies:
                print("No")
                status = True
                break
        if status:
            inpp = input()
            continue

        print("Okay")
        inpp = input()



6530197621
# 1679234, 2022-11-12 09:59:54, xPPPPx (67%)

def find_enemy(nation,ally,vs):
    num = -1
    for i in range(len(ally)):
        if nation in ally[i]:
            num = i
            break
    if num == -1:
        return []
    else:
        enemy = []
        for e in vs[num]:
            enemy += ally[e]
        return enemy

ally = []
vs = {}
x = input()
while x != "End":
    x = x.split()
    if x[0] == 'Ally':
        ally.append(x[1:])
    elif x[0] == 'Enemy':
        c1, c2 = x[1], x[2]
        team1 = -1
        team2 = -1
        for t in ally:
            if c1 in t:
                team1 = ally.index(t)
            if c2 in t:
                team2 = ally.index(t)
        if team1 == -1:
            ally.append([c1])
            team1 = ally.index([c1])
        if team2 == -1:
            ally.append([c2])
            team2 = ally.index([c2])
        if team1 not in vs:
            vs[team1] = {team2}
        else:
            vs[team1] = vs[team1].union({team2})
        if team2 not in vs:
            vs[team2] = {team1}
        else:
            vs[team2] = vs[team2].union({team1})
    elif x[0] == "Table":
        in_table = [x[-1]] + x[1:] + [x[1]]
        ok = True
        for i in range(len(in_table)-1):
            c1 = in_table[i]
            c2 = in_table[i+1]
            if c2 in find_enemy(c1,ally,vs):
                ok = False
                break
    
        if ok:
            print("Okay")
        else:
            print("No")
            
    
    x = input()
# 1679320, 2022-11-12 10:03:52, xPPPPx (67%)

ally = []
vs = {}
x = input()
while x != "End":
    x = x.split()
    if x[0] == 'Ally':
        ally.append(x[1:])
    elif x[0] == 'Enemy':
        c1, c2 = x[1], x[2]
        team1 = -1
        team2 = -1
        for t in ally:
            if c1 in t:
                team1 = ally.index(t)
            if c2 in t:
                team2 = ally.index(t)
        if team1 == -1:
            ally.append([c1])
            team1 = ally.index([c1])
        if team2 == -1:
            ally.append([c2])
            team2 = ally.index([c2])
        if team1 not in vs:
            vs[team1] = {team2}
        else:
            vs[team1] = vs[team1].union({team2})
        if team2 not in vs:
            vs[team2] = {team1}
        else:
            vs[team2] = vs[team2].union({team1})
    elif x[0] == "Table":
        in_table = [x[-1]] + x[1:] + [x[1]]
        ok = True
        for i in range(len(in_table)-1):
            c1 = in_table[i]
            c2 = in_table[i+1]
            num = -1
            for i in range(len(ally)):
                if c1 in ally[i]:
                    num = i
                    break
            if num == -1:
                enemy = []
            else:
                enemy = []
                for e in vs[num]:
                    enemy += ally[e]
            if c2 in enemy:
                ok = False
                break
    
        if ok:
            print("Okay")
        else:
            print("No")
            
    
    x = input()
# 1679347, 2022-11-12 10:05:36, PPPPPx (83%)

ally = []
vs = {}
x = input()
while x != "End":
    x = x.split()
    if x[0] == 'Ally':
        ally.append(x[1:])
    elif x[0] == 'Enemy':
        c1, c2 = x[1], x[2]
        team1 = -1
        team2 = -1
        for t in ally:
            if c1 in t:
                team1 = ally.index(t)
            if c2 in t:
                team2 = ally.index(t)
        if team1 == -1:
            ally.append([c1])
            team1 = ally.index([c1])
        if team2 == -1:
            ally.append([c2])
            team2 = ally.index([c2])
        if team1 not in vs:
            vs[team1] = {team2}
        else:
            vs[team1] = vs[team1].union({team2})
        if team2 not in vs:
            vs[team2] = {team1}
        else:
            vs[team2] = vs[team2].union({team1})
    elif x[0] == "Table":
        in_table = [x[-1]] + x[1:] + [x[1]]
        ok = True
        for i in range(len(in_table)-1):
            c1 = in_table[i]
            c2 = in_table[i+1]
            num = -1
            for i in range(len(ally)):
                if c1 in ally[i]:
                    num = i
                    break
            if num == -1:
                enemy = []
            else:
                enemy = []
                if len(vs) != 0:
                    for e in vs[num]:
                        enemy += ally[e]
            if c2 in enemy:
                ok = False
                break
    
        if ok:
            print("Okay")
        else:
            print("No")
            
    
    x = input()
# 1679834, 2022-11-12 10:29:46, PPPPPx (83%)

ally = []
vs = {}
x = input()
while x != "End":
    x = x.split()
    if x[0] == 'Ally':
        a_list = x[1:]
        ally.append(a_list)
    elif x[0] == 'Enemy':
        c1, c2 = x[1], x[2]
        team1 = -1
        team2 = -1
        for t in ally:
            if c1 in t:
                team1 = ally.index(t)
            if c2 in t:
                team2 = ally.index(t)
        if team1 == -1:
            ally.append([c1])
            team1 = ally.index([c1])
        if team2 == -1:
            ally.append([c2])
            team2 = ally.index([c2])
        if team1 not in vs:
            vs[team1] = {team2}
        else:
            vs[team1] = vs[team1].union({team2})
        if team2 not in vs:
            vs[team2] = {team1}
        else:
            vs[team2] = vs[team2].union({team1})
    elif x[0] == "Table":
        in_table = [x[-1]] + x[1:] + [x[1]]
        ok = True
        for i in range(len(in_table)-1):
            c1 = in_table[i]
            c2 = in_table[i+1]
            num = -1
            for i in range(len(ally)):
                if c1 in ally[i]:
                    num = i
                    break
            if num == -1:
                enemy = []
            else:
                enemy = []
                if len(vs) != 0:
                    for e in vs[num]:
                        enemy += ally[e]
            if c2 in enemy:
                ok = False
                break
    
        if ok:
            print("Okay")
        else:
            print("No")
            
    
    x = input()
# 1680089, 2022-11-12 10:41:04, P----x (17%)

ally = []
vs = {}
x = input()
while x != "End":
    x = x.split()
    if x[0] == 'Ally':
        a_list = x[1:]
        ally.append(a_list)
    elif x[0] == 'Enemy':
        c1, c2 = x[1], x[2]
        team1 = -1
        team2 = -1
        for t in ally:
            if c1 in t:
                team1 = ally.index(t)
            if c2 in t:
                team2 = ally.index(t)
        if team1 == -1:
            ally.append([c1])
            team1 = ally.index([c1])
        if team2 == -1:
            ally.append([c2])
            team2 = ally.index([c2])
        if team1 not in vs:
            vs[team1] = {team2}
        else:
            vs[team1] = vs[team1].union({team2})
        if team2 not in vs:
            vs[team2] = {team1}
        else:
            vs[team2] = vs[team2].union({team1})
    elif x[0] == "Table":
        x = x[1:]
        if len(x) != 0:
            in_table = [x[-1]] + x[1:] + [x[1]]
            ok = True
            for i in range(len(in_table)-1):
                c1 = in_table[i]
                c2 = in_table[i+1]
                num = -1
                for i in range(len(ally)):
                    if c1 in ally[i]:
                        num = i
                        break
                if num == -1:
                    enemy = []
                else:
                    enemy = []
                    if len(vs) != 0:
                        for e in vs[num]:
                            enemy += ally[e]
                if c2 in enemy:
                    ok = False
                    break
        
            if ok:
                print("Okay")
            else:
                print("No")
        else:
            print("Okay")
            
    
    x = input()
# 1680098, 2022-11-12 10:41:43, PPPPPx (83%)

ally = []
vs = {}
x = input()
while x != "End":
    x = x.split()
    if x[0] == 'Ally':
        a_list = x[1:]
        ally.append(a_list)
    elif x[0] == 'Enemy':
        c1, c2 = x[1], x[2]
        team1 = -1
        team2 = -1
        for t in ally:
            if c1 in t:
                team1 = ally.index(t)
            if c2 in t:
                team2 = ally.index(t)
        if team1 == -1:
            ally.append([c1])
            team1 = ally.index([c1])
        if team2 == -1:
            ally.append([c2])
            team2 = ally.index([c2])
        if team1 not in vs:
            vs[team1] = {team2}
        else:
            vs[team1] = vs[team1].union({team2})
        if team2 not in vs:
            vs[team2] = {team1}
        else:
            vs[team2] = vs[team2].union({team1})
    elif x[0] == "Table":
        x = x[1:]
        if len(x) != 0:
            in_table = [x[-1]] + x[0:] + [x[0]]
            ok = True
            for i in range(len(in_table)-1):
                c1 = in_table[i]
                c2 = in_table[i+1]
                num = -1
                for i in range(len(ally)):
                    if c1 in ally[i]:
                        num = i
                        break
                if num == -1:
                    enemy = []
                else:
                    enemy = []
                    if len(vs) != 0:
                        for e in vs[num]:
                            enemy += ally[e]
                if c2 in enemy:
                    ok = False
                    break
        
            if ok:
                print("Okay")
            else:
                print("No")
        else:
            print("Okay")
            
    
    x = input()
# 1680209, 2022-11-12 10:46:52, PPPPPP (100%)

ally = []
vs = {}
x = input()
while x != "End":
    x = x.split()
    if x[0] == 'Ally':
        a_list = x[1:]
        ally.append(a_list)
    elif x[0] == 'Enemy':
        c1, c2 = x[1], x[2]
        team1 = -1
        team2 = -1
        for t in ally:
            if c1 in t:
                team1 = ally.index(t)
            if c2 in t:
                team2 = ally.index(t)
        if team1 == -1:
            ally.append([c1])
            team1 = ally.index([c1])
        if team2 == -1:
            ally.append([c2])
            team2 = ally.index([c2])
        if team1 not in vs:
            vs[team1] = {team2}
        else:
            vs[team1] = vs[team1].union({team2})
        if team2 not in vs:
            vs[team2] = {team1}
        else:
            vs[team2] = vs[team2].union({team1})
    elif x[0] == "Table":
        x = x[1:]
        if len(x) != 0:
            in_table = [x[-1]] + x[0:] + [x[0]]
            ok = True
            for i in range(len(in_table)-1):
                c1 = in_table[i]
                c2 = in_table[i+1]
                num = -1
                for i in range(len(ally)):
                    if c1 in ally[i]:
                        num = i
                        break
                if num == -1:
                    enemy = []
                else:
                    enemy = []
                    if len(vs) != 0:
                        if num in vs:
                            for e in vs[num]:
                                enemy += ally[e]
                if c2 in enemy:
                    ok = False
                    break
        
            if ok:
                print("Okay")
            else:
                print("No")
        else:
            print("Okay")
            
    
    x = input()

6532125821
# 1680118, 2022-11-12 10:42:28, PPPP-- (67%)

def solve(country_list, enemies):
    for i in range(-1 , len(country_list) - 1):
        a= country_list[i]
        b= country_list[i+1]
        if b not in enemies:
            enemies[b] = set()
        if a not in enemies:
            enemies[a] = set()
        if(a in enemies[b] or b in enemies[a]):
            return 'No'
    return 'Okay'

def debug(allies , enemies):
    print('Allies')
    for ally in allies:
        print(ally , '->' , allies[ally])
    print('Enemies')
    for enemy in enemies:
        print(enemy , '->' , enemies[enemy])
ipt = input()
allies = {}
enemies = {}
while ipt != 'End':
    ipt_split = ipt.split()
    country_list = ipt_split[1:]
    cmd = ipt_split[0]
    if(cmd == 'Ally'):
        for country in country_list:
            other_country_list = [e for e in country_list]
            other_country_list.remove(country)
            allies[country] = set(other_country_list)
    elif (cmd == 'Enemy'):
        for country in country_list:
            other_country_list = [e for e in country_list]
            other_country_list.remove(country)
            if country not in enemies:
                enemies[country] = set()

            pre_enemies_set = set(other_country_list)
            
            for other_country in other_country_list:
                if other_country not in allies:
                    allies[other_country] = set()
                pre_enemies_set = pre_enemies_set | allies[other_country]
            
            
            enemies[country] = enemies[country] | pre_enemies_set
    else:
        #debug(allies , enemies)
        
        print(solve(country_list , enemies))
    ipt = input()
# 1680197, 2022-11-12 10:46:00, PPPP-- (67%)

def solve(country_list, enemies):
    for i in range(-1 , len(country_list) - 1):
        a= country_list[i]
        b= country_list[i+1]
        if b not in enemies:
            enemies[b] = set()
        if a not in enemies:
            enemies[a] = set()
        if(a in enemies[b] or b in enemies[a]):
            return 'No'
    return 'Okay'

def debug(allies , enemies):
    print('Allies')
    for ally in allies:
        print(ally , '->' , allies[ally])
    print('Enemies')
    for enemy in enemies:
        print(enemy , '->' , enemies[enemy])
ipt = input()
allies = {}
enemies = {}
while ipt != 'End':
    ipt_split = ipt.split()
    country_list = ipt_split[1:]
    cmd = ipt_split[0]
    if(cmd == 'Ally'):
        for country in country_list:
            other_country_list = [e for e in country_list]
            other_country_list.remove(country)
            allies[country] = set(other_country_list)
    elif (cmd == 'Enemy'):
        for country in country_list:
            other_country_list = [e for e in country_list]
            other_country_list.remove(country)
            if country not in enemies:
                enemies[country] = set()

            pre_enemies_set = set(other_country_list)
            
            for other_country in other_country_list:
                if other_country not in allies:
                    allies[other_country] = set()
                pre_enemies_set = pre_enemies_set | allies[other_country]
            
            
            enemies[country] = enemies[country] | pre_enemies_set
            #4
            if country not in allies:
                allies[country] = set()
            for ally in allies[country]:
                if ally not in enemies:
                    enemies[ally] = set()
                enemies[country] = enemies[country] | enemies[ally]


    else:
        #debug(allies , enemies)
        
        print(solve(country_list , enemies))
    ipt = input()
# 1680578, 2022-11-12 11:02:18, xPP-Px (50%)

def solve(country_list, group , enemies):
    for i in range(-1 , len(country_list) - 1):
        a= country_list[i]
        b= country_list[i+1]
        if a not in group:
            continue
        a = group[a]
        if b not in group:
            continue
        b = group[b]
        if a in enemies[b] or b in enemies[a]:
            return 'No'
    return 'Okay'


ipt = input()
group = {}
enemies = {}
g = 1
while ipt != 'End':
    ipt_split = ipt.split()
    country_list = ipt_split[1:]
    cmd = ipt_split[0]
    if(cmd == 'Ally'):
        for country in country_list:
            group[country] = g
        g += 1
    elif (cmd == 'Enemy'):
        tmp = []
        for country in country_list:
            if country not in group:
                group[country] = 0
            tmp.append(group[country])
        for kg in tmp:
            other_tmp = [e for e in tmp]
            other_tmp.remove(kg)
            enemies[kg] = set(other_tmp)



    else:
        #debug(allies , enemies)
        
        print(solve(country_list , group , enemies))
    ipt = input()
# 1680642, 2022-11-12 11:04:18, xP-PPx (50%)

def solve(country_list, group , enemies):
    for i in range(-1 , len(country_list) - 1):
        a= country_list[i]
        b= country_list[i+1]
        if a not in group:
            continue
        a = group[a]
        if b not in group:
            continue
        b = group[b]
        if a in enemies[b] or b in enemies[a]:
            return 'No'
    return 'Okay'


ipt = input()
group = {}
enemies = {}
g = 1
while ipt != 'End':
    ipt_split = ipt.split()
    country_list = ipt_split[1:]
    cmd = ipt_split[0]
    if(cmd == 'Ally'):
        for country in country_list:
            group[country] = g
        g += 1
    elif (cmd == 'Enemy'):
        tmp = []
        for country in country_list:
            if country not in group:
                group[country] = g
                g += 1
            tmp.append(group[country])
        for kg in tmp:
            other_tmp = [e for e in tmp]
            other_tmp.remove(kg)
            enemies[kg] = set(other_tmp)



    else:
        #debug(allies , enemies)
        
        print(solve(country_list , group , enemies))
    ipt = input()
# 1681048, 2022-11-12 11:17:25, xPPPPx (67%)

def solve(country_list, group , enemies):
    for i in range(-1 , len(country_list) - 1):
        a= country_list[i]
        b= country_list[i+1]
        if a not in group:
            continue
        a = group[a]
        if b not in group:
            continue
        b = group[b]
        if a in enemies[b] or b in enemies[a]:
            return 'No'
    return 'Okay'


ipt = input()
group = {}
enemies = {}
g = 1
while ipt != 'End':
    ipt_split = ipt.split()
    country_list = ipt_split[1:]
    cmd = ipt_split[0]
    if(cmd == 'Ally'):
        for country in country_list:
            group[country] = g
        g += 1
    elif (cmd == 'Enemy'):
        for a in country_list:
            for b in country_list:
                if a == b:
                    continue
                #print(a , b)
                if a not in group:
                    group[a] = g
                    g += 1
                if b not in group:
                    group[b] = g
                    g += 1
                a = group[a]
                b = group[b]
                if(a not in enemies):
                    enemies[a] = []
                if(b not in enemies):
                    enemies[b] = []
                enemies[a].append(b)
                enemies[b].append(a)



    else:
        #debug(allies , enemies)
        
        print(solve(country_list , group , enemies))
    ipt = input()
# 1681195, 2022-11-12 11:21:12, xPPPPx (67%)

def solve(country_list, group , enemies):
    for i in range(-1 , len(country_list) - 1):
        a= country_list[i]
        b= country_list[i+1]
        if a not in group:
            continue
        a = group[a]
        if b not in group:
            continue
        b = group[b]
        if a in enemies[b] or b in enemies[a]:
            return 'No'
    return 'Okay'


ipt = input()
group = {}
enemies = {}
g = 1
while ipt != 'End':
    ipt_split = ipt.split()
    country_list = ipt_split[1:]
    cmd = ipt_split[0]
    if(cmd == 'Ally'):
        for country in country_list:
            group[country] = g
        g += 1
    elif (cmd == 'Enemy'):
        for i in range(len(country_list)):
            for j in range(len(country_list)):
                if i == j:
                    continue
                a = country_list[i]
                b = country_list[j]
                if a not in group:
                    group[a] = g
                    g += 1
                if b not in group:
                    group[b] = g
                    g += 1
                a = group[a]
                b = group[b]
                if(a not in enemies):
                    enemies[a] = []
                if(b not in enemies):
                    enemies[b] = []
                enemies[a].append(b)
                enemies[b].append(a)



    else:
        #debug(allies , enemies)
        
        print(solve(country_list , group , enemies))
    ipt = input()
# 1681287, 2022-11-12 11:23:38, PPPPPP (100%)

def solve(country_list, group , enemies):
    for i in range(-1 , len(country_list) - 1):
        a= country_list[i]
        b= country_list[i+1]
        if a not in group:
            continue
        a = group[a]
        if b not in group:
            continue
        b = group[b]
        if a not in enemies:
            enemies[a] = []
        if b not in enemies:
            enemies[b] = []
        if a in enemies[b] or b in enemies[a]:
            return 'No'
    return 'Okay'


ipt = input()
group = {}
enemies = {}
g = 1
while ipt != 'End':
    ipt_split = ipt.split()
    country_list = ipt_split[1:]
    cmd = ipt_split[0]
    if(cmd == 'Ally'):
        for country in country_list:
            group[country] = g
        g += 1
    elif (cmd == 'Enemy'):
        for i in range(len(country_list)):
            for j in range(len(country_list)):
                if i == j:
                    continue
                a = country_list[i]
                b = country_list[j]
                #print(a , b)
                if a not in group:
                    group[a] = g
                    g += 1
                if b not in group:
                    group[b] = g
                    g += 1
                a = group[a]
                b = group[b]
                if(a not in enemies):
                    enemies[a] = []
                if(b not in enemies):
                    enemies[b] = []
                enemies[a].append(b)
                enemies[b].append(a)



    else:
        #debug(allies , enemies)
        
        print(solve(country_list , group , enemies))
    ipt = input()

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

ally_c = []
enemy_c = []
table = []

a = input().strip().split()
while a[0] != 'End' :
    if a[0] == 'Ally' :
        ally_c.append(a[1::])
    if a[0] == 'Enemy' :
        enemy_c.append(a[1::])
    if a[0] == 'Table' :
        table.append(a[1::])
    a = input().strip().split()
    
out = ''
for i in range(len(table)) :
    out += 'No' + '\n'
# 1679705, 2022-11-12 10:23:44, ------ (0%)

ally_c = []
enemy_c = []
table = []

a = input().strip().split()
while a[0] != 'End' :
    if a[0] == 'Ally' :
        ally_c.append(a[1::])
    if a[0] == 'Enemy' :
        enemy_c.append(a[1::])
    if a[0] == 'Table' :
        table.append(a[1::])
    a = input().strip().split()
    
out = ''
for i in range(len(table)) :
    out += 'No' + '\n'
    
print(out)
# 1679712, 2022-11-12 10:23:57, P----- (17%)

ally_c = []
enemy_c = []
table = []

a = input().strip().split()
while a[0] != 'End' :
    if a[0] == 'Ally' :
        ally_c.append(a[1::])
    if a[0] == 'Enemy' :
        enemy_c.append(a[1::])
    if a[0] == 'Table' :
        table.append(a[1::])
    a = input().strip().split()
    
out = ''
for i in range(len(table)) :
    out += 'Okay' + '\n'
    
print(out)
# 1681061, 2022-11-12 11:17:52, P----- (17%)

ally_c = []
enemy_c = []
table = []

a = input().strip().split()
while a[0] != 'End' :
    if a[0] == 'Ally' :
        ally_c.append(set(a[1::]))
    if a[0] == 'Enemy' :
        enemy_c.append(set(a[1::]))
    if a[0] == 'Table' :
        table.append(tuple(a[1::]))
    a = input().strip().split()
    
def war_ally(ally,enemy) :
    ac = []
    for a in ally_c :
        for e in a :
            ac.append(e)
    for e in enemy_c :
        for c in e :
            if c not in ac :
                ally_c.append({c})
                ac.append(c)
    war = []
    for e in enemy_c :
        country = []
        for a in ally_c :
            for c in e :
                if c in a :
                    country.append(set(a))
        war.append(country)
    return war
    
war = war_ally(ally_c,enemy_c)    

for t in table :
    out = ''
    for i in range(len(t)) :
        sitable = True
        for w in war :
            if t[i] in w[0] and t[i-1] in w[1] or \
               t[i] in w[1] and t[i-1] in w[0] :
                sitable = False
                break
        if sitable == True :
            break
        else :
            break
    if sitable == True :
        out = 'Okay'
    else :
        out = 'No'
    print(out)

# 1681260, 2022-11-12 11:22:45, P----- (17%)

ally_c = []
enemy_c = []
table = []

a = input().strip().split()
while a[0] != 'End' :
    if a[0] == 'Ally' :
        ally_c.append(set(a[1::]))
    if a[0] == 'Enemy' :
        enemy_c.append(set(a[1::]))
    if a[0] == 'Table' :
        table.append(tuple(a[1::]+[a[1]]))
    a = input().strip().split()
    
def war_ally(ally,enemy) :
    ac = []
    for a in ally_c :
        for e in a :
            ac.append(e)
    for e in enemy_c :
        for c in e :
            if c not in ac :
                ally_c.append({c})
                ac.append(c)
    war = []
    for e in enemy_c :
        country = []
        for a in ally_c :
            for c in e :
                if c in a :
                    country.append(set(a))
        war.append(country)
    return war
    
war = war_ally(ally_c,enemy_c)    

for t in table :
    out = ''
    for i in range(len(t)-1) :
        sitable = True
        for w in war :
            if t[i] in w[0] and t[i+1] in w[1] or \
               t[i] in w[1] and t[i+1] in w[0] :
                sitable = False
                break
        if sitable == True :
            break
        else :
            break
    if sitable == True :
        out = 'Okay'
    else :
        out = 'No'
    print(out)

# 1681376, 2022-11-12 11:25:35, PPPPPP (100%)

ally_c = []
enemy_c = []
table = []

a = input().strip().split()
while a[0] != 'End' :
    if a[0] == 'Ally' :
        ally_c.append(set(a[1::]))
    if a[0] == 'Enemy' :
        enemy_c.append(set(a[1::]))
    if a[0] == 'Table' :
        table.append(tuple(a[1::]+[a[1]]))
    a = input().strip().split()
    
def war_ally(ally,enemy) :
    ac = []
    for a in ally_c :
        for e in a :
            ac.append(e)
    for e in enemy_c :
        for c in e :
            if c not in ac :
                ally_c.append({c})
                ac.append(c)
    war = []
    for e in enemy_c :
        country = []
        for a in ally_c :
            for c in e :
                if c in a :
                    country.append(set(a))
        war.append(country)
    return war
    
war = war_ally(ally_c,enemy_c)    

for t in table :
    for i in range(len(t)-1) :
        sitable = True
        for w in war :
            if t[i] in w[0] and t[i+1] in w[1] or \
               t[i] in w[1] and t[i+1] in w[0] :
                sitable = False
                break
        if sitable == False :#or sitable == True :
            break
    if sitable == True :
        print('Okay')
    else :
        print('No')


6531324121
# 1679397, 2022-11-12 10:08:28, x----x (0%)

theirs_allies = {}
theirs_enemies = {}

answers = []

while True:
    s = input()
    if s == "End": break
    s = s.split()

    if s[0] == "Ally":
        couns = set(s[1:])
        for c in couns:
            if c not in theirs_allies: theirs_allies[c] = set()
            theirs_allies[c] = theirs_allies[c].union(couns)

    elif s[0] == "Enemy":
        c1, c2 = s[1:]
        if c1 not in theirs_allies: theirs_allies[c1] = {c1}
        ally_c1 = theirs_allies[c1]
        if c2 not in theirs_allies: theirs_allies[c2] = {c2}
        ally_c2 = theirs_allies[c2]

        if c1 not in theirs_enemies: theirs_enemies[c1] = set()
        if c2 not in theirs_enemies: theirs_enemies[c2] = set()
        
        for al1 in ally_c1:
            if al1 not in theirs_enemies: theirs_enemies[al1] = set()
            for al2 in ally_c2:
                if al2 not in theirs_enemies: theirs_enemies[al2] = set()
                theirs_enemies[al1].add(al2)
                theirs_enemies[al2].add(al1)

    elif s[0] == "Table":
        s = s[1:]
        orders = [s[-1]] + s + [s[0]]
        war = False

        for i in range(1, len(s)-1):
            if orders[i] not in theirs_allies: continue
            enemy = theirs_enemies[orders[i]]

            if orders[i-1] in enemy: war = True
            elif orders[i+1] in enemy: war = True

        answers.append(war)

for ans in answers:
    if ans: print("No")
    else: print("Okay")
# 1679500, 2022-11-12 10:13:31, P----- (17%)

theirs_allies = {}
theirs_enemies = {}

answers = []

while True:
    s = input()
    if s == "End": break
    s = s.split()

    if s[0] == "Ally":
        couns = set(s[1:])
        for c in couns:
            if c not in theirs_allies: theirs_allies[c] = set()
            theirs_allies[c] = theirs_allies[c].union(couns)

    elif s[0] == "Enemy":
        c1, c2 = s[1:]
        if c1 not in theirs_allies: theirs_allies[c1] = {c1}
        ally_c1 = theirs_allies[c1]
        if c2 not in theirs_allies: theirs_allies[c2] = {c2}
        ally_c2 = theirs_allies[c2]

        if c1 not in theirs_enemies: theirs_enemies[c1] = set()
        if c2 not in theirs_enemies: theirs_enemies[c2] = set()

        for al1 in ally_c1:
            if al1 not in theirs_enemies: theirs_enemies[al1] = set()
            for al2 in ally_c2:
                if al2 not in theirs_enemies: theirs_enemies[al2] = set()
                theirs_enemies[al1].add(al2)
                theirs_enemies[al2].add(al1)

    elif s[0] == "Table":
        s = s[1:]
        orders = s + [s[0]]
        war = False

        for i in range(1, len(s)-1):
            if orders[i] not in theirs_enemies: continue
            enemy = theirs_enemies[orders[i]]

            if orders[i-1] in enemy: war = True; break
            elif orders[i+1] in enemy: war = True; break

        answers.append(war)

for ans in answers:
    if ans: print("No")
    else: print("Okay")
# 1679796, 2022-11-12 10:28:20, P----- (17%)

theirs_allies = {}
theirs_enemies = {}

answers = []
enemies_input = []
table_inputs = []

while True:
    s = input()
    if s == "End": break
    s = s.split()

    if s[0] == "Ally":
        couns = set(s[1:])
        for c in couns:
            if c not in theirs_allies: theirs_allies[c] = set()
            theirs_allies[c] = theirs_allies[c].union(couns)

    elif s[0] == "Enemy":
        enemies_input.append(s[1:])

    elif s[0] == "Table":
        table_inputs.append(s[1:])

for c1, c2 in enemies_input:
    if c1 not in theirs_allies: theirs_allies[c1] = {c1}
    ally_c1 = theirs_allies[c1]
    if c2 not in theirs_allies: theirs_allies[c2] = {c2}
    ally_c2 = theirs_allies[c2]

    if c1 not in theirs_enemies: theirs_enemies[c1] = set()
    if c2 not in theirs_enemies: theirs_enemies[c2] = set()

    for al1 in ally_c1:
        if al1 not in theirs_enemies: theirs_enemies[al1] = set()
        for al2 in ally_c2:
            if al2 not in theirs_enemies: theirs_enemies[al2] = set()
            theirs_enemies[al1].add(al2)
            theirs_enemies[al2].add(al1)

for s in table_inputs:
    orders = s + [s[0]]
    war = False

    for i in range(1, len(s)-1):
        if orders[i] not in theirs_enemies: continue
        enemy = theirs_enemies[orders[i]]

        if orders[i-1] in enemy: war = True; break
        elif orders[i+1] in enemy: war = True; break

    answers.append(war)

for ans in answers:
    if ans: print("No")
    else: print("Okay")
# 1680192, 2022-11-12 10:45:46, P----- (17%)

theirs_allies = {}
theirs_enemies = {}

answers = []
enemies_input = []
table_inputs = []

while True:
    s = input()
    if s == "End": break
    s = s.split()

    if s[0] == "Ally":
        couns = set(s[1:])
        for c in couns:
            if c not in theirs_allies: theirs_allies[c] = set()
            theirs_allies[c] = theirs_allies[c].union(couns)
            for a in theirs_allies[c]:
                if a not in theirs_allies: theirs_allies[a] = set()
                theirs_allies[a] = theirs_allies[a].union(couns)
                theirs_allies[c] = theirs_allies[c].union(theirs_allies[a])

    elif s[0] == "Enemy":
        enemies_input.append(s[1:])


    elif s[0] == "Table":
        table_inputs.append(s[1:])


for c1, c2 in enemies_input:
    if c1 not in theirs_allies: theirs_allies[c1] = {c1}
    ally_c1 = theirs_allies[c1]
    if c2 not in theirs_allies: theirs_allies[c2] = {c2}
    ally_c2 = theirs_allies[c2]

    if c1 not in theirs_enemies: theirs_enemies[c1] = set()
    if c2 not in theirs_enemies: theirs_enemies[c2] = set()

    for al1 in ally_c1:
        if al1 not in theirs_enemies: theirs_enemies[al1] = set()
        for al2 in ally_c2:
            if al2 not in theirs_enemies: theirs_enemies[al2] = set()
            theirs_enemies[al1].add(al2)
            theirs_enemies[al2].add(al1)

for s in table_inputs:
    orders = s + [s[0]]
    war = False

    for i in range(1, len(s)-1):
        if orders[i] not in theirs_enemies: continue
        enemy = theirs_enemies[orders[i]]

        if orders[i-1] in enemy: war = True; break
        elif orders[i+1] in enemy: war = True; break

    answers.append(war)

for ans in answers:
    if ans: print("No")
    else: print("Okay")
# 1680907, 2022-11-12 11:13:34, P----- (17%)

theirs_allies = []
theirs_enemies = []
countries = set()
answers = []
enemies_input = []
table_inputs = []

while True:
    s = input()
    if s == "End": break
    s = s.split()

    if s[0] == "Ally":
        s = set(s[1:])
        if theirs_allies == []: theirs_allies.append(s)
        else:
            added = False
            for i in range(len(theirs_allies)):
                if s.intersection(theirs_allies[i]) != set():
                    theirs_allies.append(s.union(theirs_allies[i]))
                    del theirs_allies[i]
                    added = True
                    break

            if not added: theirs_allies.append(s)

    elif s[0] == "Enemy":
        enemies_input.append(s[1:])


    elif s[0] == "Table":
        table_inputs.append(s[1:])



for c in theirs_allies:
    for cs in c:
        countries.add(cs)

for c1, c2 in enemies_input:
    countries.add(c1)
    countries.add(c2)

    added = False
    for a in theirs_allies:
        if c1 in a: added = True; break

    if not added: theirs_allies.append({c1})
    added = False
    for a in theirs_allies:
        if c2 in a: added = True ;break

    if not added: theirs_allies.append({c2})

    ally, enemies = None, None
    for a in theirs_allies:
        if c1 in a and c2 not in a:
            ally = a
        if c2 in a and c1 not in a:
            enemies = a

    theirs_enemies.append([ally, enemies])

for s in table_inputs:
    orders = s + [s[0]]
    war = False

    for i in range(1, len(s)-1):
        to_break = False
        if orders[i] not in countries: continue

        for a, b in theirs_enemies:
            if orders[i-1] in a and orders[i] in b: war = True; to_break = True; break
            if orders[i-1] in b and orders[i] in a: war = True; to_break = True; break
            if orders[i+1] in a and orders[i] in b: war = True; to_break = True; break
            if orders[i+1] in b and orders[i] in a: war = True; to_break = True; break
        
        if to_break: break

    answers.append(war)

for ans in answers:
    if ans: print("No")
    else: print("Okay")
# 1681067, 2022-11-12 11:17:59, PPPPPP (100%)

theirs_allies = []
theirs_enemies = []
countries = set()
answers = []
enemies_input = []
table_inputs = []

while True:
    s = input()
    if s == "End": break
    s = s.split()

    if s[0] == "Ally":
        s = set(s[1:])
        if theirs_allies == []: theirs_allies.append(s)
        else:
            added = False
            for i in range(len(theirs_allies)):
                if s.intersection(theirs_allies[i]) != set():
                    theirs_allies.append(s.union(theirs_allies[i]))
                    del theirs_allies[i]
                    added = True
                    break

            if not added: theirs_allies.append(s)

    elif s[0] == "Enemy":
        enemies_input.append(s[1:])


    elif s[0] == "Table":
        table_inputs.append(s[1:])



for c in theirs_allies:
    for cs in c:
        countries.add(cs)

for c1, c2 in enemies_input:
    countries.add(c1)
    countries.add(c2)

    added = False
    for a in theirs_allies:
        if c1 in a: added = True; break

    if not added: theirs_allies.append({c1})
    added = False
    for a in theirs_allies:
        if c2 in a: added = True ;break

    if not added: theirs_allies.append({c2})

    ally, enemies = None, None
    for a in theirs_allies:
        if c1 in a and c2 not in a:
            ally = a
        if c2 in a and c1 not in a:
            enemies = a

    theirs_enemies.append([ally, enemies])

for s in table_inputs:
    orders = s + [s[0]]
    war = False

    for i in range(1, len(orders)-1):
        to_break = False
        if orders[i] not in countries: continue

        for a, b in theirs_enemies:
            if orders[i-1] in a and orders[i] in b: war = True; to_break = True; break
            if orders[i-1] in b and orders[i] in a: war = True; to_break = True; break
            if orders[i+1] in a and orders[i] in b: war = True; to_break = True; break
            if orders[i+1] in b and orders[i] in a: war = True; to_break = True; break
        
        if to_break: break

    answers.append(war)

for ans in answers:
    if ans: print("No")
    else: print("Okay")

6532084721
# 1679310, 2022-11-12 10:03:25, P----- (17%)

ally = {}; enemy = {}
while(True):
    tmp = input().split()
    if tmp[0] == 'End': break

    if tmp[0] == 'Ally':
        for i in tmp[1:]:
            ally[i] = []
            for j in tmp[1:]:
                if j == i : continue
                ally[i].append(j)

    elif tmp[0] == 'Enemy':
        first = tmp[1]
        second = tmp[2]
        if first not in ally:
            ally[first] = []
        if second not in ally:
            ally[second] = []
        if first not in enemy: enemy[first] = []
        if second not in enemy: enemy[second] = []
        enemy[first].append(second)
        enemy[second].append(first)
        print(second,first)
        for i in ally[second]:
            enemy[first].append(i)
        for i in ally[first]:
            enemy[second].append(i)
        for i in ally[first]:
            if i not in enemy: enemy[i] = []
            enemy[i].append(second)
            for j in ally[second]:
                enemy[i].append(j)
        for i in ally[second]:
            if i not in enemy: enemy[i] = []
            enemy[i].append(first)
            for j in ally[first]:
                enemy[i].append(j)

    else:
        tmp = tmp[1:]
        mod = len(tmp)
        ch = 0
        for i in range(len(tmp)):
            if tmp[i] not in enemy or tmp[(i+1)%mod] not in enemy: continue
            if tmp[(i+1)%mod] in enemy[tmp[i]]:
                ch = 1
                break
        if ch == 1:
            print('No')
        else:
            print('Okay')


        

# 1679453, 2022-11-12 10:11:28, P----- (17%)

ally = {}; enemy = {}
while(True):
    tmp = input().split()
    if tmp[0] == 'End': break

    if tmp[0] == 'Ally':
        for i in tmp[1:]:
            ally[i] = []
            for j in tmp[1:]:
                if j == i : continue
                ally[i].append(j)

    elif tmp[0] == 'Enemy':
        first = tmp[1]
        second = tmp[2]
        if first not in ally:
            ally[first] = []
        if second not in ally:
            ally[second] = []
        if first not in enemy: enemy[first] = []
        if second not in enemy: enemy[second] = []
        enemy[first].append(second)
        enemy[second].append(first)
        print(second,first)
        for i in ally[second]:
            enemy[first].append(i)
        for i in ally[first]:
            enemy[second].append(i)
        for i in ally[first]:
            if i not in enemy: enemy[i] = []
            enemy[i].append(second)
            for j in ally[second]:
                enemy[i].append(j)
        for i in ally[second]:
            if i not in enemy: enemy[i] = []
            enemy[i].append(first)
            for j in ally[first]:
                enemy[i].append(j)

    else:
        #print(enemy)
        tmp = tmp[1:]
        mod = len(tmp)
        ch = 0
        for i in range(len(tmp)):
            #print(tmp[i],tmp[(i+1)%mod])
            if tmp[i] not in enemy or tmp[(i+1)%mod] not in enemy: continue
            if tmp[(i+1)%mod] in enemy[tmp[i]]:
                ch = 1
        if ch == 1:
            print('No')
        else:
            print('Okay')


        

# 1679557, 2022-11-12 10:16:46, P----- (17%)

ally = {}; enemy = {}
while(True):
    tmp = input().split()
    if tmp[0] == 'End': break

    if tmp[0] == 'Ally':
        for i in tmp[1:]:
            ally[i] = []
            for j in tmp[1:]:
                if j == i : continue
                ally[i].append(j)

    elif tmp[0] == 'Enemy':
        first = tmp[1]
        second = tmp[2]
        if first not in ally:
            ally[first] = []
        if second not in ally:
            ally[second] = []
        if first not in enemy: enemy[first] = set()
        if second not in enemy: enemy[second] = set()
        enemy[first].add(second)
        enemy[second].add(first)
        print(second,first)
        for i in ally[second]:
            enemy[first].add(i)
        for i in ally[first]:
            enemy[second].add(i)
        for i in ally[first]:
            if i not in enemy: enemy[i] = set()
            enemy[i].add(second)
            for j in ally[second]:
                enemy[i].add(j)
        for i in ally[second]:
            if i not in enemy: enemy[i] = set()
            enemy[i].add(first)
            for j in ally[first]:
                enemy[i].add(j)

    else:
        #print(enemy)
        tmp = tmp[1:]
        mod = len(tmp)
        ch = 0
        for i in range(len(tmp)):
            #print(tmp[i],tmp[(i+1)%mod])
            if tmp[i] not in enemy or tmp[(i+1)%mod] not in enemy: continue
            if tmp[(i+1)%mod] in enemy[tmp[i]]:
                ch = 1
        if ch == 1:
            print('No')
        else:
            print('Okay')


        

# 1679646, 2022-11-12 10:21:55, PPPPPP (100%)

ally = {}; enemy = {}
while(True):
    tmp = input().split()
    if tmp[0] == 'End': break

    if tmp[0] == 'Ally':
        for i in tmp[1:]:
            ally[i] = []
            for j in tmp[1:]:
                if j == i : continue
                ally[i].append(j)

    elif tmp[0] == 'Enemy':
        first = tmp[1]
        second = tmp[2]
        if first not in ally:
            ally[first] = []
        if second not in ally:
            ally[second] = []
        if first not in enemy: enemy[first] = set()
        if second not in enemy: enemy[second] = set()
        enemy[first].add(second)
        enemy[second].add(first)
        for i in ally[second]:
            enemy[first].add(i)
        for i in ally[first]:
            enemy[second].add(i)
        for i in ally[first]:
            if i not in enemy: enemy[i] = set()
            enemy[i].add(second)
            for j in ally[second]:
                enemy[i].add(j)
        for i in ally[second]:
            if i not in enemy: enemy[i] = set()
            enemy[i].add(first)
            for j in ally[first]:
                enemy[i].add(j)

    else:
        #print(enemy)
        tmp = tmp[1:]
        mod = len(tmp)
        ch = 0
        for i in range(len(tmp)):
            #print(tmp[i],tmp[(i+1)%mod])
            if tmp[i] not in enemy or tmp[(i+1)%mod] not in enemy: continue
            if tmp[(i+1)%mod] in enemy[tmp[i]]:
                ch = 1
        if ch == 1:
            print('No')
        else:
            print('Okay')
# 1679669, 2022-11-12 10:22:49, ------ (0%)

ally = {}; enemy = {}
while(True):
    tmp = input().split()
    if tmp[0] == 'End': break

    if tmp[0] == 'Ally':
        for i in tmp[1:]:
            ally[i] = []
            for j in tmp[1:]:
                if j == i : continue
                ally[i].append(j)

    elif tmp[0] == 'Enemy':
        first = tmp[1]
        second = tmp[2]
        if first not in ally:
            ally[first] = []
        if second not in ally:
            ally[second] = []
        if first not in enemy: enemy[first] = []
        if second not in enemy: enemy[second] = []
        enemy[first].append(second)
        enemy[second].append(first)
        for i in ally[second]:
            enemy[first].append(i)
        for i in ally[first]:
            enemy[second].append(i)
        for i in ally[first]:
            if i not in enemy: enemy[i] = []
            enemy[i].append(second)
            for j in ally[second]:
                enemy[i].append(j)
        for i in ally[second]:
            if i not in enemy: enemy[i] = []
            enemy[i].append(first)
            for j in ally[first]:
                enemy[i].append(j)

    else:
        print(enemy)
        tmp = tmp[1:]
        mod = len(tmp)
        ch = 0
        for i in range(len(tmp)):
            #print(tmp[i],tmp[(i+1)%mod])
            if tmp[i] not in enemy or tmp[(i+1)%mod] not in enemy: continue
            if tmp[(i+1)%mod] in enemy[tmp[i]]:
                ch = 1
        if ch == 1:
            print('No')
        else:
            print('Okay')


        

# 1679704, 2022-11-12 10:23:42, PPPPPP (100%)

ally = {}; enemy = {}
while(True):
    tmp = input().split()
    if tmp[0] == 'End': break

    if tmp[0] == 'Ally':
        for i in tmp[1:]:
            ally[i] = []
            for j in tmp[1:]:
                if j == i : continue
                ally[i].append(j)

    elif tmp[0] == 'Enemy':
        first = tmp[1]
        second = tmp[2]
        if first not in ally:
            ally[first] = []
        if second not in ally:
            ally[second] = []
        if first not in enemy: enemy[first] = []
        if second not in enemy: enemy[second] = []
        enemy[first].append(second)
        enemy[second].append(first)
        for i in ally[second]:
            enemy[first].append(i)
        for i in ally[first]:
            enemy[second].append(i)
        for i in ally[first]:
            if i not in enemy: enemy[i] = []
            enemy[i].append(second)
            for j in ally[second]:
                enemy[i].append(j)
        for i in ally[second]:
            if i not in enemy: enemy[i] = []
            enemy[i].append(first)
            for j in ally[first]:
                enemy[i].append(j)

    else:
        #print(enemy)
        tmp = tmp[1:]
        mod = len(tmp)
        ch = 0
        for i in range(len(tmp)):
            #print(tmp[i],tmp[(i+1)%mod])
            if tmp[i] not in enemy or tmp[(i+1)%mod] not in enemy: continue
            if tmp[(i+1)%mod] in enemy[tmp[i]]:
                ch = 1
        if ch == 1:
            print('No')
        else:
            print('Okay')


        


6532182521
# 1679151, 2022-11-12 09:55:13, PPPPPP (100%)

inp = input().split()
ally = {}
allyG = {}
enemy = {}
cally = 0
cenemy = 0
while inp[0] == 'Ally':
    allyG[cally] = set()
    for cou in inp[1:]:
        ally[cou] = cally
        allyG[cally].add(cou)
    cally += 1
    inp = input().split()

while inp[0] == 'Enemy':
    for cou in inp[1:]:
        if cou not in ally:
            ally[cou] = cally
            allyG[cally] = set({cou})
            cally += 1

    ca1 = ally[inp[1]]
    ca1G = allyG[ca1]
    ca2 = ally[inp[2]]
    ca2G = allyG[ca2]

    for cou in ca1G:
        if cou not in enemy:
            enemy[cou] = set()
        enemy[cou].add(cenemy)
    for cou in ca2G:
        if cou not in enemy:
            enemy[cou] = set()
        enemy[cou].add(cenemy)
    cenemy += 1

    inp = input().split()

while inp[0] == 'Table':
    couList = inp[1:]
    couList.append(couList[0])
    can = True
    for i in range(1, len(couList)):
        c1 = couList[i-1]
        c2 = couList[i]
        if c1 not in ally:
            ally[c1] = cally
            cally += 1
        if c1 not in enemy:
            enemy[c1] = set({cenemy})
            cenemy += 1
        if c2 not in ally:
            ally[c2] = cally
            cally += 1
        if c2 not in enemy:
            enemy[c2] = set({cenemy})
            cenemy += 1

        for ecn in enemy[c1]:
            if ecn in enemy[c2] and ally[c1] != ally[c2]:
                can = False
                break
        if not can:
            break
    if can:
        print('Okay')
    else:
        print('No')
    inp = input().split()

# 1679353, 2022-11-12 10:05:59, P-PPP- (67%)

inp = input().split()
ally = {}
allyG = {}
enemy = {}
cally = 0
cenemy = 0
while inp[0] == 'Ally':
    allyG[cally] = set()
    for cou in inp[1:]:
        ally[cou] = cally
        allyG[cally].add(cou)
    cally += 1
    inp = input().split()

while inp[0] == 'Enemy':
    for cou in inp[1:]:
        if cou not in ally:
            ally[cou] = cally
            allyG[cally] = set({cou})
            cally += 1

    ca1G = allyG[ally[inp[1]]]
    ca2G = allyG[ally[inp[2]]]

    for cg in [ca1G, ca2G]:
        for cou in cg:
            if cou not in enemy:
                enemy[cou] = set()
            enemy[cou].add(cenemy)
    cenemy += 1

    inp = input().split()

while inp[0] == 'Table':
    couList = inp[1:]
    can = True
    for i in range(1, len(couList)):
        c1 = couList[i-1]
        c2 = couList[i]

        for cou in [c1, c2]:
            if cou not in ally:
                ally[cou] = cally
                cally += 1
            if cou not in enemy:
                enemy[cou] = set({cenemy})
                cenemy += 1

        for ecn in enemy[c1]:
            if ecn in enemy[c2] and ally[c1] != ally[c2]:
                can = False
                break
        if not can:
            break
    if can:
        print('Okay')
    else:
        print('No')
    inp = input().split()

# 1679381, 2022-11-12 10:07:34, PPPPPP (100%)

inp = input().split()
ally = {}
allyG = {}
enemy = {}
cally = 0
cenemy = 0
while inp[0] == 'Ally':
    allyG[cally] = set()
    for cou in inp[1:]:
        ally[cou] = cally
        allyG[cally].add(cou)
    cally += 1
    inp = input().split()

while inp[0] == 'Enemy':
    for cou in inp[1:]:
        if cou not in ally:
            ally[cou] = cally
            allyG[cally] = set({cou})
            cally += 1

    ca1G = allyG[ally[inp[1]]]
    ca2G = allyG[ally[inp[2]]]

    for cg in [ca1G, ca2G]:
        for cou in cg:
            if cou not in enemy:
                enemy[cou] = set()
            enemy[cou].add(cenemy)
    cenemy += 1

    inp = input().split()

while inp[0] == 'Table':
    couList = inp[1:]
    can = True
    for i in range(len(couList)):
        c1 = couList[i-1]
        c2 = couList[i]

        for cou in [c1, c2]:
            if cou not in ally:
                ally[cou] = cally
                cally += 1
            if cou not in enemy:
                enemy[cou] = set({cenemy})
                cenemy += 1

        for ecn in enemy[c1]:
            if ecn in enemy[c2] and ally[c1] != ally[c2]:
                can = False
                break
        if not can:
            break
    if can:
        print('Okay')
    else:
        print('No')
    inp = input().split()

# 1679849, 2022-11-12 10:30:13, PPPPPP (100%)

inp = input().split()
ally = {}
allyG = {}
enemy = {}
cally = 0
cenemy = 0

while inp[0] == 'Ally':
    allyG[cally] = set()
    for cou in inp[1:]:
        ally[cou] = cally
        allyG[cally].add(cou)
    cally += 1
    inp = input().split()

while inp[0] == 'Enemy':
    for cou in inp[1:]:
        if cou not in ally:
            ally[cou] = cally
            allyG[cally] = set({cou})
            cally += 1

    for cg in [allyG[ally[inp[1]]], allyG[ally[inp[2]]]]:
        for cou in cg:
            if cou not in enemy:
                enemy[cou] = set()
            enemy[cou].add(cenemy)
    cenemy += 1

    inp = input().split()

while inp[0] == 'Table':
    couList = inp[1:]
    can = True
    for i in range(len(couList)):
        c1 = couList[i-1]
        c2 = couList[i]

        for cou in [c1, c2]:
            if cou not in ally:
                ally[cou] = cally
                cally += 1
            if cou not in enemy:
                enemy[cou] = set({cenemy})
                cenemy += 1

        ecn = enemy[c1].intersection(enemy[c2])
        if ecn != set() and ally[c1] != ally[c2]:
            can = False
    if can:
        print('Okay')
    else:
        print('No')
    inp = input().split()

# 1679923, 2022-11-12 10:32:40, PPPPPP (100%)

inp = input().split()
ally = {}
allyG = {}
enemy = {}
cally = 0
cenemy = 0

while inp[0] == 'Ally':
    allyG[cally] = set()
    for cou in inp[1:]:
        ally[cou] = cally
        allyG[cally].add(cou)
    cally += 1
    inp = input().split()

while inp[0] == 'Enemy':
    for cou in inp[1:]:
        if cou not in ally:
            ally[cou] = cally
            allyG[cally] = set({cou})
            cally += 1

    for cg in [allyG[ally[inp[1]]], allyG[ally[inp[2]]]]:
        for cou in cg:
            if cou not in enemy:
                enemy[cou] = set()
            enemy[cou].add(cenemy)
    cenemy += 1

    inp = input().split()

while inp[0] == 'Table':
    couList = inp[1:]
    can = True
    for i in range(len(couList)):
        c1 = couList[i-1]
        c2 = couList[i]

        if c1 not in enemy or c2 not in enemy:
            continue

        ecn = enemy[c1].intersection(enemy[c2])
        if ecn != set() and ally[c1] != ally[c2]:
            can = False
    if can:
        print('Okay')
    else:
        print('No')
    inp = input().split()

# 1679965, 2022-11-12 10:35:32, PPPPPP (100%)

inp = input().split()
ally = {}
allyG = {}
enemy = {}
cally = 0
cenemy = 0

while inp[0] == 'Ally':
    allyG[cally] = set()
    for cou in inp[1:]:
        ally[cou] = cally
        allyG[cally].add(cou)
    cally += 1
    inp = input().split()

while inp[0] == 'Enemy':
    for cou in inp[1:]:
        if cou not in ally:
            ally[cou] = cally
            allyG[cally] = set({cou})
            cally += 1
    allcou = allyG[ally[inp[1]]].union(allyG[ally[inp[2]]])
    for cou in allcou:
        if cou not in enemy:
            enemy[cou] = set()
        enemy[cou].add(cenemy)
    cenemy += 1

    inp = input().split()

while inp[0] == 'Table':
    couList = inp[1:]
    can = True
    for i in range(len(couList)):
        c1 = couList[i-1]
        c2 = couList[i]

        if c1 not in enemy or c2 not in enemy:
            continue

        ecn = enemy[c1].intersection(enemy[c2])
        if ecn != set() and ally[c1] != ally[c2]:
            can = False
    if can:
        print('Okay')
    else:
        print('No')
    inp = input().split()


6530178721
# 1680545, 2022-11-12 11:00:49, xxPPP- (50%)

x = input()
ally = {}
enemy = {}
sustu = {}
while x != 'End':
    x = x.split()
    
    if x[0] == 'Ally':
        al = set()
        for i in x[1:]:
            al.add(i)
        for e in al:
            ally[e] = al - {e}
    elif x[0] == 'Enemy':
        en1 = set()
        en2 = set()
        if x[1] in ally:
            en1.add(x[1])
            for i in ally[x[1]]:
                en1.add(i)
        else:
            en1.add(x[1])
        if x[2] in ally:
            en2.add(x[2])
            for i in ally[x[2]]:
                en2.add(i)
        else:
            en2.add(x[2])
            
        for i in en1:
            for e in en2:
                if i not in sustu:
                    sustu[i] = [e]
                else:
                    sustu[i] += [e]
                if e not in sustu:
                    sustu[e] = [i]
                else:
                    sustu[e] += [i]
        
    elif x[0] == 'Table':
        check = True
        if x[-1] in sustu[x[1]]:
            check = False
        for i in range(1,len(x[1:])-1):
            if x[i+1] in sustu:
                if x[i] in sustu[x[i+1]]:
                    check = False
                    break
        if check == False:
            print('No')
        else:
            print('Okay')
        
    x = input()

# 1680572, 2022-11-12 11:02:09, PPPPP- (83%)

x = input()
ally = {}
enemy = {}
sustu = {}
while x != 'End':
    x = x.split()
    
    if x[0] == 'Ally':
        al = set()
        for i in x[1:]:
            al.add(i)
        for e in al:
            ally[e] = al - {e}
    elif x[0] == 'Enemy':
        en1 = set()
        en2 = set()
        if x[1] in ally:
            en1.add(x[1])
            for i in ally[x[1]]:
                en1.add(i)
        else:
            en1.add(x[1])
        if x[2] in ally:
            en2.add(x[2])
            for i in ally[x[2]]:
                en2.add(i)
        else:
            en2.add(x[2])
            
        for i in en1:
            for e in en2:
                if i not in sustu:
                    sustu[i] = [e]
                else:
                    sustu[i] += [e]
                if e not in sustu:
                    sustu[e] = [i]
                else:
                    sustu[e] += [i]
        
    elif x[0] == 'Table':
        check = True
        if x[1] in sustu:
            if x[-1] in sustu[x[1]]:
                check = False
        for i in range(1,len(x[1:])-1):
            if x[i+1] in sustu:
                if x[i] in sustu[x[i+1]]:
                    check = False
                    break
        if check == False:
            print('No')
        else:
            print('Okay')
        
    x = input()

# 1680802, 2022-11-12 11:09:47, PPPPP- (83%)

x = input()
ally = {}
enemy = {}
sustu = {}
while x != 'End':
    x = x.split()
    
    if x[0] == 'Ally':
        al = set()
        for i in x[1:]:
            al.add(i)
        for e in al:
            ally[e] = al 
    elif x[0] == 'Enemy':
        en1 = set()
        en2 = set()
        if x[1] in ally:
            en1.add(x[1])
            for i in ally[x[1]]:
                en1.add(i)
        else:
            en1.add(x[1])
        if x[2] in ally:
            en2.add(x[2])
            for i in ally[x[2]]:
                en2.add(i)
        else:
            en2.add(x[2])
            
        for i in en1:
            for e in en2:
                if i not in sustu:
                    sustu[i] = [e]
                else:
                    sustu[i] += [e]
                if e not in sustu:
                    sustu[e] = [i]
                else:
                    sustu[e] += [i]
        
    elif x[0] == 'Table':
        check = True
        if x[1] in sustu:
            if x[-1] in sustu[x[1]]:
                check = False
        for i in range(1,len(x[1:])-1):
            if x[i+1] in sustu:
                if x[i] in sustu[x[i+1]]:
                    check = False
                    break
        if check == False:
            print('No')
        else:
            print('Okay')
        
    x = input()

# 1680897, 2022-11-12 11:13:09, PPPPP- (83%)

x = input()
ally = {}
enemy = {}
sustu = {}
while x != 'End':
    x = x.split()
    
    if x[0] == 'Ally':
        al = set()
        for i in x[1:]:
            al.add(i)
        for e in al:
            ally[e] = al 
    elif x[0] == 'Enemy':
        en1 = set()
        en2 = set()
        if x[1] in ally:
            for i in ally[x[1]]:
                en1.add(i)
        else:
            en1.add(x[1])
        if x[2] in ally:
            for i in ally[x[2]]:
                en2.add(i)
        else:
            en2.add(x[2])
            
        for i in en1:
            for e in en2:
                if i not in sustu:
                    sustu[i] = [e]
                else:
                    sustu[i] += [e]
                if e not in sustu:
                    sustu[e] = [i]
                else:
                    sustu[e] += [i]
        
    elif x[0] == 'Table':
        check = True
        if x[1] in sustu:
            if x[-1] in sustu[x[1]]:
                check = False
        for i in range(1,len(x[1:])-1):
            if x[i+1] in sustu:
                if x[i] in sustu[x[i+1]]:
                    check = False
                    break
        if check == False:
            print('No')
        else:
            print('Okay')
        
    x = input()

# 1680935, 2022-11-12 11:14:44, PPPPPP (100%)

x = input()
ally = {}
enemy = {}
sustu = {}
while x != 'End':
    x = x.split()
    
    if x[0] == 'Ally':
        al = set()
        for i in x[1:]:
            al.add(i)
        for e in al:
            ally[e] = al 
    elif x[0] == 'Enemy':
        en1 = set()
        en2 = set()
        if x[1] in ally:
            for i in ally[x[1]]:
                en1.add(i)
        else:
            en1.add(x[1])
        if x[2] in ally:
            for i in ally[x[2]]:
                en2.add(i)
        else:
            en2.add(x[2])
            
        for i in en1:
            for e in en2:
                if i not in sustu:
                    sustu[i] = [e]
                else:
                    sustu[i] += [e]
                if e not in sustu:
                    sustu[e] = [i]
                else:
                    sustu[e] += [i]
        
    elif x[0] == 'Table':
        check = True
        if x[1] in sustu:
            if x[-1] in sustu[x[1]]:
                check = False
        for i in range(1,len(x[1:])):
            if x[i+1] in sustu:
                if x[i] in sustu[x[i+1]]:
                    check = False
                    break
        if check == False:
            print('No')
        else:
            print('Okay')
        
    x = input()


6531304621
# 1679998, 2022-11-12 10:37:07, PPPP-- (67%)

lally = []
lenemy = []
output = []
inp = input()


def ok(nextto, lenemy):
    for ch1 in nextto:
        for ch2 in lenemy:
            if ch1 == ch2:
                return 'No'
    return 'Okay'


while inp != 'End':
    inp = inp.split()
    if inp[0] == 'Ally':
        lally.append(set(inp[1:]))  # ***
    elif inp[0] == 'Enemy':
        lenemy.append(set(inp[1:]))
        for ally in lally:
            if inp[1] in ally:
                for ch in ally:
                    lenemy.append({ch, inp[2]})
            if inp[2] in ally:
                for ch in ally:
                    lenemy.append({ch, inp[1]})
    elif inp[0] == 'Table':
        nextto = [set(inp[1:][i:i+2]) for i in range(len(inp[1:])-1)] + [{inp[-1], inp[1]}]
        output.append(ok(nextto, lenemy))
    inp = input()

for e in output:
    print(e)
# 1680297, 2022-11-12 10:51:16, PPPP-- (67%)

lally = []
lenemy = []
output = []
inp = input()


def ok(nextto, lenemy):
    for ch1 in nextto:
        for ch2 in lenemy:
            if ch1 == ch2:
                return 'No'
    return 'Okay'


while inp != 'End':
    inp = inp.split()
    if inp[0] == 'Ally':
        if set(inp[1:]) & set([ch for ally in lally for ch in ally]) == set():
            lally.append(set(inp[1:]))
        else:
            for i in range(len(lally)):
                if set(inp[1:]) & lally[i] != set():
                    lally[i] = set(inp[1:]) | lally[i]
    elif inp[0] == 'Enemy':
        lenemy.append(set(inp[1:]))
        for ally in lally:
            if inp[1] in ally:
                for ch in ally:
                    lenemy.append({ch, inp[2]})
            if inp[2] in ally:
                for ch in ally:
                    lenemy.append({ch, inp[1]})
    elif inp[0] == 'Table':
        nextto = [set(inp[1:][i:i+2]) for i in range(len(inp[1:])-1)] + [{inp[-1], inp[1]}]
        output.append(ok(nextto, lenemy))
    inp = input()

for e in output:
    print(e)
# 1680848, 2022-11-12 11:11:21, PPPxPP (83%)

lally = []
lenemy = []
output = []
inp = input()


def ok(nextto, lenemy):
    for ch1 in nextto:
        ch1 = list(ch1)
        for ch2 in lenemy:
            if (ch1[0] in ch2[0]) and (ch1[1] in ch2[1]):
                return 'No'
            elif (ch1[0] in ch2[1]) and (ch1[1] in ch2[0]):
                return 'No'
    return 'Okay'


while inp != 'End':
    inp = inp.split()
    if inp[0] == 'Ally':
        if set(inp[1:]) & set([ch for ally in lally for ch in ally]) == set():
            lally.append(set(inp[1:]))
        else:
            for i in range(len(lally)):
                if set(inp[1:]) & lally[i] != set():
                    lally[i] = set(inp[1:]) | lally[i]
    elif inp[0] == 'Enemy':
        ch1 = inp[1]
        ch2 = inp[2]
        found = False
        for ally1 in lally:
            for ally2 in lally:
                if ch1 in ally1 and ch2 in ally2:
                    lenemy.append((ally1, ally2))
                    found = True
                    break
        if found == False:
            for ally1 in lally:
                for ally2 in lally:
                    if ch1 in ally1:
                        lenemy.append((ally1, {ch2, }))
                        found = True
                        break
        if found == False:
            for ally1 in lally:
                for ally2 in lally:
                    if ch2 in ally2:
                        lenemy.append((ally2, {ch1, }))
                        found = True
                        break
        if found == False:
            lenemy.append(({ch1, }, {ch2, }))
    elif inp[0] == 'Table':
        nextto = [set(inp[1:][i:i+2]) for i in range(len(inp[1:])-1)] + [{inp[-1], inp[1]}]
        output.append(ok(nextto, lenemy))
    inp = input()
for e in output:
    print(e)
# 1681102, 2022-11-12 11:18:59, ------ (0%)

lally = []
lenemy = []
output = []
inp = input()


def ok(nextto, lenemy):
    for ch1 in nextto:
        for ch2 in lenemy:
            if (ch1[0] in ch2[0]) and (ch1[1] in ch2[1]):
                return 'No'
            elif (ch1[0] in ch2[1]) and (ch1[1] in ch2[0]):
                return 'No'
    return 'Okay'


while inp != 'End':
    inp = inp.split()
    if inp[0] == 'Ally':
        if set(inp[1:]) & set([ch for ally in lally for ch in ally]) == set():
            lally.append(set(inp[1:]))
        else:
            for i in range(len(lally)):
                if set(inp[1:]) & lally[i] != set():
                    lally[i] = set(inp[1:]) | lally[i]
    elif inp[0] == 'Enemy':
        ch1 = inp[1]
        ch2 = inp[2]
        found = False
        for ally1 in lally:
            for ally2 in lally:
                if ch1 in ally1 and ch2 in ally2:
                    lenemy.append((ally1, ally2))
                    found = True
                    break
        if found == False:
            for ally1 in lally:
                for ally2 in lally:
                    if ch1 in ally1:
                        lenemy.append((ally1, {ch2, }))
                        found = True
                        break
        if found == False:
            for ally1 in lally:
                for ally2 in lally:
                    if ch2 in ally2:
                        lenemy.append((ally2, {ch1, }))
                        found = True
                        break
        if found == False:
            lenemy.append(({ch1, }, {ch2, }))
    elif inp[0] == 'Table':
        nextto = [(inp[1:][i:i+2]) for i in range(len(inp[1:])-1)] + [[inp[-1], inp[1]]]
        print(nextto)
        output.append(ok(nextto, lenemy))
    inp = input()
for e in output:
    print(e)
# 1681150, 2022-11-12 11:20:07, PPPPPP (100%)

lally = []
lenemy = []
output = []
inp = input()


def ok(nextto, lenemy):
    for ch1 in nextto:
        for ch2 in lenemy:
            if (ch1[0] in ch2[0]) and (ch1[1] in ch2[1]):
                return 'No'
            elif (ch1[0] in ch2[1]) and (ch1[1] in ch2[0]):
                return 'No'
    return 'Okay'


while inp != 'End':
    inp = inp.split()
    if inp[0] == 'Ally':
        if set(inp[1:]) & set([ch for ally in lally for ch in ally]) == set():
            lally.append(set(inp[1:]))
        else:
            for i in range(len(lally)):
                if set(inp[1:]) & lally[i] != set():
                    lally[i] = set(inp[1:]) | lally[i]
    elif inp[0] == 'Enemy':
        ch1 = inp[1]
        ch2 = inp[2]
        found = False
        for ally1 in lally:
            for ally2 in lally:
                if ch1 in ally1 and ch2 in ally2:
                    lenemy.append((ally1, ally2))
                    found = True
                    break
        if found == False:
            for ally1 in lally:
                for ally2 in lally:
                    if ch1 in ally1:
                        lenemy.append((ally1, {ch2, }))
                        found = True
                        break
        if found == False:
            for ally1 in lally:
                for ally2 in lally:
                    if ch2 in ally2:
                        lenemy.append((ally2, {ch1, }))
                        found = True
                        break
        if found == False:
            lenemy.append(({ch1, }, {ch2, }))
    elif inp[0] == 'Table':
        nextto = [(inp[1:][i:i+2]) for i in range(len(inp[1:])-1)] + [(inp[-1], inp[1])]
        output.append(ok(nextto, lenemy))
    inp = input()
for e in output:
    print(e)

6531308121
# 1679868, 2022-11-12 10:30:43, PPPP-P (83%)

a = []
e = {}
while True :
    g1 = 0 ; g2 = 0
    x = input()
    if x == 'End' :
        break
    x = x.split()
    if x[0] == 'Ally' :
        a.append(set(x[1:]))
    elif x[0] == 'Enemy' :
        for i in a :
            if x[1] in i :
                g1 = i
            if x[2] in i :
                g2 = i
        if g1 == 0 :
            g1 = {x[1]}
        if g2 == 0 :
            g2 = {x[2]}
        for i in g1 :
            if i not in e :
                e[i] = g2
            else :
                for j in g2 :
                    e[i].add(j)
        for i in g2 :
            if i not in e :
                e[i] = g1
            else :
                for j in g1 :
                    e[i].add(j)
    if x[0] == 'Table' :
        x = x[1:]
        for i in range(len(x)) :
            check = True
            if x[i] in e :
                if x[i-1] in e[x[i]] :
                    check = False
                    break
        if check == True :
            print('Okay')
        else :
            print('No')
# 1680207, 2022-11-12 10:46:48, PPPPTT (67%)

a = []
e = {}
while True :
    g1 = 0 ; g2 = 0
    x = input()
    if x == 'End' :
        break
    x = x.split()
    if x[0] == 'Ally' :
        a.append(x[1:])
    elif x[0] == 'Enemy' :
        for i in a :
            if x[1] in i :
                g1 = i
            if x[2] in i :
                g2 = i
        if g1 == 0 :
            g1 = [x[1]]
        if g2 == 0 :
            g2 = [x[2]]
        for i in g1 :
            if i not in e :
                e[i] = g2
            else :
                for j in g2 :
                    e[i].append(j)
        for i in g2 :
            if i not in e :
                e[i] = g1
            else :
                for j in g1 :
                    e[i].append(j)
    if x[0] == 'Table' :
        x = x[1:]
        for i in range(len(x)) :
            check = True
            if x[i] in e :
                if x[i-1] in e[x[i]] :
                    check = False
                    break
        if check == True :
            print('Okay')
        else :
            print('No')
# 1680216, 2022-11-12 10:47:15, PPPP-P (83%)

a = []
e = {}
while True :
    g1 = 0 ; g2 = 0
    x = input()
    if x == 'End' :
        break
    x = x.split()
    if x[0] == 'Ally' :
        a.append(set(x[1:]))
    elif x[0] == 'Enemy' :
        for i in a :
            if x[1] in i :
                g1 = i
            if x[2] in i :
                g2 = i
        if g1 == 0 :
            g1 = {x[1]}
        if g2 == 0 :
            g2 = {x[2]}
        for i in g1 :
            if i not in e :
                e[i] = g2
            else :
                for j in g2 :
                    e[i].add(j)
        for i in g2 :
            if i not in e :
                e[i] = g1
            else :
                for j in g1 :
                    e[i].add(j)
    if x[0] == 'Table' :
        x = x[1:]
        for i in range(len(x)) :
            check = True
            if x[i] in e :
                if x[i-1] in e[x[i]] :
                    check = False
                    break
        if check == True :
            print('Okay')
        else :
            print('No')
# 1680693, 2022-11-12 11:05:59, PPPP-P (83%)

a = []
e = {}
while True :
    g1 = 0 ; g2 = 0
    x = input()
    if x == 'End' :
        break
    x = x.split()
    if x[0] == 'Ally' :
        a.append(set(x[1:]))
    elif x[0] == 'Enemy' :
        for i in a :
            if x[1] in i :
                g1 = i
            if x[2] in i :
                g2 = i
        if g1 == 0 :
            g1 = {x[1]}
            a.append(g1)
        if g2 == 0 :
            g2 = {x[2]}
            a.append(g2)
        for i in g1 :
            if i not in e :
                e[i] = g2
            else :
                for j in g2 :
                    e[i].add(j)
        for i in g2 :
            if i not in e :
                e[i] = g1
            else :
                for j in g1 :
                    e[i].add(j)
    if x[0] == 'Table' :
        x = x[1:]
        for i in range(len(x)) :
            check = True
            if x[i] in e :
                if x[i-1] in e[x[i]] :
                    check = False
                    break
        if check == True :
            print('Okay')
        else :
            print('No')
# 1680784, 2022-11-12 11:09:07, PPPPPP (100%)

a = []
e = {}
while True :
    g1 = 0 ; g2 = 0
    x = input()
    if x == 'End' :
        break
    x = x.split()
    if x[0] == 'Ally' :
        a.append(set(x[1:]))
    elif x[0] == 'Enemy' :
        for i in a :
            if x[1] in i :
                g1 = i
            if x[2] in i :
                g2 = i
        if g1 == 0 :
            g1 = {x[1]}
            a.append(g1)
        if g2 == 0 :
            g2 = {x[2]}
            a.append(g2)
        for i in g1 :
            if i not in e :
                e[i] = g2
            else :
                for j in g2 :
                    r = e[i].union({j})
                    e[i] = r
        for i in g2 :
            if i not in e :
                e[i] = g1
            else :
                for j in g1 :
                    r = e[i].union({j})
                    e[i] = r
    if x[0] == 'Table' :
        x = x[1:]
        for i in range(len(x)) :
            check = True
            if x[i] in e :
                if x[i-1] in e[x[i]] :
                    check = False
                    break
        if check == True :
            print('Okay')
        else :
            print('No')   

6532092721
# 1679440, 2022-11-12 10:10:58, ------ (0%)

def check(coun ,checker,dic_ally , dic_enem) :
    if checker in dic_enem and coun in dic_enem[checker] :
        return False
    elif coun in dic_enem and checker in dic_enem[coun] :
        return False
    return True

comm = input().split()
dic_ally = {}
dic_enem = {}
while comm[0] != "End" :
    if comm[0] == "Ally" :
        for coun in comm[1:] :
            ally = comm[1:]
            ally.remove(coun)
            dic_ally[coun] = ally
    if comm[0] == "Enemy" :
        if comm[1] not in dic_enem :
            dic_enem[comm[1]] = []
        dic_enem[comm[1]].append(comm[2])
        if (comm[2] in dic_ally) :
            dic_enem[comm[1]] += dic_ally[comm[2]]
        
        if comm[2] not in dic_enem :
            dic_enem[comm[2]] = []
        dic_enem[comm[2]].append(comm[1])
        if (comm[1] in dic_ally) :
            dic_enem[comm[2]] += dic_ally[comm[1]]
    if comm[0] == "Table" :
        table = comm[1:]
        flag = True
        for i in range(len(table)) :
            check1 = table[i-1] if i-1 >= 0 else table[-1]
            check2 = table[i+1] if i+1 < len(table) else table[0]
            if not (check(table[i] , check1 ,dic_ally , dic_enem) and check(table[i] ,check2,dic_ally , dic_enem)) :
                flag = False
                break
        if (flag) :
            print("Okay")
        else :
            print("No")
    comm = input().split()
print(dic_ally)
print(dic_enem)
    
# 1679446, 2022-11-12 10:11:16, PPPP-- (67%)

def check(coun ,checker,dic_ally , dic_enem) :
    if checker in dic_enem and coun in dic_enem[checker] :
        return False
    elif coun in dic_enem and checker in dic_enem[coun] :
        return False
    return True

comm = input().split()
dic_ally = {}
dic_enem = {}
while comm[0] != "End" :
    if comm[0] == "Ally" :
        for coun in comm[1:] :
            ally = comm[1:]
            ally.remove(coun)
            dic_ally[coun] = ally
    if comm[0] == "Enemy" :
        if comm[1] not in dic_enem :
            dic_enem[comm[1]] = []
        dic_enem[comm[1]].append(comm[2])
        if (comm[2] in dic_ally) :
            dic_enem[comm[1]] += dic_ally[comm[2]]
        
        if comm[2] not in dic_enem :
            dic_enem[comm[2]] = []
        dic_enem[comm[2]].append(comm[1])
        if (comm[1] in dic_ally) :
            dic_enem[comm[2]] += dic_ally[comm[1]]
    if comm[0] == "Table" :
        table = comm[1:]
        flag = True
        for i in range(len(table)) :
            check1 = table[i-1] if i-1 >= 0 else table[-1]
            check2 = table[i+1] if i+1 < len(table) else table[0]
            if not (check(table[i] , check1 ,dic_ally , dic_enem) and check(table[i] ,check2,dic_ally , dic_enem)) :
                flag = False
                break
        if (flag) :
            print("Okay")
        else :
            print("No")
    comm = input().split()
# 1679740, 2022-11-12 10:25:13, PPPP-- (67%)

def check(coun ,checker , dic_enem) :
    if checker in dic_enem and coun in dic_enem[checker] :
        return False
    elif coun in dic_enem and checker in dic_enem[coun] :
        return False
    return True
def add_enem(curr , targ , dic_enem , dic_ally) :
    if curr not in dic_enem :
        dic_enem[curr] = []
    dic_enem[curr].append(targ)
    if targ in dic_ally :
        for coun in dic_ally[targ] :
            dic_enem[curr].append(coun)
            if coun not in dic_enem :
                dic_enem[coun] = []
            dic_enem[coun].append(curr)

comm = input().split()
dic_ally = {}
dic_enem = {}
while comm[0] != "End" :
    if comm[0] == "Ally" :
        for coun in comm[1:] :
            ally = comm[1:]
            ally.remove(coun)
            dic_ally[coun] = ally
    if comm[0] == "Enemy" :
        add_enem(comm[1] , comm[2] , dic_ally=dic_ally , dic_enem=dic_enem)
        add_enem(comm[2] , comm[1] , dic_ally=dic_ally , dic_enem=dic_enem)
    if comm[0] == "Table" :
        table = comm[1:]
        flag = True
        for i in range(len(table)) :
            check1 = table[i-1] if i-1 >= 0 else table[-1]
            check2 = table[i+1] if i+1 < len(table) else table[0]
            if not (check(table[i] , check1 , dic_enem) and check(table[i] ,check2 , dic_enem)) :
                flag = False
                break
        if (flag) :
            print("Okay")
        else :
            print("No")
    comm = input().split()
#print(dic_enem)
    
# 1680093, 2022-11-12 10:41:26, P---P- (33%)

def check(coun ,checker , dic_enem) :
    if checker in dic_enem and coun in dic_enem[checker] :
        return False
    elif coun in dic_enem and checker in dic_enem[coun] :
        return False
    return True


def add_enem(curr , targ , dic_enem , dic_ally) :
    if curr not in dic_enem :
        dic_enem[curr] = []
    if targ not in dic_enem :
        dic_enem[targ] = []
    ally_cur = dic_ally[curr] if curr in dic_ally else []
    ally_targ = dic_ally[targ] if targ in dic_ally else []
    for coun in ally_cur :
        if coun not in dic_enem :
            dic_enem[coun] = []
        dic_enem[coun] += ally_targ
    for coun in ally_targ :
        if coun not in dic_enem :
            dic_enem[coun] = []
        dic_enem[coun] += ally_cur

comm = input().split()
dic_ally = {}
dic_enem = {}
while comm[0] != "End" :
    if comm[0] == "Ally" :
        for coun in comm[1:] :
            ally = comm[1:]
            dic_ally[coun] = ally
    if comm[0] == "Enemy" :
        add_enem(comm[1] , comm[2] , dic_enem, dic_ally)
    if comm[0] == "Table" :
        table = comm[1:]
        flag = True
        for i in range(len(table)) :
            check1 = table[i-1] if i-1 >= 0 else table[-1]
            check2 = table[i+1] if i+1 < len(table) else table[0]
            if not (check(table[i] , check1 , dic_enem) and check(table[i] ,check2 , dic_enem)) :
                flag = False
                break
        if (flag) :
            print("Okay")
        else :
            print("No")
    comm = input().split()
# 1680116, 2022-11-12 10:42:17, PPPPPP (100%)

def check(coun ,checker , dic_enem) :
    if checker in dic_enem and coun in dic_enem[checker] :
        return False
    elif coun in dic_enem and checker in dic_enem[coun] :
        return False
    return True


def add_enem(curr , targ , dic_enem , dic_ally) :
    if curr not in dic_enem :
        dic_enem[curr] = []
    if targ not in dic_enem :
        dic_enem[targ] = []
    ally_cur = dic_ally[curr] if curr in dic_ally else [curr]
    ally_targ = dic_ally[targ] if targ in dic_ally else [targ]
    for coun in ally_cur :
        if coun not in dic_enem :
            dic_enem[coun] = []
        dic_enem[coun] += ally_targ
    for coun in ally_targ :
        if coun not in dic_enem :
            dic_enem[coun] = []
        dic_enem[coun] += ally_cur

comm = input().split()
dic_ally = {}
dic_enem = {}
while comm[0] != "End" :
    if comm[0] == "Ally" :
        for coun in comm[1:] :
            ally = comm[1:]
            dic_ally[coun] = ally
    if comm[0] == "Enemy" :
        add_enem(comm[1] , comm[2] , dic_enem, dic_ally)
    if comm[0] == "Table" :
        table = comm[1:]
        flag = True
        for i in range(len(table)) :
            check1 = table[i-1] if i-1 >= 0 else table[-1]
            check2 = table[i+1] if i+1 < len(table) else table[0]
            if not (check(table[i] , check1 , dic_enem) and check(table[i] ,check2 , dic_enem)) :
                flag = False
                break
        if (flag) :
            print("Okay")
        else :
            print("No")
    comm = input().split()

6532106921
# 1679681, 2022-11-12 10:23:13, P----- (17%)

x=input().split()
cnt=0
team=dict(); fight=dict()
while(x[0]!='End'):
    if(x[0]=='Ally'):
        cnt+=1; fight[cnt]=dict()
        for i in range(1,len(x)):
            team[x[i]]=cnt
    if(x[0]=='Enemy'):
        #xteam=team[x[1]]; yteam=team[x[2]] 
        if(x[1] not in team):
            cnt+=1; team[x[1]]=cnt
            fight[cnt]=dict()
        if(x[2] not in team):
            cnt+=1; team[x[2]]=cnt  
            fight[cnt]=dict()   
        if(team[x[1]] not in fight[team[x[2]]]):
            fight[team[x[2]]][team[x[1]]]=-1
        if(team[x[2]] not in fight[team[x[1]]]):
            fight[team[x[1]]][team[x[2]]]=-1      
    if(x[0]=='Table'):
        mark=0
        for i in range(1,len(x)-1):
            if(x[i] not in team):
                cnt+=1; team[x[i]]=cnt
                fight[cnt]=dict()
            if(x[i+1] not in team):
                cnt+=1; team[x[i+1]]=cnt  
                fight[cnt]=dict() 
            teama=team[x[i]]; teamb=team[x[i+1]]    
            if(teama==teamb): continue
            for j in fight[teama].items():
                if(j[0]==teamb):
                    mark=1
                    print('NO'); break
            if(mark): break
        if(not mark): print('Okay')
    x=input().split()
    
# 1679691, 2022-11-12 10:23:29, P-PPP- (67%)

x=input().split()
cnt=0
team=dict(); fight=dict()
while(x[0]!='End'):
    if(x[0]=='Ally'):
        cnt+=1; fight[cnt]=dict()
        for i in range(1,len(x)):
            team[x[i]]=cnt
    if(x[0]=='Enemy'):
        #xteam=team[x[1]]; yteam=team[x[2]] 
        if(x[1] not in team):
            cnt+=1; team[x[1]]=cnt
            fight[cnt]=dict()
        if(x[2] not in team):
            cnt+=1; team[x[2]]=cnt  
            fight[cnt]=dict()   
        if(team[x[1]] not in fight[team[x[2]]]):
            fight[team[x[2]]][team[x[1]]]=-1
        if(team[x[2]] not in fight[team[x[1]]]):
            fight[team[x[1]]][team[x[2]]]=-1      
    if(x[0]=='Table'):
        mark=0
        for i in range(1,len(x)-1):
            if(x[i] not in team):
                cnt+=1; team[x[i]]=cnt
                fight[cnt]=dict()
            if(x[i+1] not in team):
                cnt+=1; team[x[i+1]]=cnt  
                fight[cnt]=dict() 
            teama=team[x[i]]; teamb=team[x[i+1]]    
            if(teama==teamb): continue
            for j in fight[teama].items():
                if(j[0]==teamb):
                    mark=1
                    print('No'); break
            if(mark): break
        if(not mark): print('Okay')
    x=input().split()
    
# 1679736, 2022-11-12 10:25:04, Pxxxxx (17%)

x=input().split()
cnt=0
team=dict(); fight=dict()
while(x[0]!='End'):
    if(x[0]=='Ally'):
        cnt+=1; fight[cnt]=dict()
        for i in range(1,len(x)):
            team[x[i]]=cnt
    if(x[0]=='Enemy'):
        #xteam=team[x[1]]; yteam=team[x[2]] 
        if(x[1] not in team):
            cnt+=1; team[x[1]]=cnt
            fight[cnt]=dict()
        if(x[2] not in team):
            cnt+=1; team[x[2]]=cnt  
            fight[cnt]=dict()   
        if(team[x[1]] not in fight[team[x[2]]]):
            fight[team[x[2]]][team[x[1]]]=-1
        if(team[x[2]] not in fight[team[x[1]]]):
            fight[team[x[1]]][team[x[2]]]=-1      
    if(x[0]=='Table'):
        mark=0
        for i in range(1,len(x)-1):
            if(x[i] not in team):
                cnt+=1; team[x[i]]=cnt
                fight[cnt]=dict()
            if(x[i+1] not in team):
                cnt+=1; team[x[i+1]]=cnt  
                fight[cnt]=dict() 
            teama=team[x[i]]; teamb=team[x[i+1]]    
            if(teama==teamb): continue
            for j in fight[teama].items():
                if(j[0]==teamb):
                    mark=1
                    print('No'); break
            if(mark): break
        for j in fight[team[x[1]]].items():
            if(j[0]==team[x[len(x)]]):
                mark=1; print('No')
        if(not mark): print('Okay')
    x=input().split()
    
# 1679742, 2022-11-12 10:25:21, Px--xx (17%)

x=input().split()
cnt=0
team=dict(); fight=dict()
while(x[0]!='End'):
    if(x[0]=='Ally'):
        cnt+=1; fight[cnt]=dict()
        for i in range(1,len(x)):
            team[x[i]]=cnt
    if(x[0]=='Enemy'):
        #xteam=team[x[1]]; yteam=team[x[2]] 
        if(x[1] not in team):
            cnt+=1; team[x[1]]=cnt
            fight[cnt]=dict()
        if(x[2] not in team):
            cnt+=1; team[x[2]]=cnt  
            fight[cnt]=dict()   
        if(team[x[1]] not in fight[team[x[2]]]):
            fight[team[x[2]]][team[x[1]]]=-1
        if(team[x[2]] not in fight[team[x[1]]]):
            fight[team[x[1]]][team[x[2]]]=-1      
    if(x[0]=='Table'):
        mark=0
        for i in range(1,len(x)-1):
            if(x[i] not in team):
                cnt+=1; team[x[i]]=cnt
                fight[cnt]=dict()
            if(x[i+1] not in team):
                cnt+=1; team[x[i+1]]=cnt  
                fight[cnt]=dict() 
            teama=team[x[i]]; teamb=team[x[i+1]]    
            if(teama==teamb): continue
            for j in fight[teama].items():
                if(j[0]==teamb):
                    mark=1
                    print('No'); break
            if(mark): break
        for j in fight[team[x[1]]].items():
            if(j[0]==team[x[len(x)-1]]):
                mark=1; print('No')
        if(not mark): print('Okay')
    x=input().split()
    
# 1679771, 2022-11-12 10:27:03, PPPPPP (100%)

x=input().split()
cnt=0
team=dict(); fight=dict()
while(x[0]!='End'):
    if(x[0]=='Ally'):
        cnt+=1; fight[cnt]=dict()
        for i in range(1,len(x)):
            team[x[i]]=cnt
    if(x[0]=='Enemy'):
        #xteam=team[x[1]]; yteam=team[x[2]] 
        if(x[1] not in team):
            cnt+=1; team[x[1]]=cnt
            fight[cnt]=dict()
        if(x[2] not in team):
            cnt+=1; team[x[2]]=cnt  
            fight[cnt]=dict()   
        if(team[x[1]] not in fight[team[x[2]]]):
            fight[team[x[2]]][team[x[1]]]=-1
        if(team[x[2]] not in fight[team[x[1]]]):
            fight[team[x[1]]][team[x[2]]]=-1      
    if(x[0]=='Table'):
        mark=0
        for i in range(1,len(x)-1):
            if(x[i] not in team):
                cnt+=1; team[x[i]]=cnt
                fight[cnt]=dict()
            if(x[i+1] not in team):
                cnt+=1; team[x[i+1]]=cnt  
                fight[cnt]=dict() 
            teama=team[x[i]]; teamb=team[x[i+1]]    
            if(teama==teamb): continue
            for j in fight[teama].items():
                if(j[0]==teamb):
                    mark=1
                    print('No'); break
            if(mark): break
        if(not mark):
            for j in fight[team[x[1]]].items():
                if(j[0]==team[x[len(x)-1]]):
                    mark=1; print('No')
        if(not mark): print('Okay')
    x=input().split()
    

6532148221
# 1679452, 2022-11-12 10:11:27, x-PPPx (50%)

Number = {}
En = {}
Count = 1

while True:
    inp = input()
    if inp == "End": break
    inp = inp.split()
    if inp[0] == "Ally":
        for i in range(1, len(inp)):
            Number[inp[i]] = Count
        Count += 1
    elif inp[0] == 'Enemy':
        if not inp[1] in Number.keys():
            Number[inp[1]] = Count
            Count += 1
        if not inp[2] in Number.keys():
            Number[inp[2]] = Count
            Count += 1

        N1 = Number[inp[1]]
        N2 = Number[inp[2]]
        if not N1 in En.keys():
            En[N1] = set()
        if not N2 in En.keys():
            En[N2] = set()

        En[N1].add(N2)
        En[N2].add(N1)
    else:
        Can = True
        for i in range(1, len(inp) - 1):
            if not inp[i] in Number.keys():
                Number[inp[i]] = Count
                En[Count] = set()
                Count += 1
            if not inp[i + 1] in Number.keys():
                Number[inp[i + 1]] = Count
                En[Count] = set()
                Count += 1
            N1 = Number[inp[i]]
            N2 = Number[inp[i + 1]]
            if N1 in En[N2] or N2 in En[N1]:
                Can = False
                break
        if Can: print("Okay")
        else: print("No")

# 1679484, 2022-11-12 10:12:52, x-PPPx (50%)

Number = {}
En = {}
Count = 1

while True:
    inp = input()
    if inp == "End": break
    inp = inp.split()
    if inp[0] == "Ally":
        for i in range(1, len(inp)):
            Number[inp[i]] = Count
        Count += 1
    elif inp[0] == 'Enemy':
        if not inp[1] in Number.keys():
            Number[inp[1]] = Count
            Count += 1
        if not inp[2] in Number.keys():
            Number[inp[2]] = Count
            Count += 1

        N1 = Number[inp[1]]
        N2 = Number[inp[2]]
        if not N1 in En.keys():
            En[N1] = set()
        if not N2 in En.keys():
            En[N2] = set()

        En[N1].add(N2)
        En[N2].add(N1)
    else:
        if len(inp) == 2:
            print("Okay")
            continue
        Can = True
        for i in range(1, len(inp) - 1):
            if not inp[i] in Number.keys():
                Number[inp[i]] = Count
                En[Count] = set()
                Count += 1
            if not inp[i + 1] in Number.keys():
                Number[inp[i + 1]] = Count
                En[Count] = set()
                Count += 1
            N1 = Number[inp[i]]
            N2 = Number[inp[i + 1]]
            if N1 in En[N2] or N2 in En[N1]:
                Can = False
                break
        if Can: print("Okay")
        else: print("No")

# 1679515, 2022-11-12 10:14:11, P-PPP- (67%)

Number = {}
En = {}
Count = 1

while True:
    inp = input()
    if inp == "End": break
    inp = inp.split()
    if inp[0] == "Ally":
        for i in range(1, len(inp)):
            Number[inp[i]] = Count
        Count += 1
    elif inp[0] == 'Enemy':
        if not inp[1] in Number.keys():
            Number[inp[1]] = Count
            Count += 1
        if not inp[2] in Number.keys():
            Number[inp[2]] = Count
            Count += 1

        N1 = Number[inp[1]]
        N2 = Number[inp[2]]
        if not N1 in En.keys():
            En[N1] = set()
        if not N2 in En.keys():
            En[N2] = set()

        En[N1].add(N2)
        En[N2].add(N1)
    else:
        if len(inp) == 2:
            print("Okay")
            continue
        Can = True
        for i in range(1, len(inp) - 1):
            if not inp[i] in Number.keys():
                Number[inp[i]] = Count
                Count += 1
            if not inp[i + 1] in Number.keys():
                Number[inp[i + 1]] = Count
                Count += 1
                
            N1 = Number[inp[i]]
            N2 = Number[inp[i + 1]]

            if not N1 in En.keys():
                En[N1] = set()
            if not N2 in En.keys():
                En[N2] = set()

            if N1 in En[N2] or N2 in En[N1]:
                Can = False
                break
        if Can: print("Okay")
        else: print("No")

# 1679719, 2022-11-12 10:24:17, P-PPP- (67%)

Number = {}
En = []
Count = 1

while True:
    inp = input()
    if inp == "End": break
    inp = inp.split()
    if inp[0] == "Ally":
        for i in range(1, len(inp)):
            Number[inp[i]] = Count
        Count += 1
    elif inp[0] == 'Enemy':
        if not inp[1] in Number.keys():
            Number[inp[1]] = Count
            Count += 1
        if not inp[2] in Number.keys():
            Number[inp[2]] = Count
            Count += 1

        N1 = Number[inp[1]]
        N2 = Number[inp[2]]

        En += [(N1, N2)]
    else:
        if len(inp) == 2:
            print("Okay")
            continue
        Can = True
        for i in range(1, len(inp) - 1):
            if not inp[i] in Number.keys():
                Number[inp[i]] = Count
                Count += 1
            if not inp[i + 1] in Number.keys():
                Number[inp[i + 1]] = Count
                Count += 1
                
            N1 = Number[inp[i]]
            N2 = Number[inp[i + 1]]

            for e in En:
                if (N1 == e[0] and N2 == e[1]) or( N1 == e[1] and N2 == e[0]):
                    Can = False
                    break
        if Can: print("Okay")
        else: print("No")

# 1679754, 2022-11-12 10:26:05, PPPPPP (100%)

Number = {}
En = {}
Count = 1

while True:
    inp = input()
    if inp == "End": break
    inp = inp.split()
    if inp[0] == "Ally":
        for i in range(1, len(inp)):
            Number[inp[i]] = Count
        Count += 1
    elif inp[0] == 'Enemy':
        if not inp[1] in Number.keys():
            Number[inp[1]] = Count
            Count += 1
        if not inp[2] in Number.keys():
            Number[inp[2]] = Count
            Count += 1

        N1 = Number[inp[1]]
        N2 = Number[inp[2]]
        if not N1 in En.keys():
            En[N1] = set()
        if not N2 in En.keys():
            En[N2] = set()

        En[N1].add(N2)
        En[N2].add(N1)
    else:
        if len(inp) == 2:
            print("Okay")
            continue
        inp += [inp[1]]
        Can = True
        for i in range(1, len(inp) - 1):
            if not inp[i] in Number.keys():
                Number[inp[i]] = Count
                Count += 1
            if not inp[i + 1] in Number.keys():
                Number[inp[i + 1]] = Count
                Count += 1

            N1 = Number[inp[i]]
            N2 = Number[inp[i + 1]]

            if not N1 in En.keys():
                En[N1] = set()
            if not N2 in En.keys():
                En[N2] = set()

            if N1 in En[N2] or N2 in En[N1]:
                Can = False
                break
        
        if Can: print("Okay")
        else: print("No")


6530082021
# 1679288, 2022-11-12 10:02:18, P----- (17%)

k = input().split()
Ally = []
enemy = {}
while k[0] != 'End':
    if k[0] == 'Ally':
        x = set()
        for i in range(1,len(k)):
            x.add(k[i])
        Ally.append(x)
    elif k[0] == 'Enemy':
        if k[1] not in enemy:
            enemy[k[1]] = {k[2]}
        else:
            enemy[k[1]].add(k[2])
        if k[2] not in enemy:
            enemy[k[2]] = {k[1]}
        else:
            enemy[k[2]].add(k[1])
    elif k[0] == 'Table':
        print('Okay')
    k = input().split()
# 1679292, 2022-11-12 10:02:30, ------ (0%)

k = input().split()
Ally = []
enemy = {}
while k[0] != 'End':
    if k[0] == 'Ally':
        x = set()
        for i in range(1,len(k)):
            x.add(k[i])
        Ally.append(x)
    elif k[0] == 'Enemy':
        if k[1] not in enemy:
            enemy[k[1]] = {k[2]}
        else:
            enemy[k[1]].add(k[2])
        if k[2] not in enemy:
            enemy[k[2]] = {k[1]}
        else:
            enemy[k[2]].add(k[1])
    elif k[0] == 'Table':
        print('No')
    k = input().split()
# 1679296, 2022-11-12 10:02:40, P----- (17%)

k = input().split()
Ally = []
enemy = {}
while k[0] != 'End':
    if k[0] == 'Ally':
        x = set()
        for i in range(1,len(k)):
            x.add(k[i])
        Ally.append(x)
    elif k[0] == 'Enemy':
        if k[1] not in enemy:
            enemy[k[1]] = {k[2]}
        else:
            enemy[k[1]].add(k[2])
        if k[2] not in enemy:
            enemy[k[2]] = {k[1]}
        else:
            enemy[k[2]].add(k[1])
    elif k[0] == 'Table':
        print('Okay')
    k = input().split()
# 1680063, 2022-11-12 10:39:55, PPPPPP (100%)

k = input().split()
Ally = []
enemy = {}
while k[0] != 'End':
    if k[0] == 'Ally':
        x = set()
        for i in range(1,len(k)):
            x.add(k[i])
            enemy[k[i]] = set()
        Ally.append(x)
    elif k[0] == 'Enemy':
        if k[1] not in enemy:
            enemy[k[1]] = {k[2]}
        else:
            enemy[k[1]].add(k[2])
        if k[2] not in enemy:
            enemy[k[2]] = {k[1]}
        else:
            enemy[k[2]].add(k[1])
        for e in Ally:
            if k[2] in e:
                enemy[k[1]] |= e
            if k[1] in e:
                enemy[k[2]] |= e
    elif k[0] == 'Table':
        for e in enemy:
            for g in Ally:
                if e in g:
                    for i in g:
                        enemy[e] |= enemy[i]
        x = k[1:]
        found = False
        for i in range(len(x)-1):
            if x[i] not in enemy:
                pass
            elif x[i+1] in enemy[x[i]]:
                print('No')
                found = True
                break
        if found:
            pass
        elif x[0] not in enemy:
            pass
        elif x[-1] not in enemy:
            pass
        elif x[0] in enemy[x[-1]]:
            print('No')
            found = True
        if not found:
            print('Okay')
    k = input().split()

6530165521
# 1680533, 2022-11-12 11:00:17, P---P- (33%)

data = input()
who_in_what = {}
big_versus = []
enemy = {}
ans = []
while data != 'End':
    data = data.split()
    if data[0] == 'Ally':
        ally = data[1:]
        for e in ally:
            who_in_what[e] = ally
        data = input()
        
    elif data[0] == 'Enemy':
        if data[1] in who_in_what:
            if data[2] in who_in_what:
                big_versus.append([who_in_what[data[1]],who_in_what[data[2]]])
            else:
                big_versus.append([who_in_what[data[1]],[data[2]]])
        elif data[2] in who_in_what:
            big_versus.append([data[1],who_in_what[data[2]]])
        else:
            big_versus.append([[data[1]],[data[2]]])
            
        for e in who_in_what:
            if e not in enemy:
                enemy[e] = set()
            for i in range(len(big_versus)):
                if e in big_versus[i][0]:
                    enemy[e] = enemy[e].union(set(big_versus[i][1]))
                elif e in big_versus[i][1]:
                    enemy[e] = enemy[e].union(set(big_versus[i][0]))   
        data = input()
       
    elif data[0] == 'Table':
        order = data[1:]
        order += [order[0]]
        p = 0
        for i in range(len(order)-1):
            if order[i] in enemy:
                if order[i+1] in enemy[order[i]]:
                    ans.append('No')
                    p += 1
                    break
        if p == 0:
            ans.append('Okay')
        data = input()

for e in ans:
    print(e)
        
        

# 1680606, 2022-11-12 11:03:14, P---P- (33%)

data = input()
who_in_what = {}
big_versus = []
enemy = {}
ans = []
while data != 'End':
    data = data.split()
    if data[0] == 'Ally':
        ally = data[1:]
        for e in ally:
            who_in_what[e] = ally
        data = input()
        
    elif data[0] == 'Enemy':
        if data[1] in who_in_what:
            if data[2] in who_in_what:
                big_versus.append([who_in_what[data[1]],who_in_what[data[2]]])
            else:
                big_versus.append([who_in_what[data[1]],[data[2]]])
        elif data[2] in who_in_what:
            big_versus.append([data[1],who_in_what[data[2]]])
        else:
            big_versus.append([[data[1]],[data[2]]])
            
        for e in who_in_what:
            if e not in enemy:
                enemy[e] = set()
            for i in range(len(big_versus)):
                if e in big_versus[i][0]:
                    enemy[e] = enemy[e].union(set(big_versus[i][1]))
                elif e in big_versus[i][1]:
                    enemy[e] = enemy[e].union(set(big_versus[i][0]))   
        data = input()
       
    elif data[0] == 'Table':
        order = data[1:]
        order += [order[0]]
        p = 0
        for i in range(len(order)-1):
            if order[i] in enemy:
                if order[i+1] in enemy[order[i]]:
                    ans.append('No')
                    p += 1
                    break
            else:
                pass
        if p == 0:
            ans.append('Okay')
        data = input()

for e in ans:
    print(e)
        
        

# 1680898, 2022-11-12 11:13:14, PPPPPP (100%)

data = input()
who_in_what = {}
big_versus = []
enemy = {}
ans = []
while data != 'End':
    data = data.split()
    if data[0] == 'Ally':
        ally = data[1:]
        for e in ally:
            who_in_what[e] = ally
        data = input()
        
    elif data[0] == 'Enemy':
        if data[1] not in who_in_what:
            who_in_what[data[1]] = [data[1]]
        if data[2] not in who_in_what:
            who_in_what[data[2]] = [data[2]]
        if data[1] in who_in_what:
            if data[2] in who_in_what:
                big_versus.append([who_in_what[data[1]],who_in_what[data[2]]])
            else:
                big_versus.append([who_in_what[data[1]],[data[2]]])
        elif data[2] in who_in_what:
            big_versus.append([data[1],who_in_what[data[2]]])
        else:
            big_versus.append([[data[1]],[data[2]]])
            
        for e in who_in_what:
            if e not in enemy:
                enemy[e] = set()
            for i in range(len(big_versus)):
                if e in big_versus[i][0]:
                    enemy[e] = enemy[e].union(set(big_versus[i][1]))
                elif e in big_versus[i][1]:
                    enemy[e] = enemy[e].union(set(big_versus[i][0])) 
        data = input()

    elif data[0] == 'Table':
        order = data[1:]
        order += [order[0]]
        p = 0
        for i in range(len(order)-1):
            if order[i] in enemy:
                if order[i+1] in enemy[order[i]]:
                    ans.append('No')
                    p += 1
                    break
            else:
                pass
        if p == 0:
            ans.append('Okay')
        data = input()
for e in ans:
    print(e)
        
        

# 1681096, 2022-11-12 11:18:43, PPPPPP (100%)

data = input()
who_in_what = {}
big_versus = []
enemy = {}
ans = []
while data != 'End':
    
    data = data.split()
    if data[0] == 'Ally':
        ally = data[1:]
        for e in ally:
            who_in_what[e] = ally
        data = input()
        
    elif data[0] == 'Enemy':
        if data[1] not in who_in_what:
            who_in_what[data[1]] = [data[1]]
        if data[2] not in who_in_what:
            who_in_what[data[2]] = [data[2]]
        if data[1] in who_in_what:
            if data[2] in who_in_what:
                big_versus.append([who_in_what[data[1]],who_in_what[data[2]]])
            else:
                big_versus.append([who_in_what[data[1]],[data[2]]])
        elif data[2] in who_in_what:
            big_versus.append([data[1],who_in_what[data[2]]])
        else:
            big_versus.append([[data[1]],[data[2]]])
            
        for e in who_in_what:
            if e not in enemy:
                enemy[e] = set()
            for i in range(len(big_versus)):
                if e in big_versus[i][0]:
                    enemy[e] = enemy[e].union(set(big_versus[i][1]))
                elif e in big_versus[i][1]:
                    enemy[e] = enemy[e].union(set(big_versus[i][0])) 
        data = input()

    elif data[0] == 'Table':
        order = data[1:]
        order += [order[0]]
        p = 0
        for i in range(len(order)-1):
            if order[i] in enemy:
                if order[i+1] in enemy[order[i]]:
                    ans.append('No')
                    p += 1
                    break
                
        if p == 0:
            ans.append('Okay')
        data = input()
        
for e in ans:
    print(e)


6530206621
# 1679611, 2022-11-12 10:20:10, xxxxxx (0%)

t = ""
ally = {}
enemy = {}

while t != "End":
    t = input().split()
    
    if t[0] == "Ally":
        countries = t[1:]
        for coun in countries:
            for couns in countries:
                if coun not in ally:
                    ally[coun] = {couns}
                else:
                    ally[coun].add(couns)
#     print("ally")
#     print(ally)
        
    if t[0] == "Enemy":
#         c2 = t[1]
#         c1 = t[2]
#         
#         if c1 not in enemy:
#             enemy[c1] = {t[1]}
#         if c2 not in enemy:
#             enemy[c2] = {t[2]}
#         
#         if t[1] not in ally:
#             enemy[c1] = t[1]
#         else:
#             for coun in ally[t[1]]:
#                 enemy[c1].add(coun)
#         if t[2] not in ally:
#             enemy[c2] = t[2]
#         else:
#             for coun in ally[t[2]]:
#                 enemy[c2].add(coun)
        c1 = t[2]
        c2 = t[1]
        if c1 not in ally:
            ally[c1] = [c1]
        if c2 not in ally:
            ally[c2] = [c2]
            
        for key in ally:
            if key not in enemy:
                enemy[key] = set()
            
        for team1 in ally[c1]:
#             enemy[team1] = set()
            for team2 in ally[c2]:
                enemy[team1].add(team2)
        for team2 in ally[c2]:
#             enemy[team2] = set()
            for team1 in ally[c1]:
                enemy[team2].add(team1)
#     print("enemy")
#     print(enemy)
        
    valid = True    
    if t[0] == "Table":
        table = t[1:] + [t[1]]
#         print(table)
        
        for i in range(len(table)-1):
            if table[i] in enemy and table[i+1] in enemy:
                if table[i] in enemy[table[i+1]]:
                    valid = False
                    break
                
        if valid == True:
            print("Okay")
        else:
            print("No")
    
    
    

# 1679790, 2022-11-12 10:27:54, xxxxxx (0%)

t = ""
ally = {}
enemy = {}

while t != "End":
    t = input().split()
    
    if t[0] == "Ally":
        countries = t[1:]
        for coun in countries:
            for couns in countries:
                if coun not in ally:
                    ally[coun] = {couns}
                else:
                    ally[coun].add(couns)
#     print("ally")
#     print(ally)
        
    if t[0] == "Enemy":

        c1 = t[2]
        c2 = t[1]
        if c1 not in ally:
            ally[c1] = [c1]
        if c2 not in ally:
            ally[c2] = [c2]
            
        for key in ally:
            if key not in enemy:
                enemy[key] = set()
            
        for team1 in ally[c1]:
#             enemy[team1] = set()
            for team2 in ally[c2]:
                enemy[team1].add(team2)
        for team2 in ally[c2]:
#             enemy[team2] = set()
            for team1 in ally[c1]:
                enemy[team2].add(team1)
#     print("enemy")
#     for key in enemy:
#         print(key + ":" + str(enemy[key]))
        
    valid = True    
    if t[0] == "Table":
        table = t[1:] + [t[1]]
        
        for i in range(len(table)-1):
            if table[i] in enemy and table[i+1] in enemy:
                if table[i] in enemy[table[i+1]]:
                    valid = False
                    break
                
        if valid == True:
            print("Okay")
        else:
            print("No")
    
    
    

# 1679869, 2022-11-12 10:30:44, xxxxxx (0%)

t = ""
ally = {}
enemy = {}

while t != "End":
    t = input().strip().split()
    
    if t[0] == "Ally":
        countries = t[1:]
        for coun in countries:
            for couns in countries:
                if coun not in ally:
                    ally[coun] = {couns}
                else:
                    ally[coun].add(couns)
#     print("ally")
#     print(ally)
        
    if t[0] == "Enemy":

        c1 = t[2]
        c2 = t[1]
        if c1 not in ally:
            ally[c1] = [c1]
        if c2 not in ally:
            ally[c2] = [c2]
            
        for key in ally:
            if key not in enemy:
                enemy[key] = set()
            
        for team1 in ally[c1]:
#             enemy[team1] = set()
            for team2 in ally[c2]:
                enemy[team1].add(team2)
        for team2 in ally[c2]:
#             enemy[team2] = set()
            for team1 in ally[c1]:
                enemy[team2].add(team1)
#     print("enemy")
#     for key in enemy:
#         print(key + ":" + str(enemy[key]))
        
    valid = True    
    if t[0] == "Table":
        table = t[1:] + [t[1]]
        
        for i in range(len(table)-1):
            if table[i] in enemy and table[i+1] in enemy:
                if table[i] in enemy[table[i+1]]:
                    valid = False
                    break
                
        if valid == True:
            print("Okay")
        else:
            print("No")

# 1680016, 2022-11-12 10:37:55, PPPPPP (100%)

t = ""
ally = {}
enemy = {}

while t != "End":
    t = input().strip().split()
    
    if t[0] == "Ally":
        countries = t[1:]
        for coun in countries:
            for couns in countries:
                if coun not in ally:
                    ally[coun] = {couns}
                else:
                    ally[coun].add(couns)
#     print("ally")
#     print(ally)
        
    if t[0] == "Enemy":

        c1 = t[2]
        c2 = t[1]
        if c1 not in ally:
            ally[c1] = [c1]
        if c2 not in ally:
            ally[c2] = [c2]
            
        for key in ally:
            if key not in enemy:
                enemy[key] = set()
            
        for team1 in ally[c1]:
#             enemy[team1] = set()
            for team2 in ally[c2]:
                enemy[team1].add(team2)
        for team2 in ally[c2]:
#             enemy[team2] = set()
            for team1 in ally[c1]:
                enemy[team2].add(team1)
#     print("enemy")
#     for key in enemy:
#         print(key + ":" + str(enemy[key]))
        
    valid = True    
    if t[0] == "Table":
        table = t[1:] + [t[1]]
        
        for i in range(len(table)-1):
            if table[i] in enemy and table[i+1] in enemy:
                if table[i] in enemy[table[i+1]]:
                    valid = False
                    break
                
        if valid == True:
            print("Okay")
        else:
            print("No")
    if t[0] == "End":
        break



6531310321
# 1680638, 2022-11-12 11:04:11, P----- (17%)

chck=[]
enemy=[]
ret=[]
x=input().split()
while True:
    if x[0]=='End': break
    if x[0]=='Ally':
        a=set([i for i in x[1:]])
        chck.append(a)
    if x[0]=='Enemy':
        en=[]
        chckx1=0
        chckx2=0
        for i in chck:
            if x[1] in i:
                en.append(i)
                chckx1+=1
            if x[2] in i:
                en.append(i)
                chckx2+=1
        if chckx1==0 and chckx2==1:
            enemy.append(({x[1]},en[0]))
        elif chckx1==1 and chckx2==0:
            enemy.append((en[0],{x[2]}))
        elif chckx1==1 and chckx2==1:
            enemy.append((en[0],en[1]))
        elif chckx1==0 and chckx2==0:
            enemy.append(({x[1]},{x[2]}))
    if x[0]=='Table':
        okay=0
        for i in range(len(x[1:])-1):
            for j in enemy:
                if x[i+1]in j[0] and x[i+2]in j[1]:
                    ret.append('No')
                    okay+=1
                elif x[i+1]in j[1] and x[i+2] in j[0]:
                    ret.append('No')
                    okay+=1
        for j in enemy:
            if x[0] in j[0] and x[-1] in j[1]:
                ret.append('No')
                okay+=1
            elif x[0] in j[1] and x[-1] in j[0]:
                ret.append('No')
                okay+=1
        if okay==0:
            ret.append('Okay')
    x=input().split()
for i in ret:
    print(i)
# 1680805, 2022-11-12 11:09:52, P-PPP- (67%)

chck=[]
enemy=[]
ret=[]
x=input().split()
while True:
    if x[0]=='End': break
    if x[0]=='Ally':
        a=set([i for i in x[1:]])
        chck.append(a)
    if x[0]=='Enemy':
        en=[]
        chckx1=0
        chckx2=0
        for i in chck:
            if x[1] in i:
                en.append(i)
                chckx1+=1
            if x[2] in i:
                en.append(i)
                chckx2+=1
        if chckx1==0 and chckx2==1:
            enemy.append(({x[1]},en[0]))
        elif chckx1==1 and chckx2==0:
            enemy.append((en[0],{x[2]}))
        elif chckx1==1 and chckx2==1:
            enemy.append((en[0],en[1]))
        elif chckx1==0 and chckx2==0:
            enemy.append(({x[1]},{x[2]}))
    if x[0]=='Table':
        okay=0
        for i in range(len(x[1:])-1):
            for j in enemy:
                if x[i+1]in j[0] and x[i+2]in j[1]:
                    okay+=1
                elif x[i+1]in j[1] and x[i+2] in j[0]:
                    okay+=1
        for j in enemy:
            if x[0] in j[0] and x[-1] in j[1]:
                okay+=1
            elif x[0] in j[1] and x[-1] in j[0]:
                okay+=1
        if okay==0:
            ret.append('Okay')
        else:
            ret.append('No')
    x=input().split()
for i in ret:
    print(i)
# 1680862, 2022-11-12 11:12:00, P-PPP- (67%)

chck=[]
enemy=[]
ret=[]
x=input().split()
while True:
    if x[0]=='End': break
    if x[0]=='Ally':
        a=set([i for i in x[1:]])
        chck.append(a)
    if x[0]=='Enemy':
        en=[]
        chckx1=0
        chckx2=0
        for i in chck:
            if x[1] in i:
                en.append(i)
                chckx1+=1
            if x[2] in i:
                en.append(i)
                chckx2+=1
        if chckx1==0 and chckx2==1:
            enemy.append(({x[1]},en[0]))
        elif chckx1==1 and chckx2==0:
            enemy.append((en[0],{x[2]}))
        elif chckx1==1 and chckx2==1:
            enemy.append((en[0],en[1]))
        elif chckx1==0 and chckx2==0:
            enemy.append(({x[1]},{x[2]}))
    if x[0]=='Table':
        okay=0
        for i in range(len(x[1:])-1):
            for j in enemy:
                if x[i+1]in j[0] and x[i+2]in j[1]:
                    okay+=1
                elif x[i+1]in j[1] and x[i+2] in j[0]:
                    okay+=1
        for j in enemy:
            if x[0] in j[0] and x[-1] in j[1]:
                okay+=1
            elif x[0] in j[1] and x[-1] in j[0]:
                okay+=1
        if okay==0:
            ret.append('Okay')
        elif okay>0:
            ret.append('No')
    x=input().split()
for i in ret:
    print(i)
# 1680982, 2022-11-12 11:16:00, PPPPPP (100%)

chck=[]
enemy=[]
ret=[]
x=input().split()
while True:
    if x[0]=='End': break
    if x[0]=='Ally':
        a=set([i for i in x[1:]])
        chck.append(a)
    if x[0]=='Enemy':
        en=[]
        chckx1=0
        chckx2=0
        for i in chck:
            if x[1] in i:
                en.append(i)
                chckx1+=1
            if x[2] in i:
                en.append(i)
                chckx2+=1
        if chckx1==0 and chckx2==1:
            enemy.append(({x[1]},en[0]))
        elif chckx1==1 and chckx2==0:
            enemy.append((en[0],{x[2]}))
        elif chckx1==1 and chckx2==1:
            enemy.append((en[0],en[1]))
        elif chckx1==0 and chckx2==0:
            enemy.append(({x[1]},{x[2]}))
    if x[0]=='Table':
        okay=0
        for i in range(len(x[1:])-1):
            for j in enemy:
                if x[i+1]in j[0] and x[i+2]in j[1]:
                    okay+=1
                elif x[i+1]in j[1] and x[i+2] in j[0]:
                    okay+=1
        for j in enemy:
            if x[1] in j[0] and x[-1] in j[1]:
                okay+=1
            elif x[1] in j[1] and x[-1] in j[0]:
                okay+=1
        if okay==0:
            ret.append('Okay')
        elif okay>0:
            ret.append('No')
    x=input().split()
for i in ret:
    print(i)

6531330921
# 1680258, 2022-11-12 10:49:46, xxxxxx (0%)

ally = {}
enemy = {}
log = []
x = input().split()
while x != ["End"]:
    countries = [e for e in x[1:]]
    if x[0] == "Ally":
        for e in countries:
            y = countries.copy()
            y.remove(e)
            y = set(y)
            if e in ally:
                ally[e].update(y)
            else:
                ally[e] = y
    elif x[0] == "Enemy":
        for e in countries:
            y = countries.copy()
            y.remove(e)
            y = set(y)
            if e in enemy:
                enemy[e].update(y)
            else:
                enemy[e] = y
    # for key,value in enemy.items():
    #     for c in value:
    #         if c in ally:
    #             enemy[key].update(ally[c])
    # for key,value in ally.items():
    #     for c in value:
    #         if c in enemy:
    #             enemy[key].update(enemy[c])
    if x[0] == "Table":
        count = 0
        for i in range(len(countries)-1):
            if (countries[i-1] in enemy[countries[i]]) or (countries[i+1] in enemy[countries[i]]):
                log.append("No")
                break
            else: count += 1
        if count == len(countries)-1:
            log.append("Okay")
    x = input().split()

for e in log:
    print(e)
# 1680372, 2022-11-12 10:53:54, PP---- (33%)

ally = {}
enemy = {}
log = []
x = input().split()
while x != ["End"]:
    countries = [e for e in x[1:]]
    for e in countries:
        if e not in ally:
            ally[e] = set()
        if e not in enemy:
            enemy[e] = set()
    if x[0] == "Ally":
        for e in countries:
            y = countries.copy()
            y.remove(e)
            y = set(y)
            if e in ally:
                ally[e].update(y)
            else:
                ally[e] = y
    elif x[0] == "Enemy":
        for e in countries:
            y = countries.copy()
            y.remove(e)
            y = set(y)
            if e in enemy:
                enemy[e].update(y)
            else:
                enemy[e] = y
    # for key,value in enemy.items():
    #     for c in value:
    #         if c in ally:
    #             enemy[key].update(ally[c])
    # for key,value in ally.items():
    #     for c in value:
    #         if c in enemy:
    #             enemy[key].update(enemy[c])
    if x[0] == "Table":
        count = 0
        for i in range(len(countries)-1):
            if (countries[i-1] in enemy[countries[i]]) or (countries[i+1] in enemy[countries[i]]):
                log.append("No")
                break
            else: count += 1
        if count == len(countries)-1:
            log.append("Okay")
    x = input().split()

for e in log:
    print(e)
# 1680580, 2022-11-12 11:02:23, PPTTxx (33%)

ally = {}
enemy = {}
log = []
x = input().split()
while x != ["End"]:
    countries = [e for e in x[1:]]
    for e in countries:
        if e not in ally:
            ally[e] = []
        if e not in enemy:
            enemy[e] = []
    if x[0] == "Ally":
        for e in countries:
            y = countries.copy()
            y.remove(e)
            ally[e] += y
    elif x[0] == "Enemy":
        for e in countries:
            y = countries.copy()
            y.remove(e)
            enemy[e] += y
    for key,value in enemy.items():
        for i in range(len(value)):
            enemy[key] += ally[value[i]]
    for key,value in ally.items():
        for i in range(len(value)):
            enemy[key] += enemy[value[i]]
    if x[0] == "Table":
        count = 0
        
        for i in range(len(countries)-1):
            if (countries[i-1] in enemy[countries[i]]) or (countries[i+1] in enemy[countries[i]]):
                log.append("No")
                break
            else: count += 1
        if count == len(countries)-1:
            log.append("Okay")
    x = input().split()

for e in log:
    print(e)
# 1680670, 2022-11-12 11:05:00, PPPPPP (100%)

ally = {}
enemy = {}
log = []
x = input().split()
while x != ["End"]:
    countries = [e for e in x[1:]]
    for e in countries:
        if e not in ally:
            ally[e] = []
        if e not in enemy:
            enemy[e] = []
    if x[0] == "Ally":
        for e in countries:
            y = countries.copy()
            y.remove(e)
            ally[e] += y
    elif x[0] == "Enemy":
        for e in countries:
            y = countries.copy()
            y.remove(e)
            enemy[e] += y
    for key,value in enemy.items():
        for i in range(len(value)):
            enemy[key] += ally[value[i]]
    for key,value in ally.items():
        for i in range(len(value)):
            enemy[key] += enemy[value[i]]
    for key in enemy:
        enemy[key] = set(enemy[key])
        enemy[key] = list(enemy[key])
    for key in ally:
        ally[key] = set(ally[key])
        ally[key] = list(ally[key])
    if x[0] == "Table":
        count = 0
        
        for i in range(len(countries)-1):
            if (countries[i-1] in enemy[countries[i]]) or (countries[i+1] in enemy[countries[i]]):
                log.append("No")
                break
            else: count += 1
        if count == len(countries)-1:
            log.append("Okay")
    x = input().split()

for e in log:
    print(e)

6531344721
# 1679817, 2022-11-12 10:29:04, P----- (17%)

da = []
t = input()
d = {}
while t != "End":
    t1 = t.split()
    if t1[0] == "Ally":
        da.append(t1[1:])
    elif t1[0] == "Enemy":
        e1, e2 = t1[1:]
        ae1 = [e1]
        ae2 = [e2]
        for a in da:
            if e1 in a:
                ae1 = a
            if e2 in a:
                ae2 = a
        print(ae1, ae2)
        d[tuple(ae1)] = ae2
        d[tuple(ae2)] = ae1
    elif t1[0] == "Table":
        t2 = t1[1:]
        dt = set()
        for i in range(1, len(t2)-1):
            for k in d:
                if t2[i] in k and (t2[i-1] in d[k] or t2[i+1] in d[k]):
                    dt.add(t2[i])
        for k in d:
            if t2[0] in k and (t2[-1] in d[k] or t2[1] in d[k]):
                dt.add(t2[0])
            if t2[-1] in k and (t2[-2] in d[k] or t2[0] in d[k]):
                dt.add(t2[0])
        if dt == set():
            print("Okay")
        else:
            print("No")
    t = input()
    if t == "End":
        break
# 1679985, 2022-11-12 10:36:29, P----- (17%)

da = []

d = {}
while True:
    t = input()
    t1 = t.split()
    if t1[0] == "Ally":
        da.append(t1[1:])
    elif t1[0] == "Enemy":
        e1, e2 = t1[1:]
        ae1 = [e1]
        ae2 = [e2]
        for a in da:
            if e1 in a:
                ae1 = a
            if e2 in a:
                ae2 = a
        print(ae1, ae2)
        d[tuple(ae1)] = ae2
        d[tuple(ae2)] = ae1
    elif t1[0] == "Table":
        t2 = t1[1:]
        dt = set()
        for i in range(1, len(t2)-1):
            for k in d:
                if t2[i] in k and (t2[i-1] in d[k] or t2[i+1] in d[k]):
                    dt.add(t2[i])
        for k in d:
            if t2[0] in k and (t2[-1] in d[k] or t2[1] in d[k]):
                dt.add(t2[0])
            if t2[-1] in k and (t2[-2] in d[k] or t2[0] in d[k]):
                dt.add(t2[0])
        if dt == set():
            print("Okay")
        else:
            print("No")
    if t == "End":
        break
# 1679990, 2022-11-12 10:36:56, PP-PP- (67%)

da = []

d = {}
while True:
    t = input()
    t1 = t.split()
    if t1[0] == "Ally":
        da.append(t1[1:])
    elif t1[0] == "Enemy":
        e1, e2 = t1[1:]
        ae1 = [e1]
        ae2 = [e2]
        for a in da:
            if e1 in a:
                ae1 = a
            if e2 in a:
                ae2 = a
        d[tuple(ae1)] = ae2
        d[tuple(ae2)] = ae1
    elif t1[0] == "Table":
        t2 = t1[1:]
        dt = set()
        for i in range(1, len(t2)-1):
            for k in d:
                if t2[i] in k and (t2[i-1] in d[k] or t2[i+1] in d[k]):
                    dt.add(t2[i])
        for k in d:
            if t2[0] in k and (t2[-1] in d[k] or t2[1] in d[k]):
                dt.add(t2[0])
            if t2[-1] in k and (t2[-2] in d[k] or t2[0] in d[k]):
                dt.add(t2[0])
        if dt == set():
            print("Okay")
        else:
            print("No")
    if t == "End":
        break
# 1680142, 2022-11-12 10:43:23, PPPPPP (100%)

da = []
d = {}
while True:
    t = input()
    t1 = t.split()
    if t1[0] == "Ally":
        da.append(t1[1:])
    elif t1[0] == "Enemy":
        e1, e2 = t1[1:]
        ae1 = [e1]
        ae2 = [e2]
        for a in da:
            if e1 in a:
                ae1 = a
            if e2 in a:
                ae2 = a
        if tuple(ae1) not in d:
            d[tuple(ae1)] = []
        if tuple(ae2) not in d:
            d[tuple(ae2)] = []
        d[tuple(ae1)] += ae2
        d[tuple(ae2)] += ae1
    elif t1[0] == "Table":
        t2 = t1[1:]
        dt = set()
        for i in range(1, len(t2)-1):
            for k in d:
                if t2[i] in k and (t2[i-1] in d[k] or t2[i+1] in d[k]):
                    dt.add(t2[i])
        for k in d:
            if t2[0] in k and (t2[-1] in d[k] or t2[1] in d[k]):
                dt.add(t2[0])
            if t2[-1] in k and (t2[-2] in d[k] or t2[0] in d[k]):
                dt.add(t2[0])
        if dt == set():
            print("Okay")
        else:
            print("No")
    if t == "End":
        break

6532043021
# 1679827, 2022-11-12 10:29:26, xPPPPx (67%)


ally = []
sit = {}
mark = []
ch2=False
while(1):
    s = input().split()
    if(s[0]=='End'):
        break
    if(s[0]=='Ally'):
        temp=set()
        ch=False
        for e in s[1::]:
            temp.add(e)
        for e in s[1::]:
            for i in range(len(ally)):
                if(e in ally[i]):
                    ally[i] = ally[i]|temp
                    ch=True
        if(not ch):
            ally.append(temp)

    if(s[0]=='Enemy'):
        if not ch2:
            cou = len(ally)
            ch2 = True
        marka = False
        markb = False
        for i in range(len(ally)):
            if(s[1] in ally[i]):
                a = i
                marka =True
            if(s[2] in ally[i]):
                b = i
                markb = True
        if(not marka):
            ally.append(set())
            ally[-1].add(s[1])
            a = cou
            cou+=1
        if(not markb):
            ally.append(set())
            ally[-1].add(s[2])
            b = cou
            cou+=1
        if(not a in mark):
            sit[a] = []
            mark.append(a)
        if(not b in mark):
            sit[b] = []
            mark.append(b)
        sit[a].append(b)
        sit[b].append(a)
        #print(sit)

    if(s[0]=='Table'):
        #print(ally)
        s = s[1::]
        n = len(s)
        ch = False
        for i in range(n):
            if(ch):
                break
            markpos = False
            for j in range(len(ally)):
                if(s[i] in ally[j]):
                    pos = j
                    markpos = True
            if not markpos:
                continue
            for e in sit[pos]:
                if(e >= len(ally)):
                    continue
                if(s[(i-1+n)%n] in ally[e] or s[(i+1)%n] in ally[e]):
                    #print(s[i])
                    print('No')
                    ch = True
                    break
        if(not ch):
            print('Okay')
            

# 1679887, 2022-11-12 10:31:21, xPPPPx (67%)


ally = []
sit = {}
mark = []
ch2=False
while(1):
    s = input().split()
    if(s[0]=='End'):
        break
    if(s[0]=='Ally'):
        temp=set()
        ch=False
        for e in s[1::]:
            temp.add(e)
        for e in s[1::]:
            for i in range(len(ally)):
                if(e in ally[i]):
                    ally[i] = ally[i]|temp
                    ch=True
        if(not ch):
            ally.append(temp)

    if(s[0]=='Enemy'):
        if not ch2:
            cou = len(ally)
            ch2 = True
        marka = False
        markb = False
        for i in range(len(ally)):
            if(s[1] in ally[i]):
                a = i
                marka =True
            if(s[2] in ally[i]):
                b = i
                markb = True
        if(not marka):
            ally.append(set())
            ally[-1].add(s[1])
            a = cou
            cou+=1
        if(not markb):
            ally.append(set())
            ally[-1].add(s[2])
            b = cou
            cou+=1
        if(not a in mark):
            sit[a] = []
            mark.append(a)
        if(not b in mark):
            sit[b] = []
            mark.append(b)
        sit[a].append(b)
        sit[b].append(a)
        #print(sit)

    if(s[0]=='Table'):
        #print(ally)
        s = s[1::]
        n = len(s)
        ch = False
        for i in range(n):
            if(ch):
                break
            markpos = False
            for j in range(len(ally)):
                if(s[i] in ally[j]):
                    pos = j
                    markpos = True
            if not markpos:
                continue
            for e in sit[pos]:
                if(s[(i-1+n)%n] in ally[e] or s[(i+1)%n] in ally[e]):
                    #print(s[i])
                    print('No')
                    ch = True
                    break
        if(not ch):
            print('Okay')
            

# 1679955, 2022-11-12 10:35:04, PPPPPx (83%)


ally = []
sit = {}
mark = []
ch2=False
while(1):
    s = input().split()
    if(s[0]=='End'):
        break
    if(s[0]=='Ally'):
        temp=set()
        ch=False
        for e in s[1::]:
            temp.add(e)
        for e in s[1::]:
            for i in range(len(ally)):
                if(e in ally[i]):
                    ally[i] = ally[i]|temp
                    ch=True
        if(not ch):
            ally.append(temp)

    if(s[0]=='Enemy'):
        if not ch2:
            cou = len(ally)
            ch2 = True
        marka = False
        markb = False
        for i in range(len(ally)):
            if(s[1] in ally[i]):
                a = i
                marka =True
            if(s[2] in ally[i]):
                b = i
                markb = True
        if(not marka):
            ally.append(set())
            ally[-1].add(s[1])
            a = cou
            cou+=1
        if(not markb):
            ally.append(set())
            ally[-1].add(s[2])
            b = cou
            cou+=1
        if(not a in mark):
            sit[a] = []
            mark.append(a)
        if(not b in mark):
            sit[b] = []
            mark.append(b)
        sit[a].append(b)
        sit[b].append(a)
        #print(sit)

    if(s[0]=='Table'):
        #print(ally)
        s = s[1::]
        n = len(s)
        ch = False
        for i in range(n):
            if(ch):
                break
            markpos = False
            for j in range(len(ally)):
                if(s[i] in ally[j]):
                    pos = j
                    markpos = True
            if not markpos:
                continue
            if(len(sit)==0):
                break
            for e in sit[pos]:
                if(s[(i-1+n)%n] in ally[e] or s[(i+1)%n] in ally[e]):
                    #print(s[i])
                    print('No')
                    ch = True
                    break
        if(not ch):
            print('Okay')
            

# 1679995, 2022-11-12 10:37:02, PPPPPP (100%)


ally = []
sit = {}
mark = []
markdic = []
ch2=False
while(1):
    s = input().split()
    if(s[0]=='End'):
        break
    if(s[0]=='Ally'):
        temp=set()
        ch=False
        for e in s[1::]:
            temp.add(e)
        for e in s[1::]:
            for i in range(len(ally)):
                if(e in ally[i]):
                    ally[i] = ally[i]|temp
                    ch=True
        if(not ch):
            ally.append(temp)

    if(s[0]=='Enemy'):
        if not ch2:
            cou = len(ally)
            ch2 = True
        marka = False
        markb = False
        for i in range(len(ally)):
            if(s[1] in ally[i]):
                a = i
                marka =True
            if(s[2] in ally[i]):
                b = i
                markb = True
        if(not marka):
            ally.append(set())
            ally[-1].add(s[1])
            a = cou
            cou+=1
        if(not markb):
            ally.append(set())
            ally[-1].add(s[2])
            b = cou
            cou+=1
        if(not a in mark):
            sit[a] = []
            mark.append(a)
        if(not b in mark):
            sit[b] = []
            mark.append(b)
        sit[a].append(b)
        sit[b].append(a)
        markdic.append(a)
        markdic.append(b)
        #print(sit)

    if(s[0]=='Table'):
        #print(ally)
        s = s[1::]
        n = len(s)
        ch = False
        for i in range(n):
            if(ch):
                break
            markpos = False
            for j in range(len(ally)):
                if(s[i] in ally[j]):
                    pos = j
                    markpos = True
            if not markpos:
                continue
            if(not pos in markdic):
                break
            for e in sit[pos]:
                if(s[(i-1+n)%n] in ally[e] or s[(i+1)%n] in ally[e]):
                    #print(s[i])
                    print('No')
                    ch = True
                    break
        if(not ch):
            print('Okay')
            


6532068721
# 1679160, 2022-11-12 09:55:41, P----- (17%)

# Map Country to its alliance including themself
alliances = {}


def create_alliance(countries):
    for country in countries:
        alliances[country] = countries


# Map Country to its direct enemy
enemies = {}


def _create_enemy(c1, c2):
    enemies[c1] = enemies.get(c1, set())
    enemies[c1] = enemies[c1].union({c2})


def create_enemy(countries):
    _create_enemy(countries[0], countries[1])
    _create_enemy(countries[1], countries[0])

# Check if c1 and c2 is okay to sit


def is_okay(c1, c2):
    # Is alliance of enemy
    for enemy in enemies.get(c1, set()):
        if c2 in alliances.get(enemy, []):
            return False

    # Is enemy of alliance
    for alliance in alliances.get(c1, set()):
        if c2 in enemies.get(alliance, set()):
            return False

    return True


def _table(countries):
    for i in range(len(countries) - 1):
        if not is_okay(countries[i], countries[i + 1]):
            return False

        if not is_okay(countries[i + 1], countries[i]):
            return False

    if not is_okay(countries[0], countries[-1]):
        return False

    if not is_okay(countries[-1], countries[0]):
        return False

    return True


def table(countries):
    if _table(countries):
        print("Okay")
    else:
        print("No")


while True:
    tokens = input().strip().split(" ")
    command = tokens[0]

    if command == "Ally":
        create_alliance(tokens[1:])
    elif command == "Enemy":
        create_enemy(tokens[1:])
    elif command == "Table":
        table(tokens[1:])
    else:
        break

# 1679379, 2022-11-12 10:07:26, P---PP (50%)

# Map Country to its alliance including themself
alliances = {}


def create_alliance(countries):
    for country in countries:
        alliances[country] = countries


# Map Country to its direct enemy
enemies = {}


def _create_enemy(c1, c2):
    enemies[c1] = enemies.get(c1, set())
    enemies[c1] = enemies[c1].union({c2})


def create_enemy(countries):
    _create_enemy(countries[0], countries[1])
    _create_enemy(countries[1], countries[0])

# Check if c1 and c2 is okay to sit


def is_okay(c1, c2):
    # Is alliance of enemy
    for enemy in enemies.get(c1, set()):
        if c2 in alliances.get(enemy, []):
            return False

    # Is enemy of alliance
    for alliance in alliances.get(c1, []):
        for alliances_enemy in enemies.get(alliance, set()):
            if c2 in alliances.get(alliances_enemy, []):
                return False

    return True


def _table(countries):
    for i in range(len(countries) - 1):
        if not is_okay(countries[i], countries[i + 1]):
            return False

        if not is_okay(countries[i + 1], countries[i]):
            return False

    if not is_okay(countries[0], countries[-1]):
        return False

    if not is_okay(countries[-1], countries[0]):
        return False

    return True


def table(countries):
    if _table(countries):
        print("Okay")
    else:
        print("No")


while True:
    tokens = input().strip().split(" ")
    command = tokens[0]

    if command == "Ally":
        create_alliance(tokens[1:])
    elif command == "Enemy":
        create_enemy(tokens[1:])
    elif command == "Table":
        table(tokens[1:])
    else:
        break

# 1679435, 2022-11-12 10:10:43, P---PP (50%)

# Map Country to its alliance including themself
alliances = {}


def create_alliance(countries):
    for country in countries:
        alliances[country] = countries


# Map Country to its direct enemy
enemies = {}


def _create_enemy(c1, c2):
    enemies[c1] = enemies.get(c1, set())
    enemies[c1] = enemies[c1].union({c2})


def create_enemy(countries):
    _create_enemy(countries[0], countries[1])
    _create_enemy(countries[1], countries[0])

# Check if c1 and c2 is okay to sit


def is_okay(c1, c2):
    # Is alliance of enemy
    for enemy in enemies.get(c1, set()):
        if c2 in alliances.get(enemy, []):
            return False

    # Is enemy of alliance
    for alliance in alliances.get(c1, [c1]):
        for alliances_enemy in enemies.get(alliance, set()):
            if c2 in alliances.get(alliances_enemy, []):
                return False

    return True


def _table(countries):
    for i in range(len(countries) - 1):
        if not is_okay(countries[i], countries[i + 1]):
            return False

        if not is_okay(countries[i + 1], countries[i]):
            return False

    if not is_okay(countries[0], countries[-1]):
        return False

    if not is_okay(countries[-1], countries[0]):
        return False

    return True


def table(countries):
    if _table(countries):
        print("Okay")
    else:
        print("No")


while True:
    tokens = input().strip().split(" ")
    command = tokens[0]

    if command == "Ally":
        create_alliance(tokens[1:])
    elif command == "Enemy":
        create_enemy(tokens[1:])
    elif command == "Table":
        table(tokens[1:])
    else:
        break

# 1679459, 2022-11-12 10:11:46, PPPPPP (100%)

# Map Country to its alliance including themself
alliances = {}


def create_alliance(countries):
    for country in countries:
        alliances[country] = countries


# Map Country to its direct enemy
enemies = {}


def _create_enemy(c1, c2):
    enemies[c1] = enemies.get(c1, set())
    enemies[c1] = enemies[c1].union({c2})


def create_enemy(countries):
    _create_enemy(countries[0], countries[1])
    _create_enemy(countries[1], countries[0])

# Check if c1 and c2 is okay to sit


def is_okay(c1, c2):
    # Is alliance of enemy
    for enemy in enemies.get(c1, set()):
        if c2 in alliances.get(enemy, [enemy]):
            return False

    # Is enemy of alliance
    for alliance in alliances.get(c1, [c1]):
        for alliances_enemy in enemies.get(alliance, set()):
            if c2 in alliances.get(alliances_enemy, [alliances_enemy]):
                return False

    return True


def _table(countries):
    for i in range(len(countries) - 1):
        if not is_okay(countries[i], countries[i + 1]):
            return False

        if not is_okay(countries[i + 1], countries[i]):
            return False

    if not is_okay(countries[0], countries[-1]):
        return False

    if not is_okay(countries[-1], countries[0]):
        return False

    return True


def table(countries):
    if _table(countries):
        print("Okay")
    else:
        print("No")


while True:
    tokens = input().strip().split(" ")
    command = tokens[0]

    if command == "Ally":
        create_alliance(tokens[1:])
    elif command == "Enemy":
        create_enemy(tokens[1:])
    elif command == "Table":
        table(tokens[1:])
    else:
        break


6532136721
# 1678976, 2022-11-12 09:45:59, xxxxxx (0%)


while True:
    s = input().split()
    if s=='End': break
    if s[0] == 'Ally':
        ally(s[1:])
    elif s[0] == 'Enemy':
        assert len(s)==3
        enemy(s[1], s[2])

# 1678998, 2022-11-12 09:47:02, ------ (0%)

def ally(l):
    return
def enemy(a, b):
    return

while True:
    s = input().split()
    if s[0]=='End': break
    if s[0] == 'Ally':
        ally(s[1:])
    elif s[0] == 'Enemy':
        assert len(s)==3
        enemy(s[1], s[2])

# 1679609, 2022-11-12 10:20:08, PPPPPP (100%)

al = []
def ally(l):
    for country in l:
        for i in range(len(al)):
            if country in al[i]:
                al[i] = al[i].union(set(l))
                return
    al.append(set(l))
    return

d = dict()
def enemy(a, b):
    ally([a])
    ally([b])
    if a not in d:
        d[a] = set()
    if b not in d:
        d[b] = set()
    d[a].add(b)
    d[b].add(a)
    return

def now_team(a):
    for i in range(len(al)):
        if a in al[i]:
            return i
    return -1

def table(l):
    for i in range(len(l)):
        a,b = l[i], l[i-1]
        ta,tb = now_team(a), now_team(b)


        if ta == -1 or tb == -1: # no team
            continue
        if ta == tb: #same team
            continue
        for now, enemy_list in d.items():
            if now_team(now) == ta: # same team with a
                for c in enemy_list:
                    if now_team(c) == tb:
                        return False
            if now_team(now) == tb: # same team with a
                for c in enemy_list:
                    if now_team(c) == ta:
                        return False

    return True


while True:
    s = input().split()
    if s[0]=='End': break
    if s[0] == 'Ally':
        ally(s[1:])
    elif s[0] == 'Enemy':
        enemy(s[1], s[2])
    elif s[0] == 'Table':
        print('Okay' if table(s[1:]) else 'No')

# 1679757, 2022-11-12 10:26:12, PPPPPP (100%)

al = []
def ally(l):
    for country in l:
        for i in range(len(al)):
            if country in al[i]:
                al[i] = al[i].union(set(l))
                return
    al.append(set(l))
    return

def now_team(a):
    for i in range(len(al)):
        if a in al[i]:
            return i
    return -1

enemy_matrix = [ [0 for j in range(100)] for i in range(100) ]
def enemy(a, b):
    ally([a])
    ally([b])
    ia, ib = now_team(a), now_team(b)
    enemy_matrix[ia][ib] = enemy_matrix[ib][ia] = 1
    return


def table(l):
    for i in range(len(l)):
        a,b = l[i], l[i-1]
        ta,tb = now_team(a), now_team(b)
        if ta == -1 or tb == -1: # no team
            continue
        if enemy_matrix[ta][tb]:
            return False
    return True


while True:
    s = input().split()
    if s[0]=='End': break
    if s[0] == 'Ally':
        ally(s[1:])
    elif s[0] == 'Enemy':
        enemy(s[1], s[2])
    elif s[0] == 'Table':
        print('Okay' if table(s[1:]) else 'No')


6532152721
# 1679436, 2022-11-12 10:10:52, xx--xx (0%)

ally = dict()
enemy = dict()

s = input().split()
while (s[0] == "Ally"):
    for e in s[1:]:
        if e not in ally:
            ally[e] = set()
        ally[e].update(set(s[1:]))
    s = input().split()


while (s[0] == "Enemy"):
    for e in s[1:]:
        if e not in enemy:
            enemy[e] = set()
        enemy[e].update(set(s[1:]) - set([e]))
    s = input().split()

while (s[0] != "End"):
    s = s[1:]
    ok = True
    for e in s[1:]:
        if e not in ally:
            ally[e] = set()
        if e not in enemy:
            enemy[e] = set()
    for i in range(len(s)):
        left = s[i-1]
        right = s[i]
        if ally[left] & enemy[right] or ally[right] & enemy[left]:
            ok = False
            break
            
    if ok:
        print("Okay")
    else:
        print("No")
    s = input().split()

# 1679480, 2022-11-12 10:12:46, P----- (17%)

ally = dict()
enemy = dict()

s = input().split()
while (s[0] == "Ally"):
    for e in s[1:]:
        if e not in ally:
            ally[e] = set()
        ally[e].update(set(s[1:]))
    s = input().split()


while (s[0] == "Enemy"):
    for e in s[1:]:
        if e not in enemy:
            enemy[e] = set()
        enemy[e].update(set(s[1:]) - set([e]))
    s = input().split()

while (s[0] != "End"):
    s = s[1:]
    ok = True
    for e in s:
        if e not in ally:
            ally[e] = set()
        if e not in enemy:
            enemy[e] = set()
    for i in range(len(s)):
        left = s[i-1]
        right = s[i]
        if ally[left] & enemy[right] or ally[right] & enemy[left]:
            ok = False
            break
            
    if ok:
        print("Okay")
    else:
        print("No")
    s = input().split()
# 1680368, 2022-11-12 10:53:50, PPPP-- (67%)

ally = dict()
enemy = dict()

s = input().split()
while (s[0] == "Ally"):
    all_ally = set(s[1:])
    for e in s[1:]:
        if e in ally:
            all_ally.update(ally[e])
        else:
            ally[e] = set()
    tmp = set()
    while (tmp != all_ally):
        tmp = set([x for x in all_ally])
        for e in tmp:
            all_ally.update(ally[e])
    for e in all_ally:
        ally[e].update(all_ally)
    s = input().split()


while (s[0] == "Enemy"):
    for e in s[1:]:
        if e not in enemy:
            enemy[e] = set()
        if e not in ally:
            ally[e] = set([e])
    enemy[s[1]].update([s[2]])
    enemy[s[1]].update(ally[s[2]])
    enemy[s[2]].update([s[1]])
    enemy[s[2]].update(ally[s[1]])
    s = input().split()

while (s[0] != "End"):
    s = s[1:]
    ok = True
    for e in s:
        if e not in ally:
            ally[e] = set()
        if e not in enemy:
            enemy[e] = set()
    for i in range(len(s)):
        left = s[i-1]
        right = s[i]
        if ally[left] & enemy[right] or ally[right] & enemy[left]:
            ok = False
            break
            
    if ok:
        print("Okay")
    else:
        print("No")
    s = input().split()

# 1680477, 2022-11-12 10:58:09, PPPPPP (100%)

ally = dict()
enemy = dict()

s = input().split()
while (s[0] == "Ally"):
    all_ally = set(s[1:])
    for e in s[1:]:
        if e in ally:
            all_ally.update(ally[e])
        else:
            ally[e] = set()
        if e not in enemy:
            enemy[e] = set()
    tmp = set()
    while (tmp != all_ally):
        tmp = set([x for x in all_ally])
        for e in tmp:
            all_ally.update(ally[e])
    for e in all_ally:
        ally[e].update(all_ally)
    s = input().split()


while (s[0] == "Enemy"):
    for e in s[1:]:
        if e not in enemy:
            enemy[e] = set()
        if e not in ally:
            ally[e] = set([e])
    enemy[s[1]].update([s[2]])
    enemy[s[1]].update(ally[s[2]])
    for e in ally[s[2]]:
        enemy[e].add(s[1])
    enemy[s[2]].update([s[1]])
    enemy[s[2]].update(ally[s[1]])
    for e in ally[s[1]]:
        enemy[e].add(s[2])
    s = input().split()

while (s[0] != "End"):
    s = s[1:]
    ok = True
    for e in s:
        if e not in ally:
            ally[e] = set()
        if e not in enemy:
            enemy[e] = set()
    for i in range(len(s)):
        left = s[i-1]
        right = s[i]
        if ally[left] & enemy[right] or ally[right] & enemy[left]:
            ok = False
            break
            
    if ok:
        print("Okay")
    else:
        print("No")
    s = input().split()


6532187721
# 1678819, 2022-11-12 09:36:26, xxxxxx (0%)

c = 0
T = {}
E = []
while True:
    inp = input().split()
    if inp[0]=='Ally':
        for x in inp[1:]: T[x]=c
        c+=1
    elif inp[0]=='Enemy':
        if inp[1] not in T or inp[2] not in T: continue
        E.append((T[inp[1]],T[inp[2]]))
        E.append((T[inp[2]],T[inp[1]]))
    else:
        p = True
        for i in range(2,len(inp)):
            if inp[i-1] not in T or inp[i] not in T: continue
            if (T[inp[i-1]],T[inp[i]]) in E:
                p = False
                break
        if p: print('Okay')
        else: print('No')
# 1678828, 2022-11-12 09:36:51, P---P- (33%)

c = 0
T = {}
E = []
while True:
    inp = input().split()
    if inp[0]=='End': break
    if inp[0]=='Ally':
        for x in inp[1:]: T[x]=c
        c+=1
    elif inp[0]=='Enemy':
        if inp[1] not in T or inp[2] not in T: continue
        E.append((T[inp[1]],T[inp[2]]))
        E.append((T[inp[2]],T[inp[1]]))
    else:
        p = True
        for i in range(2,len(inp)):
            if inp[i-1] not in T or inp[i] not in T: continue
            if (T[inp[i-1]],T[inp[i]]) in E:
                p = False
                break
        if p: print('Okay')
        else: print('No')
# 1678936, 2022-11-12 09:43:32, P-PPP- (67%)

c = 0
T = {}
E = []
while True:
    inp = input().split()
    if inp[0]=='End': break
    if inp[0]=='Ally':
        for x in inp[1:]: T[x]=c
        c+=1
    elif inp[0]=='Enemy':
        if inp[1] not in T: T[inp[1]]=c;c+=1
        if inp[2] not in T: T[inp[2]]=c;c+=1
        E.append((T[inp[1]],T[inp[2]]))
        E.append((T[inp[2]],T[inp[1]]))
    else:
        p = True
        for i in range(2,len(inp)):
            if inp[i-1] not in T or inp[i] not in T: continue
            if (T[inp[i-1]],T[inp[i]]) in E:
                p = False
                break
        if p: print('Okay')
        else: print('No')
# 1679040, 2022-11-12 09:48:58, PPPPPP (100%)

c = 0
T = {}
E = []
while True:
    inp = input().split()
    if inp[0]=='End': break
    if inp[0]=='Ally':
        for x in inp[1:]: T[x]=c
        c+=1
    elif inp[0]=='Enemy':
        if inp[1] not in T: T[inp[1]]=c;c+=1
        if inp[2] not in T: T[inp[2]]=c;c+=1
        E.append((T[inp[1]],T[inp[2]]))
        E.append((T[inp[2]],T[inp[1]]))
    else:
        p = True
        inp.append(inp[1])
        for i in range(2,len(inp)):
            if inp[i-1] not in T or inp[i] not in T: continue
            if (T[inp[i-1]],T[inp[i]]) in E:
                p = False
                break
        
        if p: print('Okay')
        else: print('No')

6431025421
# 1680279, 2022-11-12 10:50:26, PPPPPx (83%)

qwer = []
asdf = {}
jklh = []
ch2=False
while(1):
    s = input().split()
    if(s[0]=='End'):
        break
    if(s[0]=='Ally'):
        temp=set()
        ch=False
        for e in s[1::]:
            temp.add(e)
        for e in s[1::]:
            for i in range(len(qwer)):
                if(e in qwer[i]):
                    qwer[i] = qwer[i]|temp
                    ch=True
        if(not ch):
            qwer.append(temp)

    if(s[0]=='Enemy'):
        if not ch2:
            cou = len(qwer)
            ch2 = True
        jklha = False
        jklhb = False
        for i in range(len(qwer)):
            if(s[1] in qwer[i]):
                a = i
                jklha =True
            if(s[2] in qwer[i]):
                b = i
                jklhb = True
        if(not jklha):
            qwer.append(set())
            qwer[-1].add(s[1])
            a = cou
            cou+=1
        if(not jklhb):
            qwer.append(set())
            qwer[-1].add(s[2])
            b = cou
            cou+=1
        if(not a in jklh):
            asdf[a] = []
            jklh.append(a)
        if(not b in jklh):
            asdf[b] = []
            jklh.append(b)
        asdf[a].append(b)
        asdf[b].append(a)
        #print(asdf)

    if(s[0]=='Table'):
        #print(ally)
        s = s[1::]
        n = len(s)
        ch = False
        for i in range(n):
            if(ch):
                break
            jklhpos = False
            for j in range(len(qwer)):
                if(s[i] in qwer[j]):
                    pos = j
                    jklhpos = True
            if not jklhpos:
                continue
            if(len(asdf)==0):
                break
            for e in asdf[pos]:
                if(s[(i-1+n)%n] in qwer[e] or s[(i+1)%n] in qwer[e]):
                    #print(s[i])
                    print('No')
                    ch = True
                    break
        if(not ch):
            print('Okay')
# 1680676, 2022-11-12 11:05:19, PPPPPx (83%)

qwer = []
asdf = {}
jklh = []
ch2=False
while(1):
    s = input().split()
    if(s[0]=='End'):
        break
    if(s[0]=='Ally'):
        temp=set()
        ch=False
        for e in s[1::]:
            temp.add(e)
        for e in s[1::]:
            for i in range(len(qwer)):
                if(e in qwer[i]):
                    qwer[i] = qwer[i]|temp
                    ch=True
        if(not ch):
            qwer.append(temp)

    if(s[0]=='Enemy'):
        if not ch2:
            cou = len(qwer)
            ch2 = True
        jklha = False
        jklhb = False
        for i in range(len(qwer)):
            if(s[1] in qwer[i]):
                a = i
                jklha =True
            if(s[2] in qwer[i]):
                b = i
                jklhb = True
        if(not jklha):
            qwer.append(set())
            qwer[-1].add(s[1])
            a = cou
            cou+=1
        if(not jklhb):
            qwer.append(set())
            qwer[-1].add(s[2])
            b = cou
            cou+=1
        if(not a in jklh):
            asdf[a] = []
            jklh.append(a)
        if(not b in jklh):
            asdf[b] = []
            jklh.append(b)
        asdf[a].append(b)
        asdf[b].append(a)
        #print(asdf)

    if(s[0]=='Table'):
        #print(ally)
        s = s[1::]
        n = len(s)
        ch = False
        for i in range(n):
            if(ch):
                break
            jklhpos = False
            for j in range(len(qwer)):
                if(s[i] in qwer[j]):
                    pos = j
                    jklhpos = True
            if not jklhpos:
                continue
            if(len(asdf)==0):
                break
            for e in asdf[pos]:
                if(s[(i-1+n)%n] in qwer[e] or s[(i+1)%n] in qwer[e]):
                    #print(s[i])
                    print('No')
                    ch = True
                    break
        if(not ch):
            print('Okay')
# 1681000, 2022-11-12 11:16:30, PPPPPP (100%)

qwer = {}
venom = {}
rockky = []
x = input().split()
while x != ["End"]:
    country = [e for e in x[1:]]
    for e in country:
        if e not in qwer:
            qwer[e] = []
        if e not in venom:
            venom[e] = []
    if x[0] == "Ally":
        for e in country:
            y = country.copy()
            y.remove(e)
            qwer[e] += y
    elif x[0] == "Enemy":
        for e in country:
            y = country.copy()
            y.remove(e)
            venom[e] += y
    for key,value in venom.items():
        for i in range(len(value)):
            venom[key] += qwer[value[i]]
    for key,value in qwer.items():
        for i in range(len(value)):
            venom[key] += venom[value[i]]
    for key in venom:
        venom[key] = set(venom[key])
        venom[key] = list(venom[key])
    for key in qwer:
        qwer[key] = set(qwer[key])
        qwer[key] = list(qwer[key])
    if x[0] == "Table":
        count = 0
        
        for i in range(len(country)-1):
            if (country[i-1] in venom[country[i]]) or (country[i+1] in venom[country[i]]):
                rockky.append("No")
                break
            else: count += 1
        if count == len(country)-1:
            rockky.append("Okay")
    x = input().split()

for e in rockky:
    print(e)

6531403021
# 1679723, 2022-11-12 10:24:30, P-PPPP (83%)

s = input()
A = list()
E = list()
r = list()
while s!='End' :
    S = s.split()
    a = S.pop(0)
    if a == 'Ally' :
        A.append(S)
    elif a == 'Enemy' :
        ally1 = list()
        ally1.append(S[0])
        ally2 = list()
        ally2.append(S[1])
        for i in A :
            if S[0] in i :
                ally1 = i
            if S[1] in i :
                ally2 = i
        ally = (ally1,ally2)
        E.append(ally)
    elif a == 'Table' :
        c = True
        for i in range (len(S)) :
            c1 = S[i]
            c2 = S[i-1]
            ec1 = list()
            ec2 = list()
            for j in E :
               if c2 in j[0] :
                   ec2 = j[1]
               if c1 in j[1] :
                   ec1 = j[0] 
               if c1 in ec2 :
                   c = False
               if c2 in ec1 :
                   c = False
        if c :
            r.append("Okay")
        else :
            r.append("No")
                    
                        
    s = input()

for i in r :
    print(i)
      

# 1680230, 2022-11-12 10:47:52, P-PPPP (83%)

s = input()
A = list()
E = list()
r = list()
while s!='End' :
    S = s.split()
    a = S.pop(0)
    if a == 'Ally' :
        T = True
        k = list()
        for i in A :
            for j in i :
                if j in S :
                    k = i
        
        if len(k)!= 0 :
            A.remove(k)
        for i in S :
            if not i in k :
                k.append(i)
            
        A.append(k)
        
    elif a == 'Enemy' :
        ally1 = list()
        ally1.append(S[0])
        ally2 = list()
        ally2.append(S[1])
        for i in A :
            if S[0] in i :
                ally1 = i
            if S[1] in i :
                ally2 = i
        ally = (ally1,ally2)
        E.append(ally)
    elif a == 'Table' :
        c = True
        for i in range (len(S)) :
            c1 = S[i]
            c2 = S[i-1]
            ec1 = list()
            ec2 = list()
            for j in E :
               if c2 in j[0] :
                   ec2 = j[1]
               if c1 in j[1] :
                   ec1 = j[0] 
               if c1 in ec2 :
                   c = False
               if c2 in ec1 :
                   c = False
            
            
        if c :
            r.append("Okay")
        else :
            r.append("No")
                    
                        
    s = input()

for i in r :
    print(i)
      

# 1680276, 2022-11-12 10:50:18, PPPPPP (100%)

s = input()
A = list()
E = list()
r = list()
while s!='End' :
    S = s.split()
    a = S.pop(0)
    if a == 'Ally' :
        T = True
        k = list()
        for i in A :
            for j in i :
                if j in S :
                    k = i
        
        if len(k)!= 0 :
            A.remove(k)
        for i in S :
            if not i in k :
                k.append(i)
            
        A.append(k)
        
    elif a == 'Enemy' :
        ally1 = list()
        ally1.append(S[0])
        ally2 = list()
        ally2.append(S[1])
        for i in A :
            if S[0] in i :
                ally1 = i
            if S[1] in i :
                ally2 = i
        ally = (ally1,ally2)
        E.append(ally)
    elif a == 'Table' :
        c = True
        for i in range (len(S)) :
            c1 = S[i]
            c2 = S[i-1]
            ec1 = list()
            ec2 = list()
            for j in E :
               if c2 in j[0] :
                   ec2 = j[1]
               if c1 in j[1] :
                   ec1 = j[0]
               if c2 in j[1] :
                   ec2 = j[0]
               if c1 in j[0] :
                   ec1 = j[1]
               if c1 in ec2 :
                   c = False
               if c2 in ec1 :
                   c = False
            
            
        if c :
            r.append("Okay")
        else :
            r.append("No")
                    
                        
    s = input()

for i in r :
    print(i)
      


6531514021
# 1680592, 2022-11-12 11:02:47, P-PPP- (67%)

def Ally() :
    pass
def Enemy() :
    pass
def Table() :
    pass

Ally = []
Enemy = {}
Table = []
text = input().split()
data = []
while text[0] != 'End' :
    if text[0] == 'Ally' :
        Ally.append(set(text[1:]))
    if text[0] == 'Enemy' :
        a,b = text[1:]
        if a not in Enemy : Enemy[a] = set()
        if b not in Enemy : Enemy[b] = set()
        Enemy[a].add(b)
        Enemy[b].add(a)
    if text[0] == 'Table' :
        Table.append(text[1:])
    text = input().split()

# Enemy -> {'China': {'America'}, 'America': {'China'}, 'France': {'Iran'}, \
#           'Iran': {'France', 'Iraq'}, 'Iraq': {'Iran'}}
# Ally -> [{'France', 'Ukraine', 'America', 'England'}, {'Russia', 'China'}]
# sum_enemy -> {('China', 'Russia'): {'America'}, ('England', 'America', 'France', 'Ukraine'): {'Iran'}}
sum_enemy = {}
for k,v in Enemy.items():
    b = False
    for c in Ally:
        if k in c :
            if tuple(c) not in sum_enemy :
                sum_enemy[tuple(c)] = v
                b = True
            else:
                sum_enemy[tuple(c)] |= v
                b = True
    if not b :
        sum_enemy[k] = v
for k,v in sum_enemy.items():
    for e in set(v) :
        for c in Ally :
            if e in c:
                sum_enemy[k] |= c
# sum_enemy -> {('Russia', 'China'): {'Ukraine', 'France', 'England', 'America'},
# ('Ukraine', 'England', 'France', 'America'): {'Russia', 'China', 'Iran'},
# 'Iran': {'France', 'Ukraine', 'Iraq', 'England', 'America'},
#'Iraq': {'Iran'}}
ss = {}
for k,v in sum_enemy.items() :
    if type(k) == tuple:
        for e in k:
            ss[e] = v
    else :
        ss[k] = v
        
rr = []
for e in Table :
    BB = True
    for i in range(len(e)-1):
        if e[i] in ss:
            if e[i+1] in ss[e[i]]:
                rr.append('No')
                BB = False
                break
    if BB :
        rr.append('Okay')

for e in rr:
    print(e)

# 1680752, 2022-11-12 11:07:55, PPPPPP (100%)

def Ally() :
    pass
def Enemy() :
    pass
def Table() :
    pass

Ally = []
Enemy = {}
Table = []
text = input().split()
data = []
while text[0] != 'End' :
    if text[0] == 'Ally' :
        Ally.append(set(text[1:]))
    if text[0] == 'Enemy' :
        a,b = text[1:]
        if a not in Enemy : Enemy[a] = set()
        if b not in Enemy : Enemy[b] = set()
        Enemy[a].add(b)
        Enemy[b].add(a)
    if text[0] == 'Table' :
        Table.append(text[1:])
    text = input().split()

# Enemy -> {'China': {'America'}, 'America': {'China'}, 'France': {'Iran'}, \
#           'Iran': {'France', 'Iraq'}, 'Iraq': {'Iran'}}
# Ally -> [{'France', 'Ukraine', 'America', 'England'}, {'Russia', 'China'}]
# sum_enemy -> {('China', 'Russia'): {'America'}, ('England', 'America', 'France', 'Ukraine'): {'Iran'}}
sum_enemy = {}
for k,v in Enemy.items():
    b = False
    for c in Ally:
        if k in c :
            if tuple(c) not in sum_enemy :
                sum_enemy[tuple(c)] = v
                b = True
            else:
                sum_enemy[tuple(c)] |= v
                b = True
    if not b :
        sum_enemy[k] = v
for k,v in sum_enemy.items():
    for e in set(v) :
        for c in Ally :
            if e in c:
                sum_enemy[k] |= c
# sum_enemy -> {('Russia', 'China'): {'Ukraine', 'France', 'England', 'America'},
# ('Ukraine', 'England', 'France', 'America'): {'Russia', 'China', 'Iran'},
# 'Iran': {'France', 'Ukraine', 'Iraq', 'England', 'America'},
#'Iraq': {'Iran'}}
ss = {}
for k,v in sum_enemy.items() :
    if type(k) == tuple:
        for e in k:
            ss[e] = v
    else :
        ss[k] = v
        
rr = []
for e in Table :
    BB = True
    for i in range(len(e)-1):
        if e[i] in ss:
            if e[i+1] in ss[e[i]]:
                BB = False
                break
    if e[0] in ss:
        if e[-1] in ss[e[0]]:
            BB = False
    if BB :
        rr.append('Okay')
    else:
        rr.append('No')
    
for e in rr:
    print(e)

# 1680785, 2022-11-12 11:09:09, PPPPPP (100%)

Ally = []
Enemy = {}
Table = []
text = input().split()
data = []
while text[0] != 'End' :
    if text[0] == 'Ally' :
        Ally.append(set(text[1:]))
    if text[0] == 'Enemy' :
        a,b = text[1:]
        if a not in Enemy : Enemy[a] = set()
        if b not in Enemy : Enemy[b] = set()
        Enemy[a].add(b)
        Enemy[b].add(a)
    if text[0] == 'Table' :
        Table.append(text[1:])
    text = input().split()

# Enemy -> {'China': {'America'}, 'America': {'China'}, 'France': {'Iran'}, \
#           'Iran': {'France', 'Iraq'}, 'Iraq': {'Iran'}}
# Ally -> [{'France', 'Ukraine', 'America', 'England'}, {'Russia', 'China'}]
# sum_enemy -> {('China', 'Russia'): {'America'}, ('England', 'America', 'France', 'Ukraine'): {'Iran'}}
sum_enemy = {}
for k,v in Enemy.items():
    b = False
    for c in Ally:
        if k in c :
            if tuple(c) not in sum_enemy :
                sum_enemy[tuple(c)] = v
                b = True
            else:
                sum_enemy[tuple(c)] |= v
                b = True
    if not b :
        sum_enemy[k] = v
for k,v in sum_enemy.items():
    for e in set(v) :
        for c in Ally :
            if e in c:
                sum_enemy[k] |= c
# sum_enemy -> {('Russia', 'China'): {'Ukraine', 'France', 'England', 'America'},
# ('Ukraine', 'England', 'France', 'America'): {'Russia', 'China', 'Iran'},
# 'Iran': {'France', 'Ukraine', 'Iraq', 'England', 'America'},
#'Iraq': {'Iran'}}
ss = {}
for k,v in sum_enemy.items() :
    if type(k) == tuple:
        for e in k:
            ss[e] = v
    else :
        ss[k] = v
        
rr = []
for e in Table :
    BB = True
    for i in range(len(e)-1):
        if e[i] in ss:
            if e[i+1] in ss[e[i]]:
                BB = False
                break
    if e[0] in ss:
        if e[-1] in ss[e[0]]:
            BB = False
    if BB :
        rr.append('Okay')
    else:
        rr.append('No')
    
for e in rr:
    print(e)

6530049421
# 1679588, 2022-11-12 10:18:53, PPPPPP (100%)

#Quiz 3_3 APEC Headache

allies = dict()
enemies = dict()

x = input().split()
while x[0] != "End":
    if x[0] == "Ally":
        for nation in x[1:]:
            allies_nations = x[1:]
            allies_nations.remove(nation)
            if nation in allies:
                allies[nation] = allies[nation] | set(allies_nations)
            else:
                allies[nation] = set(allies_nations)
            enemies_of_allies = set()
            for ally in allies[nation]:
                if ally in enemies:
                    for enemy_of_ally in enemies[ally]:
                        enemies_of_allies.add(enemy_of_ally)
            if nation in enemies:
                enemies[nation] = enemies[nation] | enemies_of_allies
            else:
                enemies[nation] =  enemies_of_allies
                
    if x[0] == "Enemy":
        for nation in x[1:]:
            enemies_nations = x[1:]
            enemies_nations.remove(nation)
            if nation in enemies:
                enemies[nation] = enemies[nation] | set(enemies_nations)
            else:
                enemies[nation] = set(enemies_nations)
            allies_of_enemies = set()
            for enemy in enemies[nation]:
                if enemy in allies:
                    for ally_of_enemy in allies[enemy]:
                        allies_of_enemies.add(ally_of_enemy)
            enemies[nation] = enemies[nation] | allies_of_enemies
            if nation in allies:
                for ally in allies[nation]:
                    if ally in enemies:
                        enemies[ally] = enemies[ally] | enemies[nation]
                else:
                        enemies[ally] = enemies[nation]
                        
    if x[0] == "Table":
        ok = True
        table = x[1:]
        if table[0] in enemies and table[-1] in enemies:
            if table[0] in enemies[table[-1]]:
                ok = False
        for i in range(len(table)-1):
            if table[i+1] in enemies:
                if table[i] in enemies[table[i+1]]:
                    ok = False
                    break
        if ok:
            print("Okay")
        else:
            print("No")
    x = input().split()

# 1679647, 2022-11-12 10:21:58, PPPPPP (100%)

#Quiz 3_3 APEC Headache

allies = dict()
enemies = dict()

x = input().split()
while x[0] != "End":
    if x[0] == "Ally":
        for nation in x[1:]:
            allies_nations = x[1:]
            allies_nations.remove(nation)
            if nation in allies:
                allies[nation] = allies[nation] | set(allies_nations)
            else:
                allies[nation] = set(allies_nations)
            enemies_of_allies = set()
            for ally in allies[nation]:
                if ally in enemies:
                    for enemy_of_ally in enemies[ally]:
                        enemies_of_allies.add(enemy_of_ally)
            if nation in enemies:
                enemies[nation] = enemies[nation] | enemies_of_allies
            else:
                enemies[nation] =  enemies_of_allies
            for enemy in enemies[nation]:
                enemies[enemy] = enemies[enemy] | set(allies_nations)
                
    if x[0] == "Enemy":
        for nation in x[1:]:
            enemies_nations = x[1:]
            enemies_nations.remove(nation)
            if nation in enemies:
                enemies[nation] = enemies[nation] | set(enemies_nations)
            else:
                enemies[nation] = set(enemies_nations)
            allies_of_enemies = set()
            for enemy in enemies[nation]:
                if enemy in allies:
                    for ally_of_enemy in allies[enemy]:
                        allies_of_enemies.add(ally_of_enemy)
            enemies[nation] = enemies[nation] | allies_of_enemies
            if nation in allies:
                for ally in allies[nation]:
                    if ally in enemies:
                        enemies[ally] = enemies[ally] | enemies[nation]
                else:
                        enemies[ally] = enemies[nation]
                        
    if x[0] == "Table":
        ok = True
        table = x[1:]
        if table[0] in enemies and table[-1] in enemies:
            if table[0] in enemies[table[-1]]:
                ok = False
        for i in range(len(table)-1):
            if table[i+1] in enemies:
                if table[i] in enemies[table[i+1]]:
                    ok = False
                    break
        if ok:
            print("Okay")
        else:
            print("No")
    x = input().split()

# 1679726, 2022-11-12 10:24:36, PPPPPP (100%)

#Quiz 3_3 APEC Headache

allies = dict()
enemies = dict()

x = input().split()
while x[0] != "End":
    if x[0] == "Ally":
        for nation in x[1:]:
            allies_nations = x[1:]
            allies_nations.remove(nation)
            if nation in allies:
                allies[nation] = allies[nation] | set(allies_nations)
            else:
                allies[nation] = set(allies_nations)
            enemies_of_allies = set()
            for ally in allies[nation]:
                if ally in enemies:
                    for enemy_of_ally in enemies[ally]:
                        enemies_of_allies.add(enemy_of_ally)
            if nation in enemies:
                enemies[nation] = enemies[nation] | enemies_of_allies
            else:
                enemies[nation] =  enemies_of_allies
            for enemy in enemies[nation]:
                enemies[enemy] = enemies[enemy] | set(allies_nations)
                
    if x[0] == "Enemy":
        for nation in x[1:]:
            enemies_nations = x[1:]
            enemies_nations.remove(nation)
            if nation in enemies:
                enemies[nation] = enemies[nation] | set(enemies_nations)
            else:
                enemies[nation] = set(enemies_nations)
            allies_of_enemies = set()
            for enemy in enemies[nation]:
                if enemy in allies:
                    for ally_of_enemy in allies[enemy]:
                        allies_of_enemies.add(ally_of_enemy)
            enemies[nation] = enemies[nation] | allies_of_enemies
            if nation in allies:
                for ally in allies[nation]:
                    if ally in enemies:
                        enemies[ally] = enemies[ally] | enemies[nation]
                else:
                        enemies[ally] = enemies[nation]
                        
    if x[0] == "Table":
        ok = True
        table = x[1:]
        if table[0] in enemies and table[-1] in enemies:
            if table[0] in enemies[table[-1]]:
                ok = False
        for i in range(len(table)-1):
            if table[i+1] in enemies:
                if table[i] in enemies[table[i+1]]:
                    ok = False
                    break
        if ok:
            print("Okay")
        else:
            print("No")
    x = input().split()
    
# Liverpool 3-1 Real Madrid


6530083721
# 1679946, 2022-11-12 10:34:12, x-PPPP (67%)

ally = []
foe = {}
ans = []
x = input().split()
while x[0] == 'Ally':
    a = set(x[1:])
    ally.append(a)
    x = input().split()

while  x[0] == 'Enemy':
    if x[1] not in foe:
        foe[x[1]] = {x[2]}
    else:
        foe[x[1]].add(x[2])
    if x[2] not in foe:
        foe[x[2]] = {x[1]}
    else:
        foe[x[2]].add(x[1])
    for n in ally:
        if x[1] in n:
            for al in n:
                foe[x[2]].add(al)
        if x[2] in n:
            for al in n:
                foe[x[1]].add(al)
            
    x = input().split()
for i in ally:
    for k in i:
        for mn in i:
            if k not in foe and mn in foe:
                foe[k] = foe[mn]
            if k in foe and mn in foe:
                for fo in foe[mn]: 
                    foe[k].add(fo)
while x[0] != 'End':
    for i in range(1,len(x)-1):
        if x[i] in foe and x[i+1] in foe: 
            if x[i+1] in foe[x[i]]:
                dead = True
                break
            if x[1] in foe and x[-1] in foe:
                if x[1] in foe[x[-1]]:
                    dead = True
                    break
            dead = False
    ans.append(dead)
    dead = False
    x = input().split()
for i in ans:
    if i: print('No')
    else: print('Okay')


# 1680091, 2022-11-12 10:41:22, x-PPPP (67%)

ally = []
foe = {}
ans = []
x = input().split()

while x[0] != 'End':
    if x[0] == 'Ally':
        a = set(x[1:])
        ally.append(a)
        x = input().split()

    elif x[0] == 'Enemy':
        if x[1] not in foe:
            foe[x[1]] = {x[2]}
        else:
            foe[x[1]].add(x[2])
        if x[2] not in foe:
            foe[x[2]] = {x[1]}
        else:
            foe[x[2]].add(x[1])
        for n in ally:
            if x[1] in n:
                for al in n:
                    foe[x[2]].add(al)
            if x[2] in n:
                for al in n:
                    foe[x[1]].add(al)
        for i in ally:
            for k in i:
                for mn in i:
                    if k not in foe and mn in foe:
                        foe[k] = foe[mn]
                    if k in foe and mn in foe:
                        for fo in foe[mn]: 
                            foe[k].add(fo)
        x = input().split()

    elif x[0] == 'Table':
        for i in range(1,len(x)-1):
            if x[i] in foe and x[i+1] in foe: 
                if x[i+1] in foe[x[i]]:
                    dead = True
                    break
                if x[1] in foe and x[-1] in foe:
                    if x[1] in foe[x[-1]]:
                        dead = True
                        break
                dead = False
        ans.append(dead)
        dead = False
        x = input().split()

for i in ans:
        if i: print('No')
        else: print('Okay')
    
    

# 1680165, 2022-11-12 10:44:40, PPPPPP (100%)

ally = []
foe = {}
ans = []
x = input().split()

while x[0] != 'End':
    if x[0] == 'Ally':
        a = set(x[1:])
        ally.append(a)
        x = input().split()

    elif x[0] == 'Enemy':
        if x[1] not in foe:
            foe[x[1]] = {x[2]}
        else:
            foe[x[1]].add(x[2])
        if x[2] not in foe:
            foe[x[2]] = {x[1]}
        else:
            foe[x[2]].add(x[1])
        for n in ally:
            if x[1] in n:
                for al in n:
                    foe[x[2]].add(al)
            if x[2] in n:
                for al in n:
                    foe[x[1]].add(al)
        for i in ally:
            for k in i:
                for mn in i:
                    if k not in foe and mn in foe:
                        foe[k] = foe[mn]
                    if k in foe and mn in foe:
                        for fo in foe[mn]: 
                            foe[k].add(fo)
        x = input().split()

    elif x[0] == 'Table':
        for i in x[1:]:
            if i not in foe:
                foe[i] = set()
        for i in range(1,len(x)-1):
            if x[i] in foe and x[i+1] in foe: 
                if x[i+1] in foe[x[i]]:
                    dead = True
                    break
                if x[1] in foe and x[-1] in foe:
                    if x[1] in foe[x[-1]]:
                        dead = True
                        break
                dead = False
        ans.append(dead)
        dead = False
        x = input().split()

for i in ans:
        if i: print('No')
        else: print('Okay')
    
    


6530135721
# 1680181, 2022-11-12 10:45:29, ------ (0%)

#ally = {c = {ccc}}
#notok = {c = {nokc}}
ally = {}
notok = {}
while True:
    x = input().split()
    if x[0] == 'End': break
    elif x[0] == 'Ally':
        for i in x[1:]:
            if i not in ally:
                ally[i] = set()
                ally[i] = (ally[i] | set(x[1:]))
                #ally[i] = (ally[i] | set(x[1:])) - {i}
    elif x[0] == 'Enemy':
        if x[1] not in ally: ally[x[1]] = {x[1]}
        if x[2] not in ally: ally[x[2]] = {x[2]}
        for i in ally[x[1]]:
            for j in ally[x[2]]:
                if i not in notok:
                    notok[i] = set()
                    notok[i] = notok[i] | ally[x[2]]
        for i in ally[x[2]]:
            for j in ally[x[1]]:
                if i not in notok:
                    notok[i] = set()
                    notok[i] = notok[i] | ally[x[1]]
    elif x[0] == 'Table':
        newx = x[1:] + [x[1]]
        isOK = True
        for i in range(len(newx)-1):
            if (newx[i+1] in notok) and (newx[i] in notok):
                if newx[i] not in notok[newx[i+1]]: pass
                else:
                    isOK = False
                    break
            else: pass
        if isOK: print('Okay')
        else: print('No')
print(ally)
print(notok)
        

# 1680189, 2022-11-12 10:45:41, PP-PP- (67%)

#ally = {c = {ccc}}
#notok = {c = {nokc}}
ally = {}
notok = {}
while True:
    x = input().split()
    if x[0] == 'End': break
    elif x[0] == 'Ally':
        for i in x[1:]:
            if i not in ally:
                ally[i] = set()
                ally[i] = (ally[i] | set(x[1:]))
                #ally[i] = (ally[i] | set(x[1:])) - {i}
    elif x[0] == 'Enemy':
        if x[1] not in ally: ally[x[1]] = {x[1]}
        if x[2] not in ally: ally[x[2]] = {x[2]}
        for i in ally[x[1]]:
            for j in ally[x[2]]:
                if i not in notok:
                    notok[i] = set()
                    notok[i] = notok[i] | ally[x[2]]
        for i in ally[x[2]]:
            for j in ally[x[1]]:
                if i not in notok:
                    notok[i] = set()
                    notok[i] = notok[i] | ally[x[1]]
    elif x[0] == 'Table':
        newx = x[1:] + [x[1]]
        isOK = True
        for i in range(len(newx)-1):
            if (newx[i+1] in notok) and (newx[i] in notok):
                if newx[i] not in notok[newx[i+1]]: pass
                else:
                    isOK = False
                    break
            else: pass
        if isOK: print('Okay')
        else: print('No')
# 1680836, 2022-11-12 11:10:55, PPPPPP (100%)

#ally = {c = {ccc}}
#notok = {c = {nokc}}
ally = {}
notok = {}
while True:
    x = input().split()
    if x[0] == 'End': break
    elif x[0] == 'Ally':
        for i in x[1:]:
            if i not in ally:
                ally[i] = set()
                ally[i] = (ally[i] | set(x[1:]))
                #ally[i] = (ally[i] | set(x[1:])) - {i}
    elif x[0] == 'Enemy':
        if x[1] not in ally: ally[x[1]] = {x[1]}
        if x[2] not in ally: ally[x[2]] = {x[2]}
        for i in ally[x[1]]:
            for j in ally[x[2]]:
                if i not in notok:
                    notok[i] = set()
                    notok[i] = notok[i] | ally[x[2]]
                else : notok[i] = notok[i] | ally[x[2]]
        for i in ally[x[2]]:
            for j in ally[x[1]]:
                if i not in notok:
                    notok[i] = set()
                    notok[i] = notok[i] | ally[x[1]]
                else: notok[i] = notok[i] | ally[x[1]]
    elif x[0] == 'Table':
        newx = x[1:] + [x[1]]
        isOK = True
        for i in range(len(newx)-1):
            if (newx[i+1] in notok) and (newx[i] in notok):
                if newx[i] not in notok[newx[i+1]]: pass
                else:
                    isOK = False
                    break
            else: pass
        if isOK: print('Okay')
        else: print('No')

6530154621
# 1680185, 2022-11-12 10:45:36, ------ (0%)

Al = {}
# {'America': {'France', 'England', 'Ukraine', 'America'}, 'England': {'France', 'England', 'Ukraine', 'America'},
# 'Ukraine': {'France', 'England', 'Ukraine', 'America'}, 'France': {'France', 'England', 'Ukraine', 'America'},
# 'Russia': {'Russia', 'China'}, 'China': {'Russia', 'China'}, 'Iran': set(), 'Iraq': set()}
En = {}


while True:
    x = input().split()
    if x[0] == 'End': break
    elif x[0] == 'Ally':
        l = x[1:]
        for e in range(len(l)):
            if l[e] not in Al: Al[l[e]] = set()
            for o in l:
                Al[l[e]].add(o)
    elif x[0] == 'Enemy':
        if x[1] not in En: En[x[1]] = set()
        if x[2] not in En: En[x[2]] = set()
        if x[2] not in Al:
            Al[x[2]] = set()
            Al[x[2]].add(x[2])
        if x[1] not in Al:
            Al[x[1]] = set()
            Al[x[1]].add(x[1])
        for e in Al[x[2]]:
            En[x[1]].add(e)
        for e in Al[x[1]]:
            En[x[2]].add(e)
    elif x[0] == 'Table':
        l = [e for e in x]
        l = [l[-1]]+l[1:]+[l[1]]
        for e in l:
            if e not in En: En[e] = set()
        j = 'OK'
        for i in range(1,len(l)-1):
            if l[i-1] in En[l[i]] or l[i+1] in En[l[i]]:
                j = 'No'
                break
        print(j)
# 1680359, 2022-11-12 10:53:31, ------ (0%)

Al = {}
# {'America': {'France', 'England', 'Ukraine', 'America'}, 'England': {'France', 'England', 'Ukraine', 'America'},
# 'Ukraine': {'France', 'England', 'Ukraine', 'America'}, 'France': {'France', 'England', 'Ukraine', 'America'},
# 'Russia': {'Russia', 'China'}, 'China': {'Russia', 'China'}, 'Iran': set(), 'Iraq': set()}
En = {}


while True:
    x = input().split()
    if x[0] == 'End': break
    
    elif x[0] == 'Ally':
        l = x[1:]
        for e in range(len(l)):
            if l[e] not in Al: Al[l[e]] = set()
            for o in l:
                Al[l[e]].add(o)
                
    elif x[0] == 'Enemy':
        if x[1] not in Al:
            Al[x[1]] = set()
            Al[x[1]].add(x[1])
        if x[2] not in Al:
            Al[x[2]] = set()
            Al[x[2]].add(x[2])
        for e in Al[x[1]]:
            if e not in En: En[e] = set()
        for e in Al[x[2]]:
            if e not in En: En[e] = set()
        for e in Al[x[1]]:
            for j in Al[x[2]]:
                En[e].add(j)
        for e in Al[x[2]]:
            for j in Al[x[1]]:
                En[e].add(j)
        
    elif x[0] == 'Table':
        l = [e for e in x]
        l = [l[-1]]+l[1:]+[l[1]]
        for e in l:
            if e not in En: En[e] = set()
        j = 'OK'
        for i in range(1,len(l)-1):
            if l[i-1] in En[l[i]] or l[i+1] in En[l[i]]:
                j = 'No'
                break
        print(j)
            
'''
Ally America England Ukraine France
Ally Russia China
Enemy China America
Enemy France Iran
Enemy Iran Iraq
Table America England Iceland France Iran Russia Iraq
Table America England Russia
Table America England Thailand Russia China Iran China Japan
End
'''


# 1680388, 2022-11-12 10:54:24, PPPPPP (100%)

Al = {}
# {'America': {'France', 'England', 'Ukraine', 'America'}, 'England': {'France', 'England', 'Ukraine', 'America'},
# 'Ukraine': {'France', 'England', 'Ukraine', 'America'}, 'France': {'France', 'England', 'Ukraine', 'America'},
# 'Russia': {'Russia', 'China'}, 'China': {'Russia', 'China'}, 'Iran': set(), 'Iraq': set()}
En = {}


while True:
    x = input().split()
    if x[0] == 'End': break
    
    elif x[0] == 'Ally':
        l = x[1:]
        for e in range(len(l)):
            if l[e] not in Al: Al[l[e]] = set()
            for o in l:
                Al[l[e]].add(o)
                
    elif x[0] == 'Enemy':
        if x[1] not in Al:
            Al[x[1]] = set()
            Al[x[1]].add(x[1])
        if x[2] not in Al:
            Al[x[2]] = set()
            Al[x[2]].add(x[2])
        for e in Al[x[1]]:
            if e not in En: En[e] = set()
        for e in Al[x[2]]:
            if e not in En: En[e] = set()
        for e in Al[x[1]]:
            for j in Al[x[2]]:
                En[e].add(j)
        for e in Al[x[2]]:
            for j in Al[x[1]]:
                En[e].add(j)
        
    elif x[0] == 'Table':
        l = [e for e in x]
        l = [l[-1]]+l[1:]+[l[1]]
        for e in l:
            if e not in En: En[e] = set()
        j = 'Okay'
        for i in range(1,len(l)-1):
            if l[i-1] in En[l[i]] or l[i+1] in En[l[i]]:
                j = 'No'
                break
        print(j)
            
'''
Ally America England Ukraine France
Ally Russia China
Enemy China America
Enemy France Iran
Enemy Iran Iraq
Table America England Iceland France Iran Russia Iraq
Table America England Russia
Table America England Thailand Russia China Iran China Japan
End
'''



6530162621
# 1679556, 2022-11-12 10:16:44, PPPPP- (83%)

# 2565_1_Quiz_3_3.py

allys = {}
enemys = {}
tables = []

def isEnemy(c1, c2):
    yes = False
    
    if c1 not in allys:
        ally1 = [c1]
    else:
        ally1 = allys[c1]
    if c2 not in allys:
        ally2 = [c2]
    else:
        ally2 = allys[c2]
        
    for i in ally1:
        for j in ally2:
            if i in enemys and enemys[i] == j:
                yes = True
        if yes:
            break
    return yes
        

ln = input()
while ln != 'End':
    splited = ln.split()
    mode = splited[0]
    countries = splited[1:]
    if mode == 'Ally':
        for country in countries:
            allys[country] = set(ln.split())
            
    elif mode == 'Enemy':
        for country in countries:
            _, country1,country2 = ln.split()
            enemys[country1] = country2
            enemys[country2] = country1
    
    elif mode == 'Table':
        valid = True  
        for i in range(len(countries)):
            if isEnemy(countries[i],countries[(i+1)%len(countries)]):
                valid = False 
                break
        if valid:
            print('Okay')
        else:
            print('No')
    ln = input()

# 1679661, 2022-11-12 10:22:25, PPPPP- (83%)

# 2565_1_Quiz_3_3.py

allys = {}
enemys = {}
tables = []

def isEnemy(c1, c2):
    yes = False
    
    if c1 not in allys:
        ally1 = [c1]
    else:
        ally1 = allys[c1]
    if c2 not in allys:
        ally2 = [c2]
    else:
        ally2 = allys[c2]
        
    for i in ally1:
        for j in ally2:
            if i in enemys and enemys[i] == j:
                yes = True
        if yes:
            break
    return yes
        

ln = input()
while ln != 'End':
    splited = ln.split()
    mode = splited[0]
    countries = splited[1:]
    if mode == 'Ally':
        for country in countries:
            allys[country] = set(countries)
            
    elif mode == 'Enemy':
        for country in countries:
            _, country1,country2 = ln.split()
            enemys[country1] = country2
            enemys[country2] = country1
    
    elif mode == 'Table':
        valid = True  
        for i in range(len(countries)):
            if isEnemy(countries[i],countries[(i+1)%len(countries)]):
                valid = False 
                break
        if valid:
            print('Okay')
        else:
            print('No')
    ln = input()

# 1679785, 2022-11-12 10:27:47, PPPPPP (100%)

# 2565_1_Quiz_3_3.py

allys = {}
enemys = {}
tables = []

def isEnemy(c1, c2):
    yes = False
    if c1 not in allys:
        ally1 = {c1}
    else:
        ally1 = allys[c1]

    if c2 not in allys:
        ally2 = {c2}
    else:
        ally2 = allys[c2]
        
    for i in ally1:
        for j in ally2:
            if i in enemys and enemys[i] == j:
                yes = True
                break
            elif j in enemys and enemys[j] == i:
                yes = True
                break
        if yes:
            break
    return yes
        

ln = input()
while ln != 'End':
    splited = ln.split()
    mode = splited[0]
    countries = splited[1:]
    if mode == 'Ally':
        for country in countries:
            allys[country] = set(countries)
            
    elif mode == 'Enemy':
        for country in countries:
            country1,country2 = countries
            enemys[country1] = country2
            enemys[country2] = country1
    
    elif mode == 'Table':
        valid = True  
        for i in range(len(countries)):
            if isEnemy(countries[i],countries[(i+1)%len(countries)]):
                valid = False 
                break
        if valid:
            print('Okay')
        else:
            print('No')
    ln = input()


6530187321
# 1680124, 2022-11-12 10:42:40, xxxxxx (0%)

x = input().split()
ally = {}
enemy = {}
while x[0] != 'End':
    if x[0] == 'Ally':
        for e in x[1:]:
            ally[e] = set()
            for i in x[1:]:
                if i != e:
                    ally[e].add(i)
    elif x[0] == 'Enemy':
        if x[1] not in enemy: enemy[x[1]] = set()
        enemy[x[1]].add(x[2])
        if x[2] not in enemy: enemy[x[2]] = set()
        enemy[x[2]].add(x[1])
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[x[1]].add(e)
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[x[1]].add(e)
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[x[2]].add(e)
                if e not in enemy: enemy[e] = set()
                enemy[e].add(x[2])
                if x[2] in ally:
                    for i in ally[x[2]]:
                        enemy[e].add(i)
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[x[1]].add(e)
                if e not in enemy: enemy[e] = set()
                enemy[e].add(x[1])
                if x[1] in ally:
                    for i in ally[x[1]]:
                        enemy[e].add(i)
    elif x[0] == 'Table':
        table = x[1:] + [x[1]]
        t = True
        for i in range(len(table)-1):
            if table[i] in ally or table[i] in enemy:
                if table[i+1] in ally[table[i]]|enemy[table[i]]:
                    t = False
                    break
        if t == True: print('Okay')
        else: print('No')           
    x = input().split()
        

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

print('No')
# 1680274, 2022-11-12 10:50:15, PPPPPP (100%)

x = input().strip()
ally = {}
enemy = {}
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        for e in x[1:]:
            ally[e] = set()
            for i in x[1:]:
                if i != e:
                    ally[e].add(i)
    elif x[0] == 'Enemy':
        if x[1] not in enemy: enemy[x[1]] = set()
        enemy[x[1]].add(x[2])
        if x[2] not in enemy: enemy[x[2]] = set()
        enemy[x[2]].add(x[1])
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[x[1]].add(e)
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[x[2]].add(e)
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[x[2]].add(e)
                if e not in enemy: enemy[e] = set()
                enemy[e].add(x[2])
                if x[2] in ally:
                    for i in ally[x[2]]:
                        enemy[e].add(i)
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[x[1]].add(e)
                if e not in enemy: enemy[e] = set()
                enemy[e].add(x[1])
                if x[1] in ally:
                    for i in ally[x[1]]:
                        enemy[e].add(i)
    elif x[0] == 'Table':
        table = x[1:] + [x[1]]
        t = True
        for i in range(len(table)-1):
            if table[i] in enemy:
                if table[i+1] in enemy[table[i]]:
                    t = False
                    break
        if t == True: print('Okay')
        else: print('No')           
    x = input().strip()
        


6531303021
# 1678870, 2022-11-12 09:39:02, xxxxxx (0%)

stu = {}
N,M,K = [int(i) for i in input().split()]
for i in range(N):
    a,b = input().split()
    stu[a] = b
peo = {}
fac = {}
for i in range(M):
    a = input().split()
    peo[a[0]] = a[1:]
    for z in a[1:]:
        if z in stu:
            if stu[z] not in fac:fac[stu[z]] = set()
            fac[stu[z]].add(a[0])
for i in range(K):
    fa = []
    lis = set(input().split())
    for k,v in fac.items():
        if v == lis:fa.append(k)
    if len(fa) != 0 :print(' '.join(sorted(fa)))
    else:print('None')
# 1681281, 2022-11-12 11:23:30, PPPPPP (100%)

ally = {}
d_a = {}
d_al = {}
enemi = []
vs = {}
tavle = []
n = 0
while True:
    
    x = input()
    if x == 'End':break
    x = x.split()
    if x[0] == 'Ally':
        n+= 1
        ally[n] = (set(x[1:]))
        a = x[1:]
        for i in x[1:]:
            d_al[i] = n
            d_a[i] = set(a)
            d_a[i].remove(i)
        vs[n] = set()

    elif x[0] == 'Enemy':
        con = x[1:]
        for i in con:
            a = con[:]
            a.remove(i)
            if i in d_al:
                vs[d_al[i]] |= set(a)
            else:
                n += 1
                ally[n] = {i}
                
                d_al[i] = n
                vs[n] = set(a)

            
    elif x[0] == 'Table':tavle.append(x[1:])
for k,e in vs.items():
    g = set()
    for i in vs[k]:
        g |= ally[d_al[i]]
    vs[k] |= g

for i in tavle:
    fi = True
    for h in range(len(i)):
        if i[h] in d_al and i[h-1] in vs[d_al[i[h]]]:fi = False
    if fi :print('Okay')
    else: print('No')


# 1681462, 2022-11-12 11:27:02, PPPPPP (100%)

ally = {}
group = {}
vs = {}
tavle = []
n = 0
while True:
    x = input()
    if x == 'End':break
    x = x.split()
    if x[0] == 'Ally':
        n+= 1
        ally[n] = (set(x[1:]))
        a = x[1:]
        for i in x[1:]:
            group[i] = n
        vs[n] = set()

    elif x[0] == 'Enemy':
        con = x[1:]
        for i in con:
            a = con[:]
            a.remove(i)
            if i in group:
                vs[group[i]] |= set(a)
            else:
                n += 1
                ally[n] = {i}
                group[i] = n
                vs[n] = set(a)

    elif x[0] == 'Table':tavle.append(x[1:])

for k,e in vs.items():
    g = set()
    for i in vs[k]:
        g |= ally[group[i]]
    vs[k] |= g

for i in tavle:
    fi = True
    for h in range(len(i)):
        if i[h] in group and i[h-1] in vs[group[i[h]]]:fi = False
    if fi :print('Okay')
    else: print('No')



6531329321
# 1679693, 2022-11-12 10:23:31, P----- (17%)


Allies = {}
enemies = []
t = input()
while t != 'End':
    t = t.split()
    counties = t[1:]
    if t[0] == 'Ally':
        for c in counties:
            Allies[c] = set(counties)
    elif t[0] == 'Enemy':
        for c in counties:
            if c not in Allies:
                Allies[c] = {c}
        enemies.append([Allies[t[1]],Allies[t[2]]])
    else:
        able = True
        for i in range(-1,len(counties)-1):
            for clown in enemies:
                if counties[i] in clown[0] and counties[i+1] in clown[1]\
                or counties[i] in clown[1] and counties[i+1] in clown[0]:
                    able = False
                    print(counties[i],counties[i+1])
                    break
            if not able: break
        if able: print('Okay')
        else: print('No')
    t = input()
# 1679783, 2022-11-12 10:27:41, P----- (17%)

Allies = {}
enemies = []
t = input()
while t != 'End':
    t = t.split()
    counties = t[1:]
    if t[0] == 'Ally':
        for c in counties:
            if c not in Allies:
                Allies[c] = set(counties)
            else: Allies[c] = Allies[c] | set(counties)
    elif t[0] == 'Enemy':
        for c in counties:
            if c not in Allies:
                Allies[c] = {c}
        enemies.append([Allies[t[1]],Allies[t[2]]])
    else:
        able = True
        for i in range(-1,len(counties)-1):
            for clown in enemies:
                if counties[i] in clown[0] and counties[i+1] in clown[1]\
                or counties[i] in clown[1] and counties[i+1] in clown[0]:
                    able = False
                    print(counties[i],counties[i+1])
                    break
            if not able: break
        if able: print('Okay')
        else: print('No')
    t = input()
# 1680236, 2022-11-12 10:48:24, PPPPPP (100%)

Allies = {}
enemies = []
t = input()
while t != 'End':
    t = t.split()
    counties = t[1:]
    if t[0] == 'Ally':
        for c in counties:
            Allies[c] = set(counties)
            for e in range(len(enemies)):
                if c in enemies[e][0]: enemies[e] = [Allies[c],enemies[e][1]]
                elif c in enemies[e][1]: enemies[e]= [enemies[e][0],Allies[c]]
    elif t[0] == 'Enemy':
        for c in counties:
            if c not in Allies:
                Allies[c] = {c}
        
        enemies.append([Allies[t[1]],Allies[t[2]]])
    else:
        able = True
        for i in range(-1,len(counties)-1):
            for clown in enemies:
                if counties[i] in clown[0] and counties[i+1] in clown[1]\
                or counties[i] in clown[1] and counties[i+1] in clown[0]:
                    able = False
                    break
            if not able: break
        if able: print('Okay')
        else: print('No')
    t = input()

6531346021
# 1679664, 2022-11-12 10:22:39, ------ (0%)

count=0
d={}
enl=[]
while True:
    l=input().split()

    if l==['End']:
        break
    if l[0]=='Ally':
        for i in l[1:]:
            d[i]=count
        count+=1
    elif l[0]=='Enemy':
        for j in range(1,3):
            if l[j] not in d:
                d[l[j]]=count
                count+=1
        enl.append({d[l[1]],d[l[2]]})
    elif l[0]=='Table':
        ch=True
        checks=set()
        l=l[1:]
        for i in range(len(l)):
            if l[i-1] in d and l[i] in d:
                if {d[l[i-1]],d[l[i]]} in enl:
                    ch=False
        if ch:
            print('Okay')
        else:
            print('No')
print(d)
print(enl)
# 1679672, 2022-11-12 10:22:55, PPPPPP (100%)

count=0
d={}
enl=[]
while True:
    l=input().split()

    if l==['End']:
        break
    if l[0]=='Ally':
        for i in l[1:]:
            d[i]=count
        count+=1
    elif l[0]=='Enemy':
        for j in range(1,3):
            if l[j] not in d:
                d[l[j]]=count
                count+=1
        enl.append({d[l[1]],d[l[2]]})
    elif l[0]=='Table':
        ch=True
        checks=set()
        l=l[1:]
        for i in range(len(l)):
            if l[i-1] in d and l[i] in d:
                if {d[l[i-1]],d[l[i]]} in enl:
                    ch=False
        if ch:
            print('Okay')
        else:
            print('No')
#print(d)
#print(enl)
# 1679802, 2022-11-12 10:28:33, PPPPPP (100%)

count=0
d={}
enl=[]
while True:
    l=input().split()

    if l==['End']:
        break
    if l[0]=='Ally':
        for i in l[1:]:
            d[i]=count
        count+=1
    elif l[0]=='Enemy':
        for j in range(1,3):
            if l[j] not in d:
                d[l[j]]=count
                count+=1
        enl.append({d[l[1]],d[l[2]]})
    elif l[0]=='Table':
        ch=True
        
        l=l[1:]
        for i in range(len(l)):
            if l[i-1] in d and l[i] in d:
                if {d[l[i-1]],d[l[i]]} in enl:
                    ch=False
        if ch:
            print('Okay')
        else:
            print('No')
#print(d)
#print(enl)

6532011921
# 1678932, 2022-11-12 09:43:17, PPPP-- (67%)

def is_enemies(allies, enemies, a, b):
    if a in enemies.get(b, set()):
        return True
    
    for x in allies.get(a, set()):
        if x in enemies.get(b, set()):
            return True
    for x in allies.get(b, set()):
        if x in enemies.get(a, set()):
            return True
    return False

allies = {}
enemies = {}
while True:
    s = input()
    if s == 'End':
        break
    l = [x.strip() for x in s.split()]
    if l[0] == 'Ally':
        for i in range(1, len(l)):
            # allies[l[i]].add
            if not l[i] in allies:
                allies[l[i]] = set()
            for j in range(i+1, len(l)):
                if not l[j] in allies:
                    allies[l[j]] = set()
                allies[l[i]].add(l[j])
                allies[l[j]].add(l[i])
    elif l[0] == 'Enemy':
        a, b = l[1:]
        if not a in enemies:
            enemies[a] = set()
        if not b in enemies:
            enemies[b] = set()
        enemies[a].add(b)
        enemies[b].add(a)
        # if not allies[a] in enemies:
        #     enemies[allies[a]] = set()
        # if not allies[b] in enemies:
        #     enemies[allies[b]] = set()
        # enemies[allies[a]].add(allies[b])
        # enemies[allies[b]].add(allies[a])
    else:
        ok = True
        countries = l[1:]
        for i in range(len(countries)):
            if is_enemies(allies, enemies, countries[i-1], countries[i]):
                ok = False
                break
        if ok:
            print('Okay')
        else:
            print('No')
    # print(allies)
# 1679058, 2022-11-12 09:49:53, PPPP-- (67%)

def is_enemies(allies, enemies, a, b, visited):
    visited.add(a)
    if a in enemies.get(b, set()):
        return True
    
    for x in allies.get(a, set()):
        if not x in visited and is_enemies(allies, enemies, x, b, visited):
            return True
    return False 

    # for x in allies.get(a, set()):
    #     if x in enemies.get(b, set()):
    #         return True
    # for x in allies.get(b, set()):
    #     if x in enemies.get(a, set()):
    #         return True
    # return False

allies = {}
enemies = {}
while True:
    s = input()
    if s == 'End':
        break
    l = [x.strip() for x in s.split()]
    if l[0] == 'Ally':
        for i in range(1, len(l)):
            if not l[i] in allies:
                allies[l[i]] = set()
            for j in range(i+1, len(l)):
                if not l[j] in allies:
                    allies[l[j]] = set()
                allies[l[i]].add(l[j])
                allies[l[j]].add(l[i])
    elif l[0] == 'Enemy':
        a, b = l[1:]
        if not a in enemies:
            enemies[a] = set()
        if not b in enemies:
            enemies[b] = set()
        enemies[a].add(b)
        enemies[b].add(a)
    else:
        ok = True
        countries = l[1:]
        for i in range(len(countries)):
            if is_enemies(allies, enemies, countries[i-1], countries[i], set()) or is_enemies(allies, enemies,  countries[i], countries[i-1], set()):
                ok = False
                break
        if ok:
            print('Okay')
        else:
            print('No')
    # print(allies)
# 1679163, 2022-11-12 09:55:50, PPPPPP (100%)

# def is_enemies(allies, enemies, a, b):
#     if a in enemies.get(b, set()):
#         return True
    
#     for x in allies.get(a, set()):
#         if x in enemies.get(b, set()):
#             return True
#     for x in allies.get(b, set()):
#         if x in enemies.get(a, set()):
#             return True
#     return False

allies = {}
enemies = {}
temp = 0
while True:
    s = input()
    if s == 'End':
        break
    l = [x.strip() for x in s.split()]
    if l[0] == 'Ally':
        for i in range(1, len(l)):
            allies[l[i]] = temp
        temp += 1
            # allies[l[i]].add
            # if not l[i] in allies:
            #     allies[l[i]] = set()
            # for j in range(i+1, len(l)):
            #     if not l[j] in allies:
            #         allies[l[j]] = set()
            #     allies[l[i]].add(l[j])
            #     allies[l[j]].add(l[i])
    elif l[0] == 'Enemy':
        a, b = l[1:]
        # if not a in enemies:
        #     enemies[a] = set()
        # if not b in enemies:
        #     enemies[b] = set()
        # enemies[a].add(b)
        # enemies[b].add(a)
        if not a in allies:
            allies[a] = temp
            temp += 1
        if not b in allies:
            allies[b] = temp
            temp += 1
        if not allies[a] in enemies:
            enemies[allies[a]] = set()
        if not allies[b] in enemies:
            enemies[allies[b]] = set()
        enemies[allies[a]].add(allies[b])
        enemies[allies[b]].add(allies[a])
    else:
        ok = True
        countries = l[1:]
        for i in range(len(countries)):
            # if is_enemies(allies, enemies, countries[i-1], countries[i]):
            if allies.get(countries[i-1], -1) in enemies.get(allies.get(countries[i], -1), set()):
                ok = False
                break
        if ok:
            print('Okay')
        else:
            print('No')
    # print(allies)
    # print(enemies)
    # print()

6532026321
# 1678927, 2022-11-12 09:42:48, P----- (17%)

group = []
enemy = {}
c = input().split()
while c[0] == "Ally":
  group.append(c[1:])
  c = input().split()
while c[0] == "Enemy":
  for i in group:
    if c[1] in i:
      for j in i:
        if j in enemy.keys():
          enemy[j].append(c[2])
        else:
          enemy[j] = [c[2]]
  for i in group:
    if c[2] in i:
      for j in i:
        if j in enemy.keys():
          enemy[j].append(c[1])
        else:
          enemy[j] = [c[1]]
  c = input().split()
while c[0] == "Table":
  a = c[1:]
  a.append(c[1])
  for i in range(len(a)-1):
    if a[i] in enemy.keys():
      if a[i+1] in enemy[a[i]]:
        print("No")
        break
  else:
    print("Okay")
  c = input().split()
  
# 1678969, 2022-11-12 09:45:02, P----- (17%)

group = []
enemy = {}
c = input().split()
while c[0] != "End":
  if c[0] == "Ally":
    group.append(c[1:])
  if c[0] == "Enemy":
    for i in group:
      if c[1] in i:
        for j in i:
          if j in enemy.keys():
            enemy[j].append(c[2])
          else:
            enemy[j] = [c[2]]
    for i in group:
      if c[2] in i:
        for j in i:
          if j in enemy.keys():
            enemy[j].append(c[1])
          else:
            enemy[j] = [c[1]]
  if c[0] == "Table":
    a = c[1:]
    a.append(c[1])
    for i in range(len(a)-1):
      if a[i] in enemy.keys():
        if a[i+1] in enemy[a[i]]:
          print("No")
          break
    else:
      print("Okay")
  c = input().split()
  
# 1679217, 2022-11-12 09:58:58, PPPPPP (100%)

def gp(group, find):
  for i in group:
    if find in i:
      return i
  return [find]

group = []
enemy = {}
c = input().split()
while c[0] == "Ally":
  group.append(c[1:])
  c = input().split()
while c[0] == "Enemy":
  for i in gp(group, c[1]):
    for j in gp(group, c[2]):
      if i in enemy.keys():
        enemy[i].append(j)
      else:
        enemy[i] = [j]
      if j in enemy.keys():
        enemy[j].append(i)
      else:
        enemy[j] = [i]
  c = input().split()
while c[0] == "Table":
  a = c[1:]
  a.append(c[1])
  for i in range(len(a)-1):
    if a[i] in enemy.keys():
      if a[i+1] in enemy[a[i]]:
        print("No")
        break
  else:
    print("Okay")
  c = input().split()
  

6532040021
# 1679270, 2022-11-12 10:01:45, xxxxxx (0%)

ally = {}    
ene = {}

while True:
    s =  input().split()
    if s[0] == 'Ally':
        for c in s[1:]:
            ally[c] = set(s[1:])
    if s[0] == 'Enemy':
        for c in s[1:]:
            lst = [ k for k in s[1:] if k != c ]   
            if c not in ally:
                ally[c] = {c}
            for a in ally[c]:
                if a not in ene:
                    ene[a] = set()
                ene[a].update(lst)
    if s[0] == 'Table':
        lst = [ i for i in s[1:] if i in ally ]
        ok = True
        for i in range(len(lst) - 1):
            if lst[i] in ene[lst[i + 1]] or lst[i + 1] in ene[lst[i]]:
                ok = False
                break
        if lst[0] in ene[lst[len(lst) - 1]] or lst[len(lst) - 1] in ene[lst[0]]: 
            ok = False
        if ok:
            print('Okay')     
        else:
            print('No')                          
# 1679307, 2022-11-12 10:03:22, ------ (0%)

ally = {}    
ene = {}

while True:
    s =  input().split()
    if s[0] == 'Ally':
        for c in s[1:]:
            ally[c] = set(s[1:])
    if s[0] == 'Enemy':
        for c in s[1:]:
            lst = [ k for k in s[1:] if k != c ]   
            if c not in ally:
                ally[c] = {c}
            for a in ally[c]:
                if a not in ene:
                    ene[a] = set()
                ene[a].update(lst)
    if s[0] == 'Table':
        lst = [ i for i in s[1:] if i in ally or i in ene ]
        ok = True
        for i in range(len(lst) - 1):
            if lst[i] in ene[lst[i + 1]] or lst[i + 1] in ene[lst[i]]:
                ok = False
                break
        if lst[0] in ene[lst[len(lst) - 1]] or lst[len(lst) - 1] in ene[lst[0]]: 
            ok = False
        if ok:
            print('Okay')     
        else:
            print('No')  
    else:
        break                        
# 1680073, 2022-11-12 10:40:27, PPPPPP (100%)

ally = {}    
ene = {}

while True:
    s =  input().split()
    if s[0] == 'Ally':
        for c in s[1:]:
            ally[c] = set(s[1:])
    if s[0] == 'Enemy':
        
        # for c in s[1:]:
            # lst = [ k for k in s[1:] if k != c ]
            # # print(">>> ", lst)
            # ene[]
        for c in s[1:]:
            
            if c not in ally: ally[c] = {c}
            lst = [ k for k in s[1:] if k != c ]
            # c, x
            for x in lst:
                if x not in ally: ally[x] = {x}
                for y in ally[c]:
                    if y not in ene: ene[y] = set()
                    ene[y].update(ally[x])
            # print(">>> ", lst)
            # if c not in ally:
            #     ally[c] = {c}
            # for a in ally[c]:
            #     if a not in ene:
            #         ene[a] = set()
            #     ene[a].update(lst)
            
    if s[0] == 'Table':
        # print(ene)
        lst = [ i for i in s[1:] ]
        ok = True
        for i in range(0, len(lst) - 1):
            if lst[i] not in ene or lst[i + 1] not in ene: continue
            if lst[i] in ene[lst[i + 1]] or lst[i + 1] in ene[lst[i]]:
                # print(lst[i], lst[i+1])
                ok = False
                break
        for i in range(1, len(lst)):
            if lst[i] not in ene or lst[i - 1] not in ene: continue
            if lst[i] in ene[lst[i - 1]] or lst[i - 1] in ene[lst[i]]:
                # print(lst[i], lst[i+1])
                ok = False
                break
        if lst[0] in ene and lst[len(lst) - 1] in ene:
            if lst[0] in ene[lst[len(lst) - 1]] or lst[len(lst) - 1] in ene[lst[0]]: 
                ok = False
        if ok:
            print('Okay')     
        else:
            print('No')  
    if len(s) == 1: break                  
    


6532114921
# 1679839, 2022-11-12 10:29:58, P-PPP- (67%)

def f_find(ally ,x):
    for i in range(len(ally)):
        if x in ally[i]: return ally[i]
    return [x]

ally ,enemy ,table = list() ,list() ,list()
while True:
    inp = input().split()
    if inp == ['End']: break
    elif inp[0] == 'Ally': ally.append(inp[1:])
    elif inp[0] == 'Enemy': enemy.append(inp[1:])
    elif inp[0] == 'Table': table.append(inp[1:])

for i in range(len(enemy)):
    for e in enemy[i]:
        ck = True
        for j in range(len(ally)):
            if e in ally[j]: ck = False
        if ck: ally.append([e])

enemy_1 = list()
for i in range(len(ally)):
    x = []
    for e in ally[i]:
        for j in range(len(enemy)):
            if e == enemy[j][0]:
                x += f_find(ally ,enemy[j][1])
            elif e == enemy[j][1]:
                x += f_find(ally ,enemy[j][0])
    enemy_1.append([ally[i] ,x])

for x in table:
    ck = True
    for i in range(len(x)-1):
        a ,b = x[i] ,x[i+1]
        for e in enemy_1:
            if a in e[0] and b in e[1]: ck = False
            elif a in e[1] and b in e[0]: ck = False

    if ck: print('Okay')
    else: print('No')
# 1680221, 2022-11-12 10:47:29, xxxxxx (0%)

def f_find(ally ,x):
    for i in range(len(ally)):
        if x in ally[i]: return ally[i]
    return [x]

ally ,enemy ,table = list() ,list() ,list()
while True:
    inp = input().split()
    if inp == ['End']: break
    elif inp[0] == 'Ally': ally.append(inp[1:])
    elif inp[0] == 'Enemy': enemy.append(inp[1:])
    elif inp[0] == 'Table': table.append(inp[1:])

for i in range(len(enemy)):
    for e in enemy[i]:
        ck = True
        for j in range(len(ally)):
            if e in ally[j]: ck = False
        if ck: ally.append([e])

enemy_1 = list()
for i in range(len(ally)):
    x = []
    for e in ally[i]:
        for j in range(len(enemy)):
            if e == enemy[j][0]:
                x += f_find(ally ,enemy[j][1])
            elif e == enemy[j][1]:
                x += f_find(ally ,enemy[j][0])
    enemy_1.append([ally[i] ,x])

for x in table:
    ck = True
    for i in range(len(x)):
        if i == len(x)-1: a = x[i] ,b = 0
        else: a ,b = x[i] ,x[i+1]
        for e in enemy_1:
            if a in e[0] and b in e[1]: ck = False
            elif a in e[1] and b in e[0]: ck = False

    if ck: print('Okay')
    else: print('No')
# 1680250, 2022-11-12 10:49:24, PPPPPP (100%)

def f_find(ally ,x):
    for i in range(len(ally)):
        if x in ally[i]: return ally[i]
    return [x]

ally ,enemy ,table = list() ,list() ,list()
while True:
    inp = input().split()
    if inp == ['End']: break
    elif inp[0] == 'Ally': ally.append(inp[1:])
    elif inp[0] == 'Enemy': enemy.append(inp[1:])
    elif inp[0] == 'Table': table.append(inp[1:])

for i in range(len(enemy)):
    for e in enemy[i]:
        ck = True
        for j in range(len(ally)):
            if e in ally[j]: ck = False
        if ck: ally.append([e])

enemy_1 = list()
for i in range(len(ally)):
    x = []
    for e in ally[i]:
        for j in range(len(enemy)):
            if e == enemy[j][0]:
                x += f_find(ally ,enemy[j][1])
            elif e == enemy[j][1]:
                x += f_find(ally ,enemy[j][0])
    enemy_1.append([ally[i] ,x])

for x in table:
    ck = True
    for i in range(len(x)):
        if i == len(x)-1: a ,b = x[i] ,x[0]
        else: a ,b = x[i] ,x[i+1]
        for e in enemy_1:
            if a in e[0] and b in e[1]: ck = False
            elif a in e[1] and b in e[0]: ck = False

    if ck: print('Okay')
    else: print('No')

6532143021
# 1679579, 2022-11-12 10:18:30, xPxxxx (17%)

x = input().split()

ally = []
enemy = {}
while x[0] != 'End':
    if x[0] == 'Ally':
        l = []
        for i in range(1, len(x)):
            l.append(x[i])
        ally.append(l)
        
    elif x[0] == 'Enemy':
        l = []
        for i in range(1, len(x)):
            chk = 0
            a = ''
            b = ''
            for j in ally:
                if x[1] in j:
                    a = j
                    chk = 1
                    break
            if not chk:
                ally.append([x[1]])
            
            chk = 0
            for j in ally:
                if x[2] in j:
                    b = j
                    chk = 1
                    break
            if not chk:
                ally.append([x[2]])
            
            # print(a, enemy)
            for j in a:
                if j not in enemy:
                    enemy[j] = b
                else:
                    enemy[j] += b
            
            for j in b:
                if j not in enemy:
                    enemy[j] = a
                else:
                    enemy[j] += a
        
    elif x[0] == 'Table':
        seat = x[1:]
        chk = 0
        for i in range(0, len(seat), 2):
            left = (i-1)%len(seat)
            right = (i+1)%len(seat)
            l = 0
            r = 0
            m = 0
            for j in ally:
                if seat[left] in j:
                    l = 1
                if seat[right] in j:
                    r = 1
                if seat[i] in j:
                    m = 1
            
            # print(seat[left], seat[right], l, r)
            if m == 1 and ((l == 1 and seat[left] in enemy[seat[i]][0]) or (r == 1 and seat[(i+1)%len(seat)] in enemy[seat[i]][0])):
                print('No')
                chk = 1
                break
        if not chk:
            print('Okay')
            
    x = input().split()
# 1680479, 2022-11-12 10:58:16, PPPPPP (100%)

x = input().split()

ally = []
enemy = {}
while x[0] != 'End':
    if x[0] == 'Ally':
        l = []
        for i in range(1, len(x)):
            l.append(x[i])
        ally.append(l)
        # print(ally)
        
    elif x[0] == 'Enemy':
        a = [x[1]]
        b = [x[2]]
        
        for i in ally:
            if x[1] in i:
                a = i
            if x[2] in i:
                b = i
                
        # print(a,b)
        for i in a:
            if i not in enemy:
                enemy[i] = b
            else:
                enemy[i] = enemy[i] + b
            # print(i, enemy[i])
                
        for i in b:
            if i not in enemy:
                enemy[i] = a
                # print(i, enemy[i])
            else:
                enemy[i] = enemy[i] + a
                # print(i, enemy[i])
        
    elif x[0] == 'Table':
        seat = x[1:]
        chk = 0
        for i in range(0, len(seat), 2):
            left = (i-1)%len(seat)
            right = (i+1)%len(seat)
            l = 0
            r = 0
            m = 0
            for j in enemy:
                if seat[left] in j:
                    l = 1
                if seat[right] in j:
                    r = 1
                if seat[i] in j:
                    m = 1
            
            # print(seat[i], seat[left], seat[right], m, l, r)
            # print(seat[left], seat[right], seat[i], enemy[seat[i]])
            if m == 1 and ((l == 1 and seat[left] in enemy[seat[i]]) or (r == 1 and seat[(i+1)%len(seat)] in enemy[seat[i]])):
                print('No')
                chk = 1
                break
        if not chk:
            print('Okay')
            
    x = input().split()
# print(enemy)
# Ally America England Ukraine France
# Ally Russia China
# Enemy China America
# Enemy France Iran
# Enemy Iran Iraq
# Table America Iran England
# Table Thailand Japan China
# End
# 1680509, 2022-11-12 10:59:27, PPPPPP (100%)

x = input().split()

ally = []
enemy = {}
while x[0] != 'End':
    if x[0] == 'Ally':
        l = []
        for i in range(1, len(x)):
            l.append(x[i])
        ally.append(l)
        
    elif x[0] == 'Enemy':
        a = [x[1]]
        b = [x[2]]
        
        for i in ally:
            if x[1] in i:
                a = i
            if x[2] in i:
                b = i
                
        for i in a:
            if i not in enemy:
                enemy[i] = b
            else:
                enemy[i] = enemy[i] + b
                
        for i in b:
            if i not in enemy:
                enemy[i] = a
            else:
                enemy[i] = enemy[i] + a
        
    elif x[0] == 'Table':
        seat = x[1:]
        chk = 0
        for i in range(0, len(seat), 2):
            left = (i-1)%len(seat)
            right = (i+1)%len(seat)
            l = 0
            r = 0
            m = 0
            for j in enemy:
                if seat[left] in j:
                    l = 1
                if seat[right] in j:
                    r = 1
                if seat[i] in j:
                    m = 1
            
            if m == 1 and ((l == 1 and seat[left] in enemy[seat[i]]) or (r == 1 and seat[(i+1)%len(seat)] in enemy[seat[i]])):
                print('No')
                chk = 1
                break
        if not chk:
            print('Okay')
            
    x = input().split()

6532186021
# 1679406, 2022-11-12 10:09:01, PP-PP- (67%)

Ally = {}
Enemy = {}
while True:
    x = input()
    if x == 'End':
        break
    x = x.split()
    if x[0] == 'Ally':
        country_lst = x[1:]
        for country in country_lst:
            ally0 = set(country_lst) - {country}
            Ally[country] = ally0
    if x[0] == 'Enemy':
        country0 = x[1]
        country1 = x[2]
        if country1 in Ally:
            enemy0 = {country1} | Ally[country1]
        else:
            enemy0 = {country1}
        if country0 in Ally:
            enemy1 = {country0} | Ally[country0]
        else:
            enemy1 = {country0}
        Enemy[country0] = enemy0
        Enemy[country1] = enemy1
        if country0 in Ally:
            for country in Ally[country0]:
                if country in Enemy:
                    Enemy[country] = Enemy[country] | enemy0
                else:
                    Enemy[country] = enemy0
        if country1 in Ally:
            for country in Ally[country1]:
                if country in Enemy:
                    Enemy[country] = Enemy[country] | enemy1
                else:
                    Enemy[country] = enemy1
    if x[0] == 'Table':
        no = False
        lst_country = x[1:]
        for i in range(len(lst_country)):
            if lst_country[i] not in Enemy:
                continue
            if i != len(lst_country)-1:
                country = lst_country[i]
                r_country = lst_country[i+1]
                if r_country in Enemy[country]:
                    no = True
                    break
            else:
                country = lst_country[i]
                r_country = lst_country[0]
                if r_country in Enemy[country]:
                    no = True
                    break
        if no:
            print('No')
        else:
            print('Okay')


# 1679570, 2022-11-12 10:17:48, PP-PP- (67%)

Ally = {}
Enemy = {}
while True:
    x = input()
    if x == 'End':
        break
    x = x.split()
    if x[0] == 'Ally':
        country_lst = x[1:]
        for country in country_lst:
            ally0 = set(country_lst) - {country}
            if country in Ally:
                Ally[country] = Ally[country] | ally0
            else:
                Ally[country] = ally0
    if x[0] == 'Enemy':
        country0 = x[1]
        country1 = x[2]
        if country1 in Ally:
            enemy0 = {country1} | Ally[country1]
        else:
            enemy0 = {country1}
        if country0 in Ally:
            enemy1 = {country0} | Ally[country0]
        else:
            enemy1 = {country0}
        Enemy[country0] = enemy0
        Enemy[country1] = enemy1
        if country0 in Ally:
            for country in Ally[country0]:
                if country in Enemy:
                    Enemy[country] = Enemy[country] | enemy0
                else:
                    Enemy[country] = enemy0
        if country1 in Ally:
            for country in Ally[country1]:
                if country in Enemy:
                    Enemy[country] = Enemy[country] | enemy1
                else:
                    Enemy[country] = enemy1
    if x[0] == 'Table':
        no = False
        lst_country = x[1:]
        for i in range(len(lst_country)):
            if lst_country[i] not in Enemy:
                continue
            if i != len(lst_country)-1:
                country = lst_country[i]
                r_country = lst_country[i+1]
                if r_country in Enemy[country]:
                    no = True
                    break
            else:
                country = lst_country[i]
                r_country = lst_country[0]
                if r_country in Enemy[country]:
                    no = True
                    break
        if no:
            print('No')
        else:
            print('Okay')


# 1680125, 2022-11-12 10:42:41, PPPPPP (100%)

Ally = []
Enemy_0 = []
Enemy_1 = []
while True:
    x = input()
    if x == 'End': break
    x = x.split()
    if x[0] == 'Ally':
        lst_country = set(x[1:])
        Ally.append(lst_country)
    elif x[0] == 'Enemy':
        ally0 = {x[1]}
        for ally in Ally:
            if x[1] in ally:
                ally0 = ally0 | ally
                break
        Enemy_0.append(ally0)
        ally1 = {x[2]}
        for ally in Ally:
            if x[2] in ally:
                ally1 = ally1 | ally
                break
        Enemy_1.append(ally1)
    elif x[0] == 'Table':
        No = False
        lst_country = x[1:]
        for i in range(len(lst_country)):
            country = lst_country[i]
            l_country = lst_country[i-1]
            for j in range(len(Enemy_0)):
                if country in Enemy_0[j]:
                    if l_country in Enemy_1[j]:
                        No = True
                        break
                elif country in Enemy_1[j]:
                    if l_country in Enemy_0[j]:
                        No = True
                        break
        if No:
            print('No')
        else:
            print('Okay')
                    
    
        


6230141121
# 1680259, 2022-11-12 10:49:47, ------ (0%)

enemy = []
ally = []
table = []
while True:
    a = input().split()
    b = set()
    c = set()
    if a[0] == "Ally":
        ally.append(set(a[1:]))
    elif a[0] == "Enemy":
        kk = []
        b.add(a[1])
        for ct in ally:
            if a[1] in ct:
                for xx in ct:
                    b.add(xx)
        kk.append(b)
        c.add(a[2])
        for ct in ally:
            if a[2] in ct:
                for xx in ct:
                    c.add(xx)
        kk.append(c)
        enemy.append(kk)    
    elif a[0] == "Table":
        new = a[1:]
        coop = 1
        for i in range(len(new)):
            for j in enemy:
                if new[i] in j[0] and new[i-1] in j[1]:
                    coop = 0
                    break
                elif new[i] in j[1] and new[i-1] in j[0]:
                    coop = 0
                    break
            if coop == 0:
                print("No")
                break
        if coop == 1:
            print("Okey")        
    else:
        break
# 1680267, 2022-11-12 10:50:00, PPPPPP (100%)

enemy = []
ally = []
table = []
while True:
    a = input().split()
    b = set()
    c = set()
    if a[0] == "Ally":
        ally.append(set(a[1:]))
    elif a[0] == "Enemy":
        kk = []
        b.add(a[1])
        for ct in ally:
            if a[1] in ct:
                for xx in ct:
                    b.add(xx)
        kk.append(b)
        c.add(a[2])
        for ct in ally:
            if a[2] in ct:
                for xx in ct:
                    c.add(xx)
        kk.append(c)
        enemy.append(kk)    
    elif a[0] == "Table":
        new = a[1:]
        coop = 1
        for i in range(len(new)):
            for j in enemy:
                if new[i] in j[0] and new[i-1] in j[1]:
                    coop = 0
                    break
                elif new[i] in j[1] and new[i-1] in j[0]:
                    coop = 0
                    break
            if coop == 0:
                print("No")
                break
        if coop == 1:
            print("Okay")        
    else:
        break

6530006421
# 1679862, 2022-11-12 10:30:37, ------ (0%)

# Task Quiz_3_3
# This Code was written by Folkiesss Desu!!

ally = dict()  # {country: {allies,}}
enemy = dict()  # {country: {enemy,}}
seat = dict()  # {country: {nearby,}}

while True:
    line = input().split()
    task = line[0]

    if task == "End":
        break

    if task == "Ally":
        for country in line[1:]:
            if country not in ally:
                ally[country] = set()
            ally[country] |= set([x for x in line[1:] if x != country])

    if task == "Enemy":
        country, war_enemy = line[1:]
        if country not in enemy:
            enemy[country] = set()
        enemy[country] |= {war_enemy}
        if war_enemy in ally:
            enemy[country] |= ally[war_enemy]
        if country in ally:
            for c in ally[country]:
                if c not in enemy:
                    enemy[c] = set()
                enemy[c] |= enemy[country]

    if task == "Table":
        seat = dict()
        nope = False
        seats = line[1:]
        for i in range(len(seats) - 1):
            seat[seats[i]] = {seats[i-1], seats[i+1]}

        seat[seats[-1]] = {seats[-2], seats[0]}

        for country in seat:
            if country in enemy:
                for nearby in seat[country]:
                    if nearby in enemy[country]:
                        nope = True

        print("No" if nope else "OK")
# 1679882, 2022-11-12 10:31:15, PPPPPP (100%)

# Task Quiz_3_3
# This Code was written by Folkiesss Desu!!

ally = dict()  # {country: {allies,}}
enemy = dict()  # {country: {enemy,}}
seat = dict()  # {country: {nearby,}}

while True:
    line = input().split()
    task = line[0]

    if task == "End":
        break

    if task == "Ally":
        for country in line[1:]:
            if country not in ally:
                ally[country] = set()
            ally[country] |= set([x for x in line[1:] if x != country])

    if task == "Enemy":
        country, war_enemy = line[1:]
        if country not in enemy:
            enemy[country] = set()
        enemy[country] |= {war_enemy}
        if war_enemy in ally:
            enemy[country] |= ally[war_enemy]
        if country in ally:
            for c in ally[country]:
                if c not in enemy:
                    enemy[c] = set()
                enemy[c] |= enemy[country]

    if task == "Table":
        seat = dict()
        nope = False
        seats = line[1:]
        for i in range(len(seats) - 1):
            seat[seats[i]] = {seats[i-1], seats[i+1]}

        seat[seats[-1]] = {seats[-2], seats[0]}

        for country in seat:
            if country in enemy:
                for nearby in seat[country]:
                    if nearby in enemy[country]:
                        nope = True

        print("No" if nope else "Okay")


6530014421
# 1680707, 2022-11-12 11:06:42, ------ (0%)

ally={}
enemy={}
while True:
    a=input().strip().split()
    if a[0]!='Ally':
        break
    co=set(a[1:])
    for c in co:
        ally[c]=co-{c,}
b=a
while True:
    if b[0]!='Enemy':
        break
    c1,c2=b[1:]
    if c2 in enemy:
        if c1 in ally:
            enemy[c2]=ally[c1]|{c1}
            for m in ally[c1]:
                if m in enemy:
                    enemy[m].add(c2)
                    if c2 in ally:
                        enemy[m]|=ally[c2]
                else:
                    enemy[m]={c2,}
                    if c2 in ally:
                        enemy[m]|=ally[c2]
        else:
            enemy[c2].add(c1)
    else:
        if c1 in ally:
            enemy[c2]=ally[c1]|{c1}
            for m in ally[c1]:
                if m in enemy:
                    enemy[m].add(c2)
                    if c2 in ally:
                        enemy[m]|=ally[c2]
                else:
                    enemy[m]={c2,}
                    if c2 in ally:
                        enemy[m]|=ally[c2]
        else:
            enemy[c2]={c1}
    if c1 in enemy:
        if c2 in ally:
            enemy[c1]=ally[c2]|{c2}
            for m in ally[c2]:
                if m in enemy:
                    enemy[m].add(c1)
                    if c1 in ally:
                        enemy[m]|=ally[c1]
                else:
                    enemy[m]={c1,}
                    if c1 in ally:
                        enemy[m]|=ally[c1]
        else:
            enemy[c1].add(c2)
    else:
        if c2 in ally:
            enemy[c1]=ally[c2]|{c2}
            for m in ally[c2]:
                if m in enemy:
                    enemy[m].add(c1)
                    if c1 in ally:
                        enemy[m]|=ally[c1]
                else:
                    enemy[m]={c1,}
                    if c1 in ally:
                        enemy[m]|=ally[c1]
        else:
            enemy[c1]={c2,} 
    b=input().strip().split()
c=b
print(enemy)
while True:
    if c[0]=='End':
        break
    c=c[1:]+[c[1]]
    re=True
    for k in range(len(c)-1):
        if c[k+1] in enemy:
            if c[k] in enemy[c[k+1]]:
                re=False
                break
    if re:
        print('Okay')
    else:
        print('No')
    c=input().strip().split()

# 1680743, 2022-11-12 11:07:41, PPPPPP (100%)

ally={}
enemy={}
while True:
    a=input().strip().split()
    if a[0]!='Ally':
        break
    co=set(a[1:])
    for c in co:
        ally[c]=co-{c,}
b=a
while True:
    if b[0]!='Enemy':
        break
    c1,c2=b[1:]
    if c2 in enemy:
        if c1 in ally:
            enemy[c2]=ally[c1]|{c1}
            for m in ally[c1]:
                if m in enemy:
                    enemy[m].add(c2)
                    if c2 in ally:
                        enemy[m]|=ally[c2]
                else:
                    enemy[m]={c2,}
                    if c2 in ally:
                        enemy[m]|=ally[c2]
        else:
            enemy[c2].add(c1)
    else:
        if c1 in ally:
            enemy[c2]=ally[c1]|{c1}
            for m in ally[c1]:
                if m in enemy:
                    enemy[m].add(c2)
                    if c2 in ally:
                        enemy[m]|=ally[c2]
                else:
                    enemy[m]={c2,}
                    if c2 in ally:
                        enemy[m]|=ally[c2]
        else:
            enemy[c2]={c1}
    if c1 in enemy:
        if c2 in ally:
            enemy[c1]=ally[c2]|{c2}
            for m in ally[c2]:
                if m in enemy:
                    enemy[m].add(c1)
                    if c1 in ally:
                        enemy[m]|=ally[c1]
                else:
                    enemy[m]={c1,}
                    if c1 in ally:
                        enemy[m]|=ally[c1]
        else:
            enemy[c1].add(c2)
    else:
        if c2 in ally:
            enemy[c1]=ally[c2]|{c2}
            for m in ally[c2]:
                if m in enemy:
                    enemy[m].add(c1)
                    if c1 in ally:
                        enemy[m]|=ally[c1]
                else:
                    enemy[m]={c1,}
                    if c1 in ally:
                        enemy[m]|=ally[c1]
        else:
            enemy[c1]={c2,} 
    b=input().strip().split()
c=b
while True:
    if c[0]=='End':
        break
    c=c[1:]+[c[1]]
    re=True
    for k in range(len(c)-1):
        if c[k+1] in enemy:
            if c[k] in enemy[c[k+1]]:
                re=False
                break
    if re:
        print('Okay')
    else:
        print('No')
    c=input().strip().split()


6530023021
# 1680575, 2022-11-12 11:02:12, PPPP-- (67%)

x = input().strip()
ally = {}
enemy = {}
while x != 'End':
    a = x.split()
    test = a[0]
    cin = a[1::]
    if test == 'Ally':
        for e in cin:
            for k in cin:
                if e != k:
                    if e not in ally:
                        ally[e] = [k]
                    else:
                        ally[e].append(k) 
    elif test == 'Enemy':
        for e in cin:
            for k in cin:
                if e != k:
                    if e not in enemy:
                        enemy[e] = [k]
                    else:
                        enemy[e].append(k)
        a = cin[0]
        b = cin[1]
        if a in ally:
            for e in ally[a]:
                if e not in enemy:
                    enemy[e] = [b]
                else:
                    if b not in enemy[e]:
                        enemy[e].append(b)
                enemy[b].append(e)
        if b in ally:
            for e in ally[b]:
                if e not in enemy:
                    enemy[e] = [a]
                else:
                    if b not in enemy[e]:
                        enemy[e].append(a)
                enemy[a].append(e)
    else:
        po = True
        for i in range(len(cin)-1):
            if cin[i] in enemy and cin[i+1] in enemy and cin[i] in enemy[cin[i+1]]:
                po = False
            elif cin[i] in enemy and cin[i-1] in enemy and cin[i] in enemy[cin[i-1]]:
                po = False
            if po == False:break
        if po == True:
            print('Okay')
        else:
            print('No')
    x = input().strip()
# 1681034, 2022-11-12 11:17:06, PPPPPP (100%)

x = input().strip()
ally = {}
enemy = {}
while x != 'End':
    a = x.split()
    test = a[0]
    cin = a[1::]
    if test == 'Ally':
        for e in cin:
            for k in cin:
                if e != k:
                    if e not in ally:
                        ally[e] = [k]
                    else:
                        ally[e].append(k) 
    elif test == 'Enemy':
        for e in cin:
            for k in cin:
                if e != k:
                    if e not in enemy:
                        enemy[e] = [k]
                    else:
                        enemy[e].append(k)
        a = cin[0]
        b = cin[1]
        if a in ally:
            for e in ally[a]:
                if e not in enemy:
                    enemy[e] = [b]
                else:
                    if b not in enemy[e]:
                        enemy[e].append(b)
                enemy[b].append(e)
        if b in ally:
            for e in ally[b]:
                if e not in enemy:
                    enemy[e] = [a]
                else:
                    if b not in enemy[e]:
                        enemy[e].append(a)
                enemy[a].append(e)
        for e in enemy:
            for k in enemy[e]:
                if k in ally:
                    for g in ally[k]:
                        if g not in enemy[e]:
                            enemy[e].append(g)
    else:
        po = True
        for i in range(len(cin)-1):
            if cin[i] in enemy and cin[i+1] in enemy and cin[i] in enemy[cin[i+1]]:
                po = False
            elif cin[i] in enemy and cin[i-1] in enemy and cin[i] in enemy[cin[i-1]]:
                po = False
            if po == False:break
        if po == True:
            print('Okay')
        else:
            print('No')
    x = input().strip()


6530072821
# 1679349, 2022-11-12 10:05:49, PPPP-P (83%)

txt = input().strip()
allys = {}
enemys = {}
while txt != 'End':
    countries = txt.split()
    cmd = countries.pop(0)
    if cmd == "Ally":
        for c in countries:
            allys[c]=(set(countries))
    elif cmd == "Enemy":
        vs = []
        for c in countries:
            if c not in allys:
                allys[c]={c}
            vs.append(allys[c])
        party1 = vs[0]
        party2 = vs[1]
        for c in party1:
            if c in enemys:
                enemys[c].update(party2)
            else:
                enemys[c]=party2
        for c in party2:
            if c in enemys:
                enemys[c].update(party1)
            else:
                enemys[c]=party1
               
            
    elif cmd == "Table":
        able = True
        near = [countries[-1]]+countries+[countries[0]]
        for i in range(1,len(near)-1):
            if near[i] in enemys:
                en = enemys[near[i]]
                if near[i-1] in en or near[i+1] in en:
                    able=False
                    break
        print("Okay" if able else "No")
                
    txt = input().strip()

# 1679605, 2022-11-12 10:20:02, PPPPPP (100%)

txt = input().strip()
allys = {}
enemys = {}
while txt != 'End':
    countries = txt.split()
    cmd = countries.pop(0)
    if cmd == "Ally":
        for c in countries:
            allys[c]=(set(countries))
    elif cmd == "Enemy":
        vs = []
        for c in countries:
            if c not in allys:
                allys[c]={c}
            vs.append(allys[c])
        for party in vs:
            en = list(vs)
            en.remove(party)
            for c in party:
                if c in enemys:
                    enemys[c].update(set([ch for e in en for ch in e]))
                else:
                    enemys[c]=set([ch for e in en for ch in e])
               
            
    elif cmd == "Table":
        able = True
        near = [countries[-1]]+countries+[countries[0]]
        for i in range(1,len(near)-1):
            if near[i] in enemys:
                en = enemys[near[i]]
                if near[i-1] in en or near[i+1] in en:
                    able=False
                    break
        print("Okay" if able else "No")
                
    txt = input().strip()


6530092321
# 1681085, 2022-11-12 11:18:30, xxxxxx (0%)

t = input().split()
student = {}
guest = {}
interested = []

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

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

for i in range(int(t[2])):
    temp = input().split()
    faculty = []
    first = True
    for j in temp:
        templst = []
        for k in guest[j]:
            if first:
                faculty.append(student[k])
            else:
                templst.append(student[k])
        if not first:
            faculty = list(set(faculty) & set(templst))
        first = False
    if len(faculty) < 1:
        print('None')
    else:
        print(*sorted(faculty))


# 1681130, 2022-11-12 11:19:38, PPPPPP (100%)

temp = input()
ally = []
enemy = []
table = []
while temp != 'End':
    temp = temp.split()
    if temp[0] == 'Ally':
        ally.append(temp[1:])
    elif temp[0] == 'Enemy':
        enemy.append(temp[1:])
    elif temp[0] == 'Table':
        table.append(temp[1:])
    temp = input()

enemy_adj = []
for i in enemy:
    temp1 = []
    temp2 = []
    for j in ally:
        if i[0] in j:
            temp1.extend(j)
            continue
        if i[1] in j:
            temp2.extend(j)
            continue
    if len(temp1) == 0:
        temp1.append(i[0])
    if len(temp2) == 0:
        temp2.append(i[1])
    enemy_adj.append({1: temp1, 2: temp2})

for k, i in enumerate(table):
    no_flag = False
    for j in enemy_adj:
        for one in list(set(i) & set(j[1])):
            for two in list(set(i) & set(j[2])):
                if abs(i.index(one) - i.index(two)) == 1 or abs(i.index(one) - i.index(two)) == (len(i) - 1):
                    no_flag = True
    if no_flag:
        print('No')
    else:
        print('Okay')

6530113921
# 1679727, 2022-11-12 10:24:37, PP-PP- (67%)

i = input()
a = []
e = []
t = []
while i != 'End':
    i = i.split()
    if i[0] == 'Ally':
        a.append(i[1:])
    elif i[0] == 'Enemy':
        e.append(i[1:])
    else:
        t.append(i[1:])
    i = input()

for i in e:
    for j in i:
        count = 0
        for k in a:
            if j in k:
                count += 1
        if count == 0:
            a.append([j])
en = {}
for i in e:
    for j in range(len(i)):
        for k in a:
            if i[j] in k:
                en[i[j-1]] = k
for i in a:
    for j in i:
        if j not in en:
            for k in i:
                if k in en:
                    en[j] = en[k]
                
for i in t:
    ind = True
    for j in range(len(i)):
        if i[j-1] in en and i[j] in en:
            if i[j] in en[i[j-1]]:
                ind = False
                break
    if ind == False:
        print('No')
    else:
        print('Okay')

# 1680293, 2022-11-12 10:51:06, PPPPPP (100%)

i = input()
a = []
e = []
t = []
while i != 'End':
    i = i.split()
    if i[0] == 'Ally':
        a.append(i[1:])
    elif i[0] == 'Enemy':
        e.append(i[1:])
    else:
        t.append(i[1:])
    i = input()

for i in e: # append country that's not in ally
    for j in i:
        count = 0
        for k in a:
            if j in k:
                count += 1
        if count == 0:
            a.append([j])
en = {} # append country in en
for i in a:
    for j in i:
        en[j] = set()
for i in e:
    for j in i:
        en[j] = set()
        
for i in en: # append enemy country for each country
    for j in e:
        for k in range(len(j)):
            if i == j[k]:
                for l in a:
                    if j[k-1] in l:
                        en[i] = en[i] | set(l)
                        
for i in a: # append enemy country in ally
    for j in i:
        for k in i:
            if k in en:
                en[j] = en[j] | en[k]
                
for i in t:
    ind = True
    for j in range(len(i)):
        if i[j-1] in en and i[j] in en:
            if i[j] in en[i[j-1]]:
                ind = False
                break
    if ind == False:
        print('No')
    else:
        print('Okay')


6530149521
# 1679996, 2022-11-12 10:37:02, P-PPP- (67%)

ans = []
aly = dict()
aly2 = []
ene = dict()
while True :
    n = input().strip()
    if n == 'End' :
        break
    n = n.split()
    if n[0] == 'Ally' :
        for x in n[1::] :
            aly[x] = []
            for y in n[1::] :
                if y != x :
                    aly[x].append(y)
        aly2.append(n[1::])
    elif n[0] == 'Enemy' :
        for x in n[1::] :
            for y in n[1::] :
                if x not in ene and y != x :
                    ene[x] = {y,}
                    if aly.get(y) != None :
                        for k in aly[y] :
                            ene[x].add(k)
                elif y != x :
                    ene[x].add(y)
                    if aly.get(y) != None :
                        for k in aly[y] :
                            ene[x].add(k)
        for x in n[1::] :
            if aly.get(x) != None :
                for y in aly[x]:
                    if x in aly[y] :
                        if y not in ene :
                            ene[y] = ene[x]
                        else :
                            ene[y] = ene[y] | ene[x]
        
        '''
        for x in n[1::] :
            for y in aly :
                if x in aly[y] :
                    for k in n[1::] :
                        if y not in ene and k not in aly[y]:
                            ene[y] = {k,}
                        elif k not in aly[y] :
                            ene[y].add(k)
        '''
    elif n[0] == 'Table' :
        ch = 'Okay'
        for i in range (1,len(n[1::])) :
            if ene.get(n[i]) != None :
                if n[i+1] in ene[n[i]] :
                    ch = 'No'
                
        ans.append(ch)
for x in ans :
    print(x)
               
# 1680156, 2022-11-12 10:43:58, PPPPPP (100%)

ans = []
aly = dict()
aly2 = []
ene = dict()
while True :
    n = input().strip()
    if n == 'End' :
        break
    n = n.split()
    if n[0] == 'Ally' :
        for x in n[1::] :
            aly[x] = []
            for y in n[1::] :
                if y != x :
                    aly[x].append(y)
        aly2.append(n[1::])
    elif n[0] == 'Enemy' :
        for x in n[1::] :
            for y in n[1::] :
                if x not in ene and y != x :
                    ene[x] = {y,}
                    if aly.get(y) != None :
                        for k in aly[y] :
                            ene[x].add(k)
                elif y != x :
                    ene[x].add(y)
                    if aly.get(y) != None :
                        for k in aly[y] :
                            ene[x].add(k)
        for x in n[1::] :
            if aly.get(x) != None :
                for y in aly[x]:
                    if x in aly[y] :
                        if y not in ene :
                            ene[y] = ene[x]
                        else :
                            ene[y] = ene[y] | ene[x]

    elif n[0] == 'Table' :
        ch = 'Okay'
        for i in range (1,len(n[1::])) :
            if ene.get(n[i]) != None :
                if n[i+1] in ene[n[i]] :
                    ch = 'No'
        if ene.get(n[1]) != None :
            if n[-1] in ene[n[1]] :
                ch = 'No'
        ans.append(ch)
for x in ans :
    print(x)
                


6530174121
# 1679319, 2022-11-12 10:03:48, PPPPPP (100%)

info = input()
ally_dict = {}
enemy_dict = {}
while info != "End":
    info = info.split()
    if info[0] == "Ally":
        allies = info[1:]
        for e in allies:
            for f in allies:
                if e not in ally_dict:
                    ally_dict[e] = []
                if e != f:
                    ally_dict[e].append(f)
    elif info[0] == "Enemy":
        enemies = info[1:]
        for e in enemies:
            for f in enemies:
                if e not in enemy_dict:
                    enemy_dict[e] = set()
                if e != f:
                    enemy_dict[e].add(f)
                    if f in ally_dict:
                        for g in ally_dict[f]:
                            enemy_dict[e].add(g)
            if e in ally_dict:
                for g in ally_dict[e]:
                    if g not in enemy_dict:
                        enemy_dict[g] = set()
                    for h in enemy_dict[e]:
                        enemy_dict[g].add(h)
    elif info[0] == "Table":
        c = 0
        table = [info[-1]] + info[1:] + [info[1]]
        for i in range(len(table)-1):
            if table[i] in enemy_dict:
                if table[i+1] in enemy_dict[table[i]]:
                    print("No")
                    c = 1
                    break
        if c == 0:
            print("Okay")
    info = input()
# 1680656, 2022-11-12 11:04:38, PPPPPP (100%)

info = input()
ally_dict = {}
enemy_dict = {}
while info != "End":
    info = info.split()
    if info[0] == "Ally":
        allies = info[1:]
        for e in allies:
            for f in allies:
                if e not in ally_dict:
                    ally_dict[e] = []
                if e != f:
                    ally_dict[e].append(f)
    elif info[0] == "Enemy":
        enemies = info[1:]
        for e in enemies:
            for f in enemies:
                if e not in enemy_dict:
                    enemy_dict[e] = set()
                if e != f:
                    enemy_dict[e].add(f)
                    if f in ally_dict:
                        for g in ally_dict[f]:
                            enemy_dict[e].add(g)
            if e in ally_dict:
                for g in ally_dict[e]:
                    if g not in enemy_dict:
                        enemy_dict[g] = set()
                    for h in enemy_dict[e]:
                        enemy_dict[g].add(h)
    elif info[0] == "Table":
        c = 0
        table = [info[-1]] + info[1:] + [info[1]]
        for i in range(len(table)-1):
            if table[i] in enemy_dict:
                if table[i+1] in enemy_dict[table[i]]:
                    print("No")
                    c = 1
                    break
        if c == 0:
            print("Okay")
    info = input()

6530181521
# 1679361, 2022-11-12 10:06:22, PPPPPP (100%)

def check(t) :
    for i in range(len(t)-1) :
        if t[i] in enemy[t[i+1]] :
            return False
    return True

def team(c) :
    for j in ally :
        if i in ally[j] :
            return j
    return 0
        
ally = {}
enemy = {0:set()}
c = 1

while True :
    x = input().strip().split()
    if x[0] not in ['Ally'] :
        break
    ally[c] = set(x[1:])
    enemy[c] = set()
    c += 1

while x[0] == 'Enemy' :
    a,b = x[1:]
    y,z = 0,0
    for k in ally :
        if a in ally[k] :
            y = k
        elif b in ally[k] :
            z = k
    if y == 0 :
        ally[c] = x[1]
        y = c
        enemy[c] = set()
        c += 1
    if z == 0 :
        ally[c] = x[2]
        z = c
        enemy[c] = set()
        c += 1
    enemy[y].add(z)
    enemy[z].add(y)
    x = input().strip().split()
    
while x[0] != 'End':
    table = x[1:]+x[1:2]
    t = []
    for i in table:
        t.append(team(i))
    if check(t) :
        print('Okay')
    else :
        print('No')
    x = input().strip().split()
            

# 1681401, 2022-11-12 11:25:58, PPPPPP (100%)

def ch(t):
    for i in range(len(t)-1):
        if t[i] in enemy[t[i+1]]:
            return False
    return True
def t1(i,c):
    for j in ally:
        if i in ally[j]:
            return j,c
    cr([i])
    c+=1
    return c-1,c
def ad(i,j):
    enemy[i].add(j)
def cr(a):
    ally[c]=set(a)
    enemy[c]=set()
    return c
ally={}
enemy={0:set()}
c=1
while True:
    x = input().split()
    if x[0]!='Ally':break
    cr(x[1:])
    c+=1
while x[0]=='Enemy':
    a,b=x[1:]
    y,c=t1(a,c)
    z,c=t1(b,c)
    ad(y,z)
    ad(z,y)
    x=input().split()
while x[0]!='End':
    table=x[1:]+x[1:2]
    t=[t1(i,c)[0] for i in table]
    if ch(t):print('Okay')
    else:print('No')
    x=input().split()

6531309821
# 1679555, 2022-11-12 10:16:43, PPPP-- (67%)

s = input().split()
alliance = {}
enemies = {}

while s[0] != "End":
    cmd = s[0]
    if cmd == "Ally":
        for country in s[1:]:
            ally = s[1:]
            ally.remove(country)
            alliance[country] = set(ally)
    elif cmd == "Enemy":
        e1, e2 = s[1:]
        if e1 not in enemies:
            enemies[e1] = set()
        if e2 not in enemies:
            enemies[e2] = set()
        enemies[e1].add(e2); enemies[e2].add(e1)
        if e1 in alliance:
            enemies[e2].update(alliance[e1])
        if e2 in alliance:
            enemies[e1].update(alliance[e2])
    elif cmd == "Table":
        countries = s[1:]
        check = True
        for i in range(len(countries)):
            if countries[i-1] in enemies:
                if countries[i] in enemies[countries[i-1]]:
                    print("No")
                    check = False
                    break
            if countries[i] in enemies:
                if countries[i-1] in enemies[countries[i]]:
                    print("No")
                    check = False
                    break
        if check:
            print("Okay")
    
    s = input().split()
# 1679907, 2022-11-12 10:32:13, PPPPPP (100%)

#----------------------------------------------
def make_enemy(c1, c2, alliance, enemies):
    if c1 not in enemies: enemies[c1] = set()
    if c2 not in enemies: enemies[c2] = set()
    enemies[c1].add(c2); enemies[c2].add(c1)

    if c1 in alliance:
        enemies[c2].update(alliance[c1])
    if c2 in alliance:
        enemies[c1].update(alliance[c2])
#----------------------------------------------
s = input().split()
alliance = {}
enemies = {}

while s[0] != "End":
    cmd = s[0]
    if cmd == "Ally":
        for country in s[1:]:
            alliance[country] = s[1:]
    
    elif cmd == "Enemy":
        c1, c2 = s[1:]
        make_enemy(c1, c2, alliance, enemies)
        if c1 in alliance:
            for ally in alliance[c1]:
                make_enemy(ally, c2, alliance, enemies)
        if c2 in alliance:
            for ally in alliance[c2]:
                make_enemy(ally, c1, alliance, enemies)
    
    elif cmd == "Table":
        countries = s[1:]
        check = True
        for i in range(len(countries)):
            if countries[i-1] in enemies:
                if countries[i] in enemies[countries[i-1]]:
                    print("No")
                    check = False
                    break
        if check:
            print("Okay")
    
    s = input().split()

6531332121
# 1679956, 2022-11-12 10:35:10, PPP--- (50%)

countries_group = []

while 1:
    s_input = input().split()

    if s_input[0] == 'End':
        break

    elif s_input[0] == 'Ally':
        allies = s_input[1:]
        allies_list = []
        for ally in allies:
            allies_list.append(ally)
        countries_group.append(allies_list)

    elif s_input[0] == 'Enemy':
        have_group_1 = False
        have_group_2 = False
        country1, country2 = s_input[1], s_input[2]
        for group in countries_group:
            if country1 in group:
                have_group_1 = True
            if country2 in group:
                have_group_2 = True
        if have_group_1 == False:
            countries_group.append([country1])
        if have_group_2 == False:
            countries_group.append([country2])

    elif s_input[0] == 'Table':
        table_order = [s_input[-1]] + s_input[1:] + [s_input[1]]
        valid = True
        for i in range(1, len(table_order) - 1):
            left_country = table_order[i - 1]
            me_country = table_order[i]
            right_country = table_order[i + 1]
            left_ally_index = -1
            me_ally_index = -1
            right_ally_index = -1

            # print(left_country, me_country, right_country)

            for group in countries_group:
                if left_country in group:
                    left_ally_index = countries_group.index(group)
                if me_country in group:
                    me_ally_index = countries_group.index(group)
                if right_country in group:
                    right_ally_index = countries_group.index(group)

                # print(left_ally_index, me_ally_index, right_ally_index)

            # might wrong
            if left_ally_index >= 0 and me_ally_index >= 0:
                if left_ally_index != me_ally_index:
                    valid = False
                    print('No')
                    break

            if right_ally_index >= 0 and me_ally_index >= 0:
                if right_ally_index != me_ally_index:
                    valid = False
                    print('No')
                    break

        if valid == True:
            print('Okay')
        # if valid == False:
        #     break
        # else:
        #     print('Okay')

# print(countries_group)

# 1680924, 2022-11-12 11:14:13, PPPPPP (100%)

countries_group = []
enemy_of_countries = {}

while 1:
    s_input = input().split()

    if s_input[0] == 'End':
        break

    elif s_input[0] == 'Ally':
        allies = s_input[1:]
        allies_list = []
        for ally in allies:
            allies_list.append(ally)
        countries_group.append(allies_list)

    elif s_input[0] == 'Enemy':
        have_group_1 = False
        have_group_2 = False
        country1, country2 = s_input[1], s_input[2]
        for group in countries_group:
            if country1 in group:
                have_group_1 = True
            if country2 in group:
                have_group_2 = True

        if have_group_1 == False:
            countries_group.append([country1])
        if have_group_2 == False:
            countries_group.append([country2])

        # calculate enemy index try2
        # create empty dict for every country:
        for group in countries_group:
            for country in group:
                if country not in enemy_of_countries:
                    enemy_of_countries[country] = set()

        for group in countries_group:
            if country1 in group:
                index1 = countries_group.index(group)
            if country2 in group:
                index2 = countries_group.index(group)

        for country in countries_group[index1]:
            enemy_of_countries[country].update(countries_group[index2])

            # print(enemy_of_countries[country])
            # print(countries_group[index2])

        for country in countries_group[index2]:
            enemy_of_countries[country].update(countries_group[index1])

            # print(enemy_of_countries[country])
            # print(countries_group[index1])

    elif s_input[0] == 'Table':
        table_order = [s_input[-1]] + s_input[1:] + [s_input[1]]
        valid = True
        for i in range(1, len(table_order) - 1):
            left_country = table_order[i - 1]
            me_country = table_order[i]
            right_country = table_order[i + 1]
            left_ally_index = -1
            me_ally_index = -1
            right_ally_index = -1

            # print(left_country, me_country, right_country)

            for group in countries_group:
                if left_country in group:
                    left_ally_index = countries_group.index(group)
                if me_country in group:
                    me_ally_index = countries_group.index(group)
                if right_country in group:
                    right_ally_index = countries_group.index(group)

                # print(left_ally_index, me_ally_index, right_ally_index)

            # might wrong
            if me_country not in enemy_of_countries:
                pass
            elif left_country in enemy_of_countries[me_country] or right_country in enemy_of_countries[me_country]:
                valid = False
                print('No')
                break
            # if left_ally_index >= 0 and me_ally_index >= 0:
            #     if left_ally_index != me_ally_index:
            #         valid = False
            #         print('No')
            #         break

            # if right_ally_index >= 0 and me_ally_index >= 0:
            #     if right_ally_index != me_ally_index:
            #         valid = False
            #         print('No')
            #         break

        if valid == True:
            print('Okay')
        # if valid == False:
        #     break
        # else:
        #     print('Okay')

# print(countries_group)
# print(enemy_of_countries)


6531333821
# 1679054, 2022-11-12 09:49:46, PPPPPP (100%)

data = input().split()
allyDict = {}
enemyDict = {}
while(data[0] != "End"):
    if(data[0] == "Ally"):
        for country in data[1:]:
            allyDict[country] = set(data[1:])
    elif(data[0] == "Enemy"):
        for country in data[1:]:
            if(country not in allyDict):
                allyDict[country] = {country}
        for ally in allyDict[data[1]]:
            if(ally not in enemyDict):
                enemyDict[ally] = set()
            enemyDict[ally].update(allyDict[data[2]])
        for ally in allyDict[data[2]]:
            if(ally not in enemyDict):
                enemyDict[ally] = set()
            enemyDict[ally].update(allyDict[data[1]])
    elif(data[0] == "Table"):
        countryList = data[1:]
        isOkay = True
        for i in range(-1, len(countryList)-1):
            if(countryList[i] in enemyDict):
                if(countryList[i+1] in enemyDict[countryList[i]]):
                    isOkay = False
        if(isOkay):
            print("Okay")
        else:
            print("No")
    data = input().split()
# 1679473, 2022-11-12 10:12:34, PPPPPP (100%)

allyDict = {}
enemyDict = {}
data = input().split()
while(data[0] != "End"):
    if(data[0] == "Ally"):
        for country in data[1:]:
            allyDict[country] = set(data[1:])
    elif(data[0] == "Enemy"):
        enemies = [data[1], data[2]]
        for country in enemies:
            if(country not in allyDict):
                allyDict[country] = {country}
        for i in range(-1, 1):
            for ally in allyDict[enemies[i]]:
                if(ally not in enemyDict):
                    enemyDict[ally] = set()
                enemyDict[ally].update(allyDict[enemies[i+1]])
    elif(data[0] == "Table"):
        countryList = data[1:]
        isOkay = True
        for i in range(len(countryList)):
            if(countryList[i] in enemyDict):
                if(countryList[i-1] in enemyDict[countryList[i]]):
                    print("No")
                    isOkay = False
                    break
        if(isOkay):
            print("Okay")
    data = input().split()

6531337321
# 1678844, 2022-11-12 09:37:31, xxxxxx (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')
# 1679873, 2022-11-12 10:30:50, PPPPPP (100%)

def get_enemies(country, allies, enemies):
    ally = {country}
    enemy = set()
    for a in allies:
        if country in a:
            ally = ally.union(a)
    for a in ally:
        for b in enemies:
            if a in b:
                c = b.copy()
                c.remove(a)
                enemy = enemy.union(c)
    for a in enemy:
        for b in allies:
            if a in b:
                enemy = enemy.union(b)
    return enemy


allies = []
enemies = []

while True:
    input_ = input().split()
    if input_[0] == 'End':
        break
    elif input_[0] == 'Ally':
        allies.append(input_[1:])
    elif input_[0] == 'Enemy':
        enemies.append(input_[1:])

    elif input_[0] == 'Table':
        table = input_[1:]
        for i in range(len(table)-1):
            country = table[i]
            not_allow = get_enemies(country, allies, enemies)
            if table[i+1] in not_allow:
                print('No')
                break
        else:
            if table[0] in get_enemies(table[-1], allies, enemies):
                print('No')
            else:
                print('Okay')
            


6531340121
# 1679370, 2022-11-12 10:06:49, PP---- (33%)

a = [e for e in input().split()]
l = []
l1 = []
while a[0] == 'Ally':
    l.append(a[1:])
    a = [e for e in input().split()]
while a[0] == "Enemy":
    ll = []
    for i in range(len(l)):
        for k in range(len(l[i])):
            if l[i][k] == a[1]:
                ll.append(l[i])
    if len(ll)==0:
        ll.append([a[1]])
    for i in range(len(l)):
        for k in range(len(l[i])):
            if l[i][k] == a[2]:
                ll.append(l[i])
    if len(ll) == 1:
        ll.append([a[2]])
    l1.append(ll)
    a = [e for e in input().split()]
while a[0] == "Table":
    x = True
    for j in range(1,len(a)-1):
        for k in l1:
            if (a[j] in k[0] and a[j+1] in k[1]) or (a[j] in k[1] and a[j+1] in k[0]):
                print("No")
                x = False
                break
    for s in l1:
        if( (a[-1] in s[0] and a[1] in s[1]) or (a[-1] in s[1] and a[1] in s[0])) and x:
                print("No")
                x = False
                break
    if x:
        print("Okay")
    a = [e for e in input().split()]
# 1679385, 2022-11-12 10:07:52, PPPPPP (100%)

a = [e for e in input().split()]
l = []
l1 = []
while a[0] == 'Ally':
    l.append(a[1:])
    a = [e for e in input().split()]
while a[0] == "Enemy":
    ll = []
    for i in range(len(l)):
        for k in range(len(l[i])):
            if l[i][k] == a[1]:
                ll.append(l[i])
    if len(ll)==0:
        ll.append([a[1]])
    for i in range(len(l)):
        for k in range(len(l[i])):
            if l[i][k] == a[2]:
                ll.append(l[i])
    if len(ll) == 1:
        ll.append([a[2]])
    l1.append(ll)
    a = [e for e in input().split()]
while a[0] == "Table":
    x = True
    for j in range(1,len(a)-1):
        for k in l1:
            if (a[j] in k[0] and a[j+1] in k[1]) or (a[j] in k[1] and a[j+1] in k[0]):
                print("No")
                x = False
                break
        if not x:
            break
    for s in l1:
        if( (a[-1] in s[0] and a[1] in s[1]) or (a[-1] in s[1] and a[1] in s[0])) and x:
                print("No")
                x = False
                break
    if x:
        print("Okay")
    a = [e for e in input().split()]

6532082421
# 1679454, 2022-11-12 10:11:29, PPPPPP (100%)

cmd = input()
cnt = 0
ally = dict()
enemy = dict()
while(cmd != 'End'):
    cmd = cmd.split()
    if(cmd[0] == 'Ally'):
        group = cmd[1:]
        for i in range(len(group)):
            if(not group[i] in ally): ally[group[i]] = set()
            ally[group[i]].update(group[0:i])
            ally[group[i]].update(group[i+1:])
    elif(cmd[0] == 'Enemy'):
        c1,c2 = cmd[1:]
        if(not c1 in ally):
            ally[c1] = set()
        if(not c2 in ally):
            ally[c2] = set()
        u = ally[c1]
        u.add(c1)
        for e1 in u:
            if(not e1 in enemy): enemy[e1] = set()
            enemy[e1].add(c2)
            for e2 in ally[c2]:
                enemy[e1].add(e2)
        u = ally[c2]
        u.add(c2)
        for e1 in u:
            if(not e1 in enemy): enemy[e1] = set()
            enemy[e1].add(c1)
            # print(e1,enemy[e1])
            for e2 in ally[c1]:
                enemy[e1].add(e2)
    elif(cmd[0] == "Table"):
        # print(enemy) 
        lst = cmd[1:]
        valid = True
        for i in range(len(lst)):
            if(not lst[i] in enemy):
                continue
            if(lst[i-1] in enemy[lst[i]]):
                valid = False
                break
        if(valid):
            print('Okay')
        else:
            print('No')
    
    cmd = input()

# 1679455, 2022-11-12 10:11:38, PPPPPP (100%)

cmd = input()
cnt = 0
ally = dict()
enemy = dict()
while(cmd != 'End'):
    cmd = cmd.split()
    if(cmd[0] == 'Ally'):
        group = cmd[1:]
        for i in range(len(group)):
            if(not group[i] in ally): ally[group[i]] = set()
            ally[group[i]].update(group[0:i])
            ally[group[i]].update(group[i+1:])
    elif(cmd[0] == 'Enemy'):
        c1,c2 = cmd[1:]
        if(not c1 in ally):
            ally[c1] = set()
        if(not c2 in ally):
            ally[c2] = set()
        u = ally[c1]
        u.add(c1)
        for e1 in u:
            if(not e1 in enemy): enemy[e1] = set()
            enemy[e1].add(c2)
            for e2 in ally[c2]:
                enemy[e1].add(e2)
        u = ally[c2]
        u.add(c2)
        for e1 in u:
            if(not e1 in enemy): enemy[e1] = set()
            enemy[e1].add(c1)
            for e2 in ally[c1]:
                enemy[e1].add(e2)
    elif(cmd[0] == "Table"):
        lst = cmd[1:]
        valid = True
        for i in range(len(lst)):
            if(not lst[i] in enemy):
                continue
            if(lst[i-1] in enemy[lst[i]]):
                valid = False
                break
        if(valid):
            print('Okay')
        else:
            print('No')
    
    cmd = input()

6532123521
# 1679308, 2022-11-12 10:03:24, PPPPPP (100%)

ally = []
enemy = []
while True:
    inp = input().strip()
    if(inp == 'End'):
        break
    inp = inp.split()
    cmd = inp[0]
    if(cmd == 'Ally'):
        ally.append(set(inp[1:]))
    elif(cmd == 'Enemy'):
        set_a, set_b = set([inp[1]]), set([inp[2]])
        for allied_countries in ally:
            if(inp[1] in allied_countries):
                set_a = set(allied_countries)
            elif(inp[2] in allied_countries):
                set_b = set(allied_countries)
        enemy.append((set_a, set_b))
    elif(cmd == 'Table'):
        chk = True
        countries = inp[1:].copy()
        length = len(countries)
        for i in range(length):
            if(not chk):
                break
            for team_a, team_b in enemy:
                if(countries[i] in team_a and (countries[i-1] in team_b or countries[(i+1) % length] in team_b)):
                    chk = False
                    break
                elif(countries[i] in team_b and (countries[i-1] in team_a or countries[(i+1) % length] in team_a)):
                    chk = False
                    break
        print('Okay' if chk else 'No')

# 1679426, 2022-11-12 10:10:12, PPPPPP (100%)

ally, enemy = [], []
while True:
    inp = input().strip()
    if(inp == 'End'): break
    inp = inp.split()
    cmd = inp[0]
    if(cmd == 'Ally'): ally.append(set(inp[1:]))
    elif(cmd == 'Enemy'):
        set_a, set_b = set([inp[1]]), set([inp[2]])
        for allied_countries in ally:
            if(inp[1] in allied_countries): set_a = set(allied_countries)
            elif(inp[2] in allied_countries): set_b = set(allied_countries)
        enemy.append((set_a, set_b))
    elif(cmd == 'Table'):
        chk = True; countries = inp[1:].copy(); length = len(countries)
        for i in range(length):
            if(not chk): break
            for team_a, team_b in enemy:
                if((countries[i] in team_a and (countries[i-1] in team_b or countries[(i+1) % length] in team_b)) or (countries[i] in team_b and (countries[i-1] in team_a or countries[(i+1) % length] in team_a))): chk = False; break
        print('Okay' if chk else 'No')


6532157921
# 1679251, 2022-11-12 10:01:00, P-PPP- (67%)

d = {}
rv = {}
enm = {}
now = 0
while(1):
    a = [i.strip() for i in input().split()]
    if a[0]=='Ally':
        d[now] = set()
        enm[now] = set()
        for i in range(1,len(a)):
            rv[a[i]] = now
            d[now].add(a[i])
        now += 1
    if a[0]=='Enemy':
        if a[1] not in rv:
            d[now] = set()
            enm[now] = set()
            rv[a[1]] = now
            d[now].add(a[1])
            now+=1
        if a[2] not in rv:
            d[now] = set()
            enm[now] = set()
            rv[a[2]] = now
            d[now].add(a[2])
            now+=1
        enm[rv[a[1]]].add(rv[a[2]])
        enm[rv[a[2]]].add(rv[a[1]])
    if a[0]=='Table':
        ch = 1
        for i in range(2,len(a)):
            if a[i] not in rv or a[i-1] not in rv: continue
            if rv[a[i]] in enm[rv[a[i-1]]]:
                ch = 0
                break
        if ch:
            print('Okay')
        else:
            print('No')
    if a[0]=='End':
        break

# Ally A E U F
# Ally R C
# Enemy C A
# Enemy F I
# Enemy I Ir
# Table A E Ic I R Ir
# Table A E R
# Table A E T R C I C J
# End
# 1679290, 2022-11-12 10:02:21, PPPPPP (100%)

d = {}
rv = {}
enm = {}
now = 0
while(1):
    a = [i.strip() for i in input().split()]
    if a[0]=='Ally':
        d[now] = set()
        enm[now] = set()
        for i in range(1,len(a)):
            rv[a[i]] = now
            d[now].add(a[i])
        now += 1
    if a[0]=='Enemy':
        if a[1] not in rv:
            d[now] = set()
            enm[now] = set()
            rv[a[1]] = now
            d[now].add(a[1])
            now+=1
        if a[2] not in rv:
            d[now] = set()
            enm[now] = set()
            rv[a[2]] = now
            d[now].add(a[2])
            now+=1
        enm[rv[a[1]]].add(rv[a[2]])
        enm[rv[a[2]]].add(rv[a[1]])
    if a[0]=='Table':
        ch = 1
        a.append(a[1])
        for i in range(2,len(a)):
            if a[i] not in rv or a[i-1] not in rv: continue
            if rv[a[i]] in enm[rv[a[i-1]]]:
                ch = 0
                break
        if ch:
            print('Okay')
        else:
            print('No')
    if a[0]=='End':
        break

# Ally A E U F
# Ally R C
# Enemy C A
# Enemy F I
# Enemy I Ir
# Table A E Ic I R Ir
# Table A E R
# Table A E T R C I C J
# End

6530019621
# 1680589, 2022-11-12 11:02:43, PPPPPP (100%)

x = input().strip().split()
Type = x[0].strip()
AllAlly = dict()
AllEnemy = dict()
AllCountry = []
while Type == 'Ally' or Type == 'Enemy':
    if Type == 'Ally':
        AllCountryPhak = []
        for i in range(1,len(x)):
            AllCountryPhak.append(x[i].strip())
        for Country in AllCountryPhak:
            if Country not in AllAlly:
                AllAlly[Country] = []
            if Country not in AllCountry:
                AllCountry.append(Country)
        for Country in AllCountryPhak:
           for Ally in AllCountryPhak:
               if Ally != Country and Ally not in AllAlly[Country]:
                   AllAlly[Country].append(Ally)
        
                   
#         print('Ally',AllAlly)
                   
    elif Type == 'Enemy':
        AllCountryPhak = []
        for i in range(1,len(x)):
            AllCountryPhak.append(x[i].strip())
        for Country in AllCountryPhak:
            if Country not in AllEnemy:
                AllEnemy[Country] = []
            if Country not in AllCountry:
                AllCountry.append(Country)
        for Country in AllCountryPhak:
           for Enemy in AllCountryPhak:
               if Enemy != Country and Enemy not in AllEnemy[Country]:
                   AllEnemy[Country].append(Enemy)
    
#         print('Enemy',AllEnemy)
        
    x = input().strip().split()
    Type = x[0].strip()
    
# หาศัตรูของพันธมิตรเพิ่มใน AllEnemy

for Country in AllCountry:
    if Country not in AllEnemy:
        AllEnemy[Country] = []

# print(AllEnemy,'\n')

for Country in AllEnemy:
    EnemyGroup = AllEnemy[Country]
    for Enemy in EnemyGroup:
        if Enemy in AllAlly:
            EnemyAllyGroup = AllAlly[Enemy]
            for EnemyAlly in EnemyAllyGroup:
                if EnemyAlly not in AllEnemy[Country]:
                    AllEnemy[Country].append(EnemyAlly)

#เติมศัตรูขอวพันธมิตรให้

for Country in AllEnemy:
    if Country in AllAlly:
        for Ally in AllAlly[Country]:
            AllyEnemyGroup = AllEnemy[Ally]
            for AllyEnemy in AllyEnemyGroup:
                if AllyEnemy not in AllEnemy[Country]:
                    AllEnemy[Country].append(AllyEnemy)
                                        
for Country in AllEnemy:
    AllEnemy[Country].sort()
#     print(Country)
#     print(AllEnemy[Country])
    
#มาเลือกโต๊ะกัน

#หาว่าเป็นศัตรูกันมั้ย

def Check_Enemy(Country1,Country2,count):
    if Country1 in AllEnemy:
        Enemy_Country1 = AllEnemy[Country1]
        if Country2 in Enemy_Country1:
            count += 1
    return count

Ans = []
while x[0] != 'End':
    Table = x[0].strip()
    TableGroup = []
    for i in range(1,len(x)):
        TableGroup.append(x[i].strip())
    TableGroup.append(x[1])
#     print(TableGroup)
    count = 0
    for i in range(len(TableGroup)-1):
        count = Check_Enemy(TableGroup[i],TableGroup[i+1],count)
    if count != 0:
        Ans.append('No')
    else:
        Ans.append('Okay')
        
    x = input().strip().split()
for ans in Ans:
    print(ans)



6530028221
# 1679855, 2022-11-12 10:30:26, PPPPPP (100%)

group=[]
enemy=[]
s=str(input())
while s!='End' :
    a=[str(e) for e in s.split()]
    if a[0]=='Ally' :
        group.append(a[1::])
    if a[0]=='Enemy' :
        for k in a[1::] :
            c=0
            for q in group :
                if k in q :
                    c+=1
            if c==0 :
                group.append([k])
        p=[]
        for k in group :
            if a[1] in k :
                p.append(k)
        for k in group :
            if a[2] in k :
                p.append(k)
        enemy.append(p)
    if a[0]=='Table' :
        b=a[1::]
        z=0
        for i in range(len(b)) :
            x=[]
            y=[]
            for k in group :
                if b[i] in k :
                    x=k
                if b[(i+1)%len(b)] in k :
                    y=k
            if [x,y] in enemy or [y,x] in enemy :
                print('No')
                z+=1
                break
        if z==0 :
            print('Okay')
                    
    
    
    s=str(input())




6530059721
# 1679673, 2022-11-12 10:22:58, PPPPPP (100%)

#good_LUCK

land = {}

inp = input().strip().split()
while inp[0]!="End":
    if inp[0] == "Ally":
        for c in inp[1::]:
            land[c] = {"ally":set(inp[1::]),"ene":set()}

    elif inp[0] == "Enemy":
        c1,c2 = inp[1],inp[2]
        if c1 not in land:
            land[c1] = {"ally":set(),"ene":set()}
        if c2 not in land:
            land[c2] = {"ally":set(),"ene":set()} 
        
        land[c1]["ene"] = land[c1]["ene"].union(land[c2]["ally"])
        land[c1]["ene"].add(c2)
        for l in land[c1]["ally"]:
            land[l]["ene"] = land[c1]["ene"]
        
        land[c2]["ene"] = land[c2]["ene"].union(land[c1]["ally"])
        land[c2]["ene"].add(c1)
        for l in land[c2]["ally"]:
            land[l]["ene"] = land[c2]["ene"]
    
    elif inp[0] == "Table":
        like = inp[1::]+inp[1:2:]
        for i in range(len(like)-1):
            ok = True
            c1 = like[i]
            c2 = like[i+1]
            
            if c1 in land and c2 in land[c1]["ene"]:
                ok = False
                break
            if c2 in land and c1 in land[c2]["ene"]:
                ok = False
                break
        if ok:
            print("Okay")
        else:
            print("No")
        
    
    inp = input().strip().split()
    

    
'''
Ally America England Ukraine France
Ally Russia China
Enemy China America
Enemy France Iran
Enemy Iran Iraq
End
'''


6530112221
# 1679413, 2022-11-12 10:09:25, PPPPPP (100%)

status = {}

inp = input().split()
enemy = {}
ally = {}
while len(inp) != 1:
    command = inp[0]
    countries = inp[1:]
    if command == 'Ally':
        for country in countries:
            ally[country] = {c for c in countries}
            
    elif command == 'Enemy':
        countA = inp[1]
        countB = inp[2]
        if countA in ally:
            countA = ally[countA]
        else:
            countA = set([countA])
        if countB in ally:
            countB = ally[countB]
        else:
            countB = set([countB])
        for c in countA:
            if c not in enemy:
                enemy[c] = countB
                
            else:
                enemy[c] = enemy[c] | countB
            
        for c in countB:
            if c not in enemy:
                enemy[c] = countA
                
            else:
                enemy[c] = enemy[c] | countA
                
    else:
        war = False
        countries.append(countries[0])
        for i in range(len(countries)-1):
            if countries[i+1] in enemy:
                if countries[i] in enemy[countries[i+1]]:
                    print('No')
                    war = True
                    break
            
        if not war:
            print('Okay')
    
    inp = input().split()

6530117421
# 1679568, 2022-11-12 10:17:44, PPPPPP (100%)

Ally = []
Enemy = {}
rev = {}

def ally(inp):
    temp = set()
    for i in inp:
        i.strip()
        temp.add(i)
    return temp

def table(inp):
    for i in range(len(inp)):
        c1 = inp[i].strip()
        c2 = inp[i-1].strip()
        for j in Ally:
            if c1 in j: c1 = j
            if c2 in j: c2 = j
        if type(c1) == str:
            temp = set()
            temp.add(c1)
            c1 = temp
        if type(c2) == str:
            temp = set()
            temp.add(c2)
            c2 = temp
        for a in c1:
            if a in Enemy:
                if Enemy[a] in c2: return "No"
        for a in c2:
            if a in Enemy:
                if Enemy[a] in c1: return "No"
    return "Okay"
    
inp = str(input())
while inp != "End":
    inp = inp.split()
    if inp[0].strip() == "Ally":
        Ally.append(ally(inp[1:]))
    elif inp[0].strip() == "Enemy":
        Enemy[inp[1].strip()] = inp[2].strip()
    elif inp[0].strip() == "Table":
        print(table(inp[1:]))
    inp = str(input())


6530141421
# 1680100, 2022-11-12 10:41:47, PPPPPP (100%)

alldic = {};edic = {};ans = []
while True:
    x = input().strip()
    if x == "End": break
    x = x.split()
    if x[0] == "Ally":
        adic = {}
        for e in x[1:]:
            if e not in adic:
                adic[e] = set()
            for f in x[1:]:
                adic[e].add(f)
        for e in adic:
            alldic[e] = adic[e]
    elif x[0] == "Enemy":
        if x[1] not in alldic:  alldic[x[1]] = {x[1]}
        if x[2] not in alldic: alldic[x[2]] = {x[2]}
        for e in alldic[x[1]]:
            for f in alldic[x[2]]:
                if e not in edic: edic[e] = {f}
                if f not in edic: edic[f] = {e}
                edic[e].add(f)
                edic[e].add(x[2])
                edic[f].add(e)
                edic[f].add(x[1])
    elif x[0] == "Table":
        t = x[1:] + [x[1]]
        check = 0
        for i in range(len(t)-1):
            if t[i+1] not in edic:
                edic[t[i+1]] = set()
            if t[i] in edic[t[i+1]]:
                ans.append("No")
                check = -1
                break
        if check == 0:
            ans.append("Okay")
print("\n".join(ans))
            

6530163221
# 1680868, 2022-11-12 11:12:12, PPPPPP (100%)

a = input()
Ally = []
Data = {}
check1 = 0
check2 = 0

while a != 'End':
    a = [ e for e in a.split() ]
    
    if a[0] == 'Ally':
        Ally = Ally + [a[1:]]
        
    elif a[0] == 'Enemy':
        check1 = 0
        check2 = 0
        for i in range(len(Ally)):
            if a[1] in Ally[i]:
                O = i
                check1 += 1
            if a[2] in Ally[i]:
                W = i
                check2 += 1
                
        if check1 > 0 and check2 > 0:
            for i in Ally[O]:
                if i in Data:
                    Data[i] = Data[i] + Ally[W]
                else:
                    Data[i] = Ally[W]
            for i in Ally[W]:
                if i in Data:
                    Data[i] = Data[i] + Ally[O]
                else:
                    Data[i] = Ally[O]
            
        else:
            if check1 > 0 :
                for i in Ally[O]:
                    if i in Data:
                        Data[i] = Data[i] + [a[2]]
                    else:
                        Data[i] = [a[2]]
            else:
                if check2 == 0:
                    if a[1] in Data:
                        Data[a[1]] = Data[a[1]] + [a[2]]
                    else:
                        Data[a[1]] = [a[2]]
                else:
                    if a[1] in Data:
                        Data[a[1]] = Data[a[1]] + Ally[W]
                    else:
                        Data[a[1]] = Ally[W]
                
            if check2 > 0:
                for i in Ally[W]:
                    if i in Data:
                        Data[i] = Data[i] + [a[1]]
                    else:
                        Data[i] = [a[1]]
            else:
                if check1 == 0:
                    if a[2] in Data:
                        Data[a[2]] = Data[a[2]] + [a[1]]
                    else:
                        Data[a[2]] = [a[1]]
                else:
                    if a[2] in Data:
                        Data[a[2]] = Data[a[2]] + Ally[O]
                    else:
                        Data[a[2]] = Ally[O]
    elif a[0] == 'Table':
        Table = a[1:] + [a[1]]
        check3 = len(Table) - 1
        for i in range(len(Table)-1):
            if Table[i+1] in Data:
                if Table[i] in Data[Table[i+1]]:
                    check3 = check3 - 1
        if check3 == len(Table)-1:
            print('Okay')
        else:
            print('No')
        
    a = input()


6530186721
# 1679830, 2022-11-12 10:29:33, PPPPPP (100%)

x = input()
country = {}
while x != 'End' :
    x = x.split()
    for i in x[1:] :
        if i not in country :
            country[i] = {'atwar' : set(),'ally' : set()}
    if x[0] == 'Ally' :
        for i in x[1:] :
            for e in x[1:] :
                if e != i :
                    country[i]['ally'].add(e)
    elif x[0] == 'Enemy' :
        country[x[1]]['atwar'].add(x[2])
        country[x[2]]['atwar'].add(x[1])
    for i in country :
        for e in country[i]['atwar'] :
            country[i]['atwar'] = country[i]['atwar'].union(country[e]['ally'])
        for e in country[i]['ally'] :
            country[e]['atwar'] = country[e]['atwar'].union(country[i]['atwar'])
    if x[0] == 'Table' :
        okay = True
        sit = x[1:] + [x[1]]
        for n,i in enumerate(sit[:-1]) :
            if sit[n+1] in country[i]['atwar'] :
                okay = False
        if okay == True :
            print('Okay')
        else :
            print('No')
    x = input()


6531305221
# 1680833, 2022-11-12 11:10:50, PPPPPP (100%)

allies = {}
ens = {}
result = []


while True:
    y = input()
    x = y.split()
    if y == 'End':
        break
    if x[0] == 'Ally':
        for i in x[1:]:
            allies.update({i: set()})
            for j in x[1:]:
                if i != j:
                    allies[i].add(j)
    elif x[0] == 'Enemy':
        for i in x[1:]:
            ens.update({i: set()})
            for j in x[1:]:
                if i != j:
                    ens[i].add(j)
    elif x[0] == 'Table':

        for i in allies:
            if i not in ens:
                ens.update({i: set()})

        for k1, v1 in ens.items():
            for k2, v2 in allies.items():
                if k2 in v1:
                    for i in v2:
                        ens[k1].add(i)

        for k1, v1 in ens.items():
            for k2, v2 in ens.items():
                if k1 in v2:
                    ens[k1].add(k2)

        for k1, v1 in ens.items():
            for i in v1:
                for k2, v2 in allies.items():
                    if k1 in v2:
                        ens[k2].add(i)
        for k1, v1 in ens.items():
            for k2, v2 in ens.items():
                if k1 in v2:
                    ens[k1].add(k2)

        table = x[1:]

        bool = True
        for i in range(len(table)):
            if table[i] not in ens or table[i-1] not in ens:
                pass
            elif table[i-1] in ens[table[i]]:
                bool = False
                break
        if bool:
            result.append('Okay')
        else:
            result.append('No')

for i in result:
    print(i)


6531314921
# 1680130, 2022-11-12 10:42:57, PPPPPP (100%)

a = []
b = input().split()


while b[0] != 'Table':
    while b[0] == 'Ally':
        c = set()
        for i in b[1:]:
            c.add(i)
        a.append([c, set()])
        b = input().split()
    while b[0] == 'Enemy':
        d = False
        for i in a:
            if b[1] in i[0]:
                for j in b[2:]:
                    i[1].add(j)
                    for k in a:
                        if j in k[0]:
                            for l in k[0]:
                                i[1].add(l)
                    d = True
        if d == False:
            e = set()
            for j in b[2:]:
                e.add(j)
            a.append([{b[1]}, e])
        b = input().split()


def war(x, y, z):
    for i in a:
        if x in i[0]:
            if y in i[1] or z in i[1]:
                return False
            else:
                return True


while b[0] != 'End':
    q = True
    if war(b[1], b[-1], b[2]) == False:
        q = False
    if q == True:
        for i in range(2, len(b)-1):
            if war(b[i], b[i+1], b[i-1]) == False:
                q = False
                break
    if q == True:
        if war(b[-1], b[-2], b[1]) == False:
            q = False
    if q == True:
        print('Okay')
    else:
        print('No')
    b = input().split()


6531315521
# 1680913, 2022-11-12 11:13:50, PPPPPP (100%)

ally = {} # {COUNTRY : [ALLY - COUNTRY] , ...}
enemy = {} # {COUNTRY : [ENEMY , ...] , ...}
while True:
    x = [e.strip() for e in input().split()]
    if x[0] == 'End': break
    elif x[0] == 'Ally':
        for e in x[1:]:
            ally[e] = []
            for k in x[1:]:
                if k != e:
                    ally[e].append(k)
    elif x[0] == 'Enemy':
        for e in x[1:]:
            if e not in enemy:
                if e in ally:
                    for k in ally[e]:
                        enemy[k] = []
                enemy[e] = []
            for k in x[1:]:
                if k != e:
                    if k in ally:
                        enemy[e] += ally[k]
                    enemy[e].append(k)  
                    if e in ally:
                        for e2 in ally[e]:
                            if e2 != e and e2 in ally[e]:
                                enemy[e2] = enemy[e]
                    



    elif x[0] == 'Table':
        check = False
        for i in range(len(x[1:])):
            if x[1:][i] in enemy and x[1:][i-1] in enemy[x[1:][i]]:
                check = False
                break
            check = True
        if check: print('Okay')
        else: print('No')

6531316121
# 1680108, 2022-11-12 10:42:05, PPPPPP (100%)

s = input()
ally = []
enemy = []
table = []
while s != "End":
     l = s.split()
     if l[0] == "Ally":
          ally.append(l[1:])
     elif l[0] == "Enemy":
          enemy.append(l[1:])
     elif l[0] == "Table":
          table.append(l[1:])
     s = input()

war = []
for e in enemy:
     p = e[0] ; q = e[1]
     x = [p]
     y = [q]
     for a in ally:
          if (p in a):
               x = a
          if (q in a):
               y = a
     war.append([x,y])


for t in table:
     qc = True
     for i in range(len(t)):
          c1 = t[i]
          c2 = t[(i+1)%len(t)]
          for w in war:
               if (c1 in w[0] and c2 in w[1]) or \
                    (c1 in w[1] and c2 in w[0]):
                    qc = False
     if qc:
          print("Okay")
     else:
          print("No")

6531323521
# 1681110, 2022-11-12 11:19:15, PPPPPP (100%)

n = input()
ally = []
enemy = {}
table = []
op = []
while n != "End":
    op.append(n)
    n = input()
    
    

for n in op:
    n = n.split()
    if n[0] in ["Ally","Enemy"]:
        if n[0] == "Ally" :
            ally.append([n[i] for i in range(1,len(n)) ])
        else : 
            for i in n[1:]:
                if n[1] not in enemy :
                    enemy[n[1]] = set([n[2]])
                else :  
                    enemy[n[1]].add(n[2])
                if n[2] not in enemy :
                    enemy[n[2]] = set([n[1]])
                else :
                    enemy[n[2]].add(n[1])
                for i in enemy :
                    for j in enemy[i] :
                        for k in ally :
                            if j in k:
                                for l in k :
                                    enemy[i].add(l)
                        break
    for k in ally :
        for i in k :
            for j in enemy :
                if j != i :
                    for l in enemy[j] :
                        if l in i :
                            enemy[j] = enemy[j] | set(k)
    y = 1
    if n[0] == "Table" and y == 1 :
        if y == 1:
            for k in ally :
                for i in k :
                    for j in k :
                        if i not in enemy and j in enemy   :
                            enemy[i] =enemy[j]
            y+= 1
    if n[0] == "Table" and y != 1  :
         table = [n[i] for i in range(1,len(n))]
         table.append(table[0])
         for i in range(len(table)-1) :
             if table[i+1] and table[i] in enemy :
                if table[i+1] in enemy[table[i]]:
                    print("No")
                    break
             if i == len(table) -2 :
                 print("Okay")
                 break

                







     
    


6531339621
# 1679363, 2022-11-12 10:06:23, PPPPPP (100%)

shipchart = {}

# shipchart = {
#   nation: {
#       n1: "Ally"
#       n2: "Enemy"
#   }
# }


def addAlly(nation, ally):
    if(nation == ally):
        return -1
    if(shipchart[nation].get(ally) == "Ally"):
        return -2
    shipchart[nation][ally] = "Ally"
    for n in shipchart[nation]:
        if(shipchart[nation][n] == "Ally"):
            addAlly(n, ally)
            addAlly(ally, n)
    return 0


inStr = input()
while(inStr != 'End'):
    inList = inStr.split()
    if(inList[0] == 'Ally'):
        # firstly add all members not present in the shipchart
        for nation in inList[1:]:
            if(shipchart.get(nation) == None):
                shipchart[nation] = {}
        # then enter a recursive function
        for n in inList[2:]:
            addAlly(inList[1], n)
            addAlly(n, inList[1])
    if(inList[0] == 'Enemy'):
        # firstly add all members not present in the shipchart
        for nation in inList[1:]:
            if(shipchart.get(nation) == None):
                shipchart[nation] = {}
        # two nations are enemies, inList[1] and inList[2]
        guild1 = [e for e in shipchart[inList[1]] if shipchart[inList[1]][e] == "Ally"] + [inList[1]]
        guild2 = [e for e in shipchart[inList[2]] if shipchart[inList[2]][e] == "Ally"] + [inList[2]]
        for i in guild1:
            for j in guild2:
                shipchart[i][j] = "Enemy"
                shipchart[j][i] = "Enemy"
    if(inList[0] == 'Table'):
        # firstly add all members not present in the shipchart
        for nation in inList[1:]:
            if(shipchart.get(nation) == None):
                shipchart[nation] = {}
        ok = True
        inList[0] = inList[-1]
        for i in range(len(inList)-1):
            if(shipchart[inList[i]].get(inList[i+1]) == "Enemy"):
                ok = False
                break
        if(ok):
            print("Okay")
        else:
            print("No")
    inStr = input()


6531345321
# 1679199, 2022-11-12 09:57:42, PPPPPP (100%)

x = input().split()
country = dict()
group = dict()
problem = []
group_cnt = 1
while x[0] != "END" :
    if x[0] == "Ally" :
        group[group_cnt] = list()
        for i in range(1,len(x)) :
            group[group_cnt].append(x[i])
            country[x[i]] = group_cnt
        group_cnt += 1
    elif x[0] == 'Enemy' : # country1 country2 
        if x[1] not in country :
            country[x[1]] = group_cnt
            group[group_cnt] = x[1]
            group_cnt += 1
        if x[2] not in country :
            country[x[2]] = group_cnt
            group[group_cnt] = x[2]
            group_cnt += 1 
        problem.append((country[x[1]],country[x[2]]))
        problem.append((country[x[2]],country[x[1]]))
    elif x[0] == "Table" :
        already = False
        for i in range(1,len(x)-1) :
            if x[i] not in country or x[i+1] not in country  :
                continue
            else :
                temp = (country[x[i]],country[x[i+1]])
                if temp in problem :
                    print("No")
                    already = True
                    break
        if not already :
            if x[1] not in country or x[-1] not in country :
                print("Okay")
            else :
                temp = (country[x[1]],country[x[-1]])
                if temp in problem :
                    print("No")
                else : 
                    print("Okay")
    else :
        break
    x = input().split()

            

6532027021
# 1678912, 2022-11-12 09:42:07, PPPPPP (100%)

def bfs(s, graph) :
    q = [s]
    members = set()
    members.add(s)
    while len(q) > 0 :
        u = q.pop(0)
        if u in graph :
            for v in graph[u] :
                if v not in members :
                    members.add(v)
                    q.append(v)
    return members

graph = {}
hate = {}
while True :
    data = input()
    if data == 'End' :
        break

    data = data.split()
    if data[0] == 'Ally' :
        data = data[1:]
        for i in data :
            for j in data :
                if i != j :
                    if i not in graph :
                        graph[i] = set()
                    if j not in graph :
                        graph[j] = set()
                    graph[i].add(j)
                    graph[j].add(i)
    elif data[0] == 'Enemy' :
        head1, head2 = data[1:]
        team1 = bfs(head1, graph)
        team2 = bfs(head2, graph)

        for t1 in team1 :
            for t2 in team2 :
                if t1 not in hate :
                    hate[t1] = set()
                if t2 not in hate :
                    hate[t2] = set()
                hate[t1].add(t2)
                hate[t2].add(t1)
    elif data[0] == 'Table' :
        data = data[1:]
        notOk = False
        for i in range(len(data)) :
            m1 = data[i]; m2 = data[(i + 1) % len(data)]
            if (m1 in hate and m2 in hate[m1]) or (m2 in hate and m1 in hate[m2]) :
                notOk = True
        if notOk == False :
            print('Okay')
        else :
            print('No')

6532118421
# 1679135, 2022-11-12 09:54:12, PPPPPP (100%)

x = input()
k = list()
c = list()
while x!="End" :
    x = x.strip().split()
    o = set()
    if x[0]=="Ally" :
        for i in range(1,len(x)) : o.add(x[i])
        k.append(o)
    elif x[0]=="Enemy" :
        check = True
        for r in k :
            if x[1] in r : check = False
        if check :
            g = set()
            g.add(x[1])
            k.append(g)
        check = True
        for r in k :
            if x[2] in r : check = False
        if check :
            g = set()
            g.add(x[2])
            k.append(g)
        c.append((x[1],x[2]))
    elif x[0]=="Table" :
        check = "Okay"
        for i in range(1,len(x)-1) :
            for v in c :
                for r in k :
                    if v[0] in r : s = r
                    if v[1] in r : e = r
                if x[i] in s and x[i+1] in e : check = "No"
                if x[i] in e and x[i+1] in s : check = "No"
                if check=="No" : break
        for v in c :
            for r in k :
                if v[0] in r : s = r
                if v[1] in r : e = r
            if x[1] in s and x[len(x)-1] in e : check = "No"
            if x[1] in e and x[len(x)-1] in s : check = "No"
            if check=="No" : break
        print(check)
    x = input()

6532120621
# 1679014, 2022-11-12 09:47:44, PPPPPP (100%)

c2g = {}
enemies = set()

while True:
    raw = input()
    if raw == "End":
        exit()
    cmd, *args = raw.split()
    if cmd == "Ally":
        countries = args
        group = set(countries)
        for country in countries:
            if country not in c2g:
                c2g[country] = []
            c2g[country].append(group)
#         for x in c2g:
#             print(x, c2g[x])
#         print('-----')
    elif cmd == "Enemy":
        a, b = args
        
        if a not in c2g:
            c2g[a] = []

        if b not in c2g:
            c2g[b] = []

        g_a = set([a])
        for allies_group_a in c2g[a]:
            for allies_a in allies_group_a:
                g_a.add(allies_a)

        g_b = set([b])
        for allies_group_b in c2g[b]:
            for allies_b in allies_group_b:
                g_b.add(allies_b)

        for x in g_a:
            for y in g_b:
                enemies.add((x, y))
                enemies.add((y, x))
#         print(enemies)
#         print('-----')
    elif cmd == "Table":
        countries = args
        valid = True
        for i in range(len(countries) - 1):
            if (countries[i], countries[i + 1]) in enemies:
                valid = False
                break
        if (countries[0], countries[-1]) in enemies:
            valid = False

        if valid:
            print("Okay")
        else:
            print("No")
#        print('-----')


6532124121
# 1679519, 2022-11-12 10:14:23, PPPPPP (100%)

Ally = []
coun = []
name = {}
x = input().split()
while(x[0]=="Ally"):
    t = []
    for i in range(1,len(x)):
        t.append(x[i])
        if(x[i] not in name):
            name[x[i]] = set()
        if(x[i] not in coun):
            coun.append(x[i])
    Ally.append(t)
    x = input().split()
#print(Ally)
#print(name)
while(x[0]=="Enemy"):
    for i in range(1,len(x)):
        if(x[i] not in name):
            name[x[i]] = set()
        if(x[i] not in coun):
            coun.append(x[i])
            Ally.append([x[i]])
    for i in range(1,len(x)):
        me = x[i]
        mg = []
        yg = []
        #find my group
        for k in range (0,len(Ally)):
            if(me in Ally[k]):
                mg = Ally[k]
        #print("mg",mg)
        for j in range(1,len(x)):
            if(i==j):
                continue
            yg = []
            you = x[j]
            for k in range(0,len(Ally)):
                if(you in Ally[k]):
                    yg = Ally[k]
            #print("yg",yg)
            for m in mg:
                for y in yg:
                    name[m].add(y)
                    name[y].add(m)
    x = input().split()
while(x[0]!="End"):
    ok = True
    for i in range(1,len(x)):
        if(x[i] not in name):
            name[x[i]] = set()
    x = x[1::]
    #print(x)
    for i in range(0,len(x)):
        if(i==len(x)-1):
            l = x[i-1]
            me = x[i]
            r = x[0]
        else:
            l = x[i-1]
            me = x[i]
            r = x[i+1]
        if(l in name[me]):
            ok = False
        if(r in name[me]):
            ok = False
    if(ok):
        print("Okay")
    else:
        print("No")
    x = input().split()
#print(name)


6532141821
# 1679731, 2022-11-12 10:24:51, PPPPPP (100%)

ally = []
enemy = []
while True :
    x = input().strip().split()
    command = x[0]
    countrieslist = x[1:]
    if command == "Ally" :
        ally.append(countrieslist)
    if command == "Enemy" :
        enemygroup = []
        for c in countrieslist :
            ingroup = False
            for a in ally :
                if c in a :
                    enemygroup.append(a)
                    ingroup = True
                    break
            if not ingroup :
                enemygroup.append([c])
        enemy.append(enemygroup)
    if command == "Table" :
        table = countrieslist
        valid = True
        try :
            for i in range(len(table)) :
                c1, c2 = table[i], table[i+1]
                for e1, e2 in enemy :
                    if ((c1 in e1) and (c2 in e2)) or ((c1 in e2) and (c2 in e1)) :
                        print("No")
                        valid = False
                        break
                    if not valid :
                        break
                if not valid :
                        break
        except :
            c1, c2 = table[0], table[-1]
            for e1, e2 in enemy :
                if ((c1 in e1) and (c2 in e2)) or ((c1 in e2) and (c2 in e1)) :
                    print("No")
                    valid = False
                    break
                if not valid :
                        break
        if valid :
            print("Okay")
    if command == "End" :
        break


6532155621
# 1679230, 2022-11-12 09:59:41, PPPPPP (100%)


couAlly = {}
couEnem = {}

def addEnemy(couEnem: dict, couAlly: set, enemAlly: set):
    for cou in couAlly:
        if cou not in couEnem: couEnem[cou] = set()
        couEnem[cou].update(enemAlly)
    return couEnem

while True:
    raw = input().strip().split()
    if raw[0] == "End": break

    if raw[0] == "Ally":
        for coun in raw[1: ]:
            tmp = set(raw[1: ])
            couAlly[coun] = tmp
        
        # for key, val in couAlly.items():
        #     print(f"{key}: {val}")
    elif raw[0] == "Enemy":
        if raw[1] not in couAlly: couAlly[raw[1]] = set([raw[1]])
        if raw[2] not in couAlly: couAlly[raw[2]] = set([raw[2]])

        couEnem = addEnemy(couEnem, couAlly[raw[1]], couAlly[raw[2]])
        couEnem = addEnemy(couEnem, couAlly[raw[2]], couAlly[raw[1]])
    elif raw[0] == "Table":
        raw.append(raw[1])
        ok = True
        for i in range(1, len(raw)-1):
            if raw[i] in couEnem and raw[i+1] in couEnem[raw[i]]:
                ok = False
    
        if ok: print("Okay")
        else: print("No")
    # elif raw[0] == "1":
    #     for key, val in couEnem.items():
    #         print(f"{key}: {val}")
        
    

Max Score = 83


6532180221
# 1679485, 2022-11-12 10:12:55, xxxxxx (0%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        anc = l[0]
        for country in l:
            country_to_ancestor[country] = disjoint_set(anc)
    
    if(cmd == 'Enemy'):
        a,b = l[1:]
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(l):
            main = l[i]
            left = l[i-1]
            right = l[i+1]
            
            if(enemy[disjoint_set(main)] == disjoint_set(left) or 
               enemy[disjoint_set(main)] == disjoint_set(right)):
                ok = False
        if(ok):print("Okay")
        else:print("No")
# 1679560, 2022-11-12 10:16:59, xxxxxx (0%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        anc = l[0]
        for country in l:
            country_to_ancestor[country] = disjoint_set(anc)
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[i+1]
            
            if(disjoint_set(main) in enemy and enemy[disjoint_set(main)] == disjoint_set(left)):
                ok = False
            if(disjoint_set(main) in enemy and enemy[disjoint_set(main)] == disjoint_set(right)):
                ok= False
                
        if(ok):print("Okay")
        else:print("No")
# 1679572, 2022-11-12 10:17:53, P----- (17%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        anc = l[0]
        for country in l:
            country_to_ancestor[country] = disjoint_set(anc)
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            if(disjoint_set(main) in enemy and enemy[disjoint_set(main)] == disjoint_set(left)):
                ok = False
            if(disjoint_set(main) in enemy and enemy[disjoint_set(main)] == disjoint_set(right)):
                ok= False
                
        if(ok):print("Okay")
        else:print("No")
# 1679735, 2022-11-12 10:24:59, PPPPP- (83%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        anc = l[0]
        for country in l:
            country_to_ancestor[country] = disjoint_set(anc)
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1679944, 2022-11-12 10:34:07, PPPPP- (83%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[country] = disjoint_set(anc)
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1680083, 2022-11-12 10:40:48, PPPPP- (83%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1680306, 2022-11-12 10:51:43, PP-P-- (50%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)] 
               and disjoint_set(main) in enemy[disjoint_set(left)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]
               and disjoint_set(main) in enemy[disjoint_set(right)]):
                ok= False
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print(enemy[disjoint_set(main)])
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
  # # # # DEBUG
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    # for k,v in enemy.items():
    #     print(k,":",v)
    
        
# 1680326, 2022-11-12 10:52:31, Pxxxxx (17%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy  
               and disjoint_set(main) in enemy[disjoint_set(left)]):
                ok = False
            if(disjoint_set(main) in enemy 
               and disjoint_set(main) in enemy[disjoint_set(right)]):
                ok= False
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print(enemy[disjoint_set(main)])
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
  # # # # DEBUG
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    # for k,v in enemy.items():
    #     print(k,":",v)
    
        
# 1680345, 2022-11-12 10:52:58, PPPPP- (83%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(left) in enemy  
               and disjoint_set(main) in enemy[disjoint_set(left)]):
                ok = False
            if(disjoint_set(right) in enemy 
               and disjoint_set(main) in enemy[disjoint_set(right)]):
                ok= False
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print(enemy[disjoint_set(main)])
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
  # # # # DEBUG
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    # for k,v in enemy.items():
    #     print(k,":",v)
    
        
# 1680375, 2022-11-12 10:53:57, PPPPP- (83%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False
                
            if(disjoint_set(left) in enemy  
               and disjoint_set(main) in enemy[disjoint_set(left)]):
                ok = False
            if(disjoint_set(right) in enemy 
               and disjoint_set(main) in enemy[disjoint_set(right)]):
                ok= False
            
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1680383, 2022-11-12 10:54:12, PP-P-- (50%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        # if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        # else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False
                
            if(disjoint_set(left) in enemy  
               and disjoint_set(main) in enemy[disjoint_set(left)]):
                ok = False
            if(disjoint_set(right) in enemy 
               and disjoint_set(main) in enemy[disjoint_set(right)]):
                ok= False
            
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1680447, 2022-11-12 10:56:30, PPPP-- (67%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [(b)]
        else: enemy[disjoint_set(a)] += [(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [(a)]
        else: enemy[disjoint_set(b)] += [(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False
                
            if(disjoint_set(left) in enemy  
               and disjoint_set(main) in enemy[disjoint_set(left)]):
                ok = False
            if(disjoint_set(right) in enemy 
               and disjoint_set(main) in enemy[disjoint_set(right)]):
                ok= False
            
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1680455, 2022-11-12 10:56:49, PPPP-- (67%)

country_to_ancestor = {}
enemy = {}
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [(b)]
        else: enemy[disjoint_set(a)] += [(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [(a)]
        else: enemy[disjoint_set(b)] += [(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False
         
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1680491, 2022-11-12 10:58:46, Pxxxxx (17%)

country_to_ancestor = {}
enemy = {}
st=1
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [(b)]
        else: enemy[disjoint_set(a)] += [(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [(a)]
        else: enemy[disjoint_set(b)] += [(a)]
        
    if(cmd == 'Table'):
        if(st):
            st=0
            for i in enemy:
                for j in range(enemy[i]):
                    enemy[i][j] = disjoint_set(enemy[i][j])
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False
         
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1680512, 2022-11-12 10:59:33, PPPPP- (83%)

country_to_ancestor = {}
enemy = {}
st=1
def disjoint_set(country):
    if(country not in country_to_ancestor 
       or country_to_ancestor[country] == country):
        country_to_ancestor[country] = country
        return country
    else:
        return disjoint_set(country_to_ancestor[country])

while(True):
    a = input()
    if(a == 'End'):break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        anc = l[0]
        for i in l:
            if(i in country_to_ancestor):
                anc=i ; break
        for country in l:
            country_to_ancestor[disjoint_set(country)] = disjoint_set(anc)
    
    # for k,v in country_to_ancestor.items():
    #     print(k,":",v)
    
    
    if(cmd == 'Enemy'):
        a,b = l
        if a not in enemy: enemy[disjoint_set(a)] = [(b)]
        else: enemy[disjoint_set(a)] += [(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [(a)]
        else: enemy[disjoint_set(b)] += [(a)]
        
    if(cmd == 'Table'):
        if(st):
            st=0
            for i in enemy:
                for j in range(len(enemy[i])):
                    enemy[i][j] = disjoint_set(enemy[i][j])
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False
         
            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1680934, 2022-11-12 11:14:43, PPxxxx (33%)

parent = {}
enemy = {}
def disjoint_set(country):
    if country not in parent:
        parent[country] = country
        return country

    if(parent[country] == country):
        return country

    return disjoint_set(parent[country])

while(True):
    a = input()
    if(a == 'End'): break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        p = l[0]
        for i in l:
            if(i in parent):
                p=i ; break
        for country in l:
            parent[disjoint_set(country)] = p

    
    
    if(cmd == 'Enemy'):
        a,b = l[0],l[1]
        if a not in enemy: enemy[disjoint_set(a)] = set([disjoint_set(b)])
        else: enemy[disjoint_set(a)].insert(disjoint_set(b))
        if b not in enemy: enemy[disjoint_set(b)] = set([disjoint_set(a)])
        else: enemy[disjoint_set(b)].insert(disjoint_set(a))
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False

            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1680944, 2022-11-12 11:15:04, PPPPP- (83%)

parent = {}
enemy = {}
def disjoint_set(country):
    if country not in parent:
        parent[country] = country
        return country

    if(parent[country] == country):
        return country

    return disjoint_set(parent[country])

while(True):
    a = input()
    if(a == 'End'): break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        p = l[0]
        for i in l:
            if(i in parent):
                p=i ; break
        for country in l:
            parent[disjoint_set(country)] = p

    
    
    if(cmd == 'Enemy'):
        a,b = l[0],l[1]
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        else: enemy[disjoint_set(a)] += [disjoint_set(b)]
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        else: enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False

            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1681019, 2022-11-12 11:16:51, PPPPP- (83%)

parent = {}
enemy = {}
def disjoint_set(country):
    if country not in parent:
        parent[country] = country
        return country

    if(parent[country] == country):
        return country

    return disjoint_set(parent[country])

while(True):
    a = input()
    if(a == 'End'): break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        p = l[0]
        for i in l:
            if(i in parent):
                p=i ; break
        for country in l:
            parent[disjoint_set(country)] = p

    
    
    if(cmd == 'Enemy'):
        a,b = l[0],l[1]
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        elif (disjoint_set(b) not in enemy[disjoint_set(a)]): 
            enemy[disjoint_set(a)] += [disjoint_set(b)]
            
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        elif (disjoint_set(a) not in enemy[disjoint_set(b)]): 
            enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False

            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1681086, 2022-11-12 11:18:31, PPPPP- (83%)

parent = {}
enemy = {}
def disjoint_set(country):
    if country not in parent:
        parent[country] = country
        return country

    if(parent[country] == country):
        return country

    return disjoint_set(parent[country])

while(True):
    a = input()
    if(a == 'End'): break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        p = l[0]
        # for i in l:
        #     if(i in parent):
        #         p=i ; break
        for country in l:
            parent[disjoint_set(country)] = p

    
    
    if(cmd == 'Enemy'):
        a,b = l[0],l[1]
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        elif (disjoint_set(b) not in enemy[disjoint_set(a)]): 
            enemy[disjoint_set(a)] += [disjoint_set(b)]
            
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        elif (disjoint_set(a) not in enemy[disjoint_set(b)]): 
            enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False

            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1681117, 2022-11-12 11:19:24, PP-P-- (50%)

parent = {}
enemy = {}
def disjoint_set(country):
    if country not in parent:
        parent[country] = country
        return country

    if(parent[country] == country):
        return country

    return disjoint_set(parent[country])

while(True):
    a = input()
    if(a == 'End'): break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        p = l[0]
        # for i in l:
        #     if(i in parent):
        #         p=i ; break
        for country in l:
            parent[disjoint_set(country)] = p

    
    
    if(cmd == 'Enemy'):
        a,b = l[0],l[1]
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        elif (disjoint_set(b) not in enemy[disjoint_set(a)]): 
            enemy[disjoint_set(a)] += [disjoint_set(b)]
            
        # if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        # elif (disjoint_set(a) not in enemy[disjoint_set(b)]): 
        #     enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False

            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")
# 1681126, 2022-11-12 11:19:36, PPPPP- (83%)

parent = {}
enemy = {}
def disjoint_set(country):
    if country not in parent:
        parent[country] = country
        return country

    if(parent[country] == country):
        return country

    return disjoint_set(parent[country])

while(True):
    a = input()
    if(a == 'End'): break
    
    a = a.split(' ')
    cmd, l = a[0],a[1:]
    
    if(cmd == 'Ally'):
        # find one country that already has an ally
        p = l[0]
        # for i in l:
        #     if(i in parent):
        #         p=i ; break
        for country in l:
            parent[disjoint_set(country)] = p

    
    
    if(cmd == 'Enemy'):
        a,b = l[0],l[1]
        if a not in enemy: enemy[disjoint_set(a)] = [disjoint_set(b)]
        elif (disjoint_set(b) not in enemy[disjoint_set(a)]): 
            enemy[disjoint_set(a)] += [disjoint_set(b)]
            
        if b not in enemy: enemy[disjoint_set(b)] = [disjoint_set(a)]
        elif (disjoint_set(a) not in enemy[disjoint_set(b)]): 
            enemy[disjoint_set(b)] += [disjoint_set(a)]
        
    if(cmd == 'Table'):
        ok = True
        for i in range(len(l)):
            main = l[i]
            left = l[i-1]
            right = l[(i+1)%len(l)]
            
            
            
            if(disjoint_set(main) in enemy and disjoint_set(left) in enemy[disjoint_set(main)]):
                ok = False
            if(disjoint_set(main) in enemy and disjoint_set(right) in enemy[disjoint_set(main)]):
                ok= False

            
            # print("main: ",main)
            # if(disjoint_set(main) in enemy):
            #     print()
            # print("L: ",left, disjoint_set(left))
            # print("R: ",right, disjoint_set(right))
            
        if(ok):print("Okay")
        else:print("No")

6532100021
# 1679917, 2022-11-12 10:32:27, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
            for j in enem[c1]:
                enem[j].append(i)
        for i in ally[c2]:
            enem[i].append(c1)
            for j in enem[c2]:
                enem[j].append(i)
    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                continue
        if check:
            print("Okay")

    n = input().split()
# print(enem)
# print("-------------+")
# print(ally)

# 1680348, 2022-11-12 10:53:08, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            for j in ally[c2]:
                enem[i].append(j)
        for i in ally[c2]:
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                continue
        if check:
            print("Okay")

    n = input().split()
# print(enem)
# print("-------------+")
# print(ally)

# 1680513, 2022-11-12 10:59:33, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                continue
        if check:
            print("Okay")

    n = input().split()

# 1680537, 2022-11-12 11:00:26, P-PPP- (67%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                break
        if check:
            print("Okay")

    n = input().split()

# 1680543, 2022-11-12 11:00:39, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                continue
        if check:
            print("Okay")

    n = input().split()
# 1680690, 2022-11-12 11:05:49, xxxxxx (0%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem[i]:
                if n[i] in enem[n[i+1]] or n[i+1] in enem[n[i]]: 
                    print("No")
                    check = False
                    break
            else:
                break
        if check:
            print("Okay")

    n = input().split()

print(enem)
print("---------------+")
print(ally)

# 1680694, 2022-11-12 11:06:00, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                continue
        if check:
            print("Okay")

    n = input().split()
# 1680706, 2022-11-12 11:06:41, xxxxxx (0%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem[i] and n[i] in enem:
                if n[i] in enem[n[i+1]] or n[i+1] in enem[n[i]]: 
                    print("No")
                    check = False
                    break
            else:
                break
        if check:
            print("Okay")

    n = input().split()

print(enem)
print("---------------+")
print(ally)
# 1680712, 2022-11-12 11:06:51, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                continue
        if check:
            print("Okay")

    n = input().split()
# 1681057, 2022-11-12 11:17:40, xxxxxx (0%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                if n[i+1] in enem[i]:
                    print("No")
                    check = False
                    break


        if check:
            print("Okay")

    n = input().split()
# print(enem)
# print("-------++000")
# print(ally)

# 1681062, 2022-11-12 11:17:53, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                continue
        if check:
            print("Okay")

    n = input().split()
# 1681118, 2022-11-12 11:19:24, xxxxPx (17%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                if n[i+1] in enem[n[i]]:
                    print("No")
                    check = False
                    break


        if check:
            print("Okay")

    n = input().split()
# print(enem)
# print("-------++000")
# print(ally)
# 1681129, 2022-11-12 11:19:37, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            else:
                continue
        if check:
            print("Okay")

    n = input().split()
# 1681223, 2022-11-12 11:21:48, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            elif n[i] in enem:
                if n[i+1] in enem[n[i]]:
                    print("No")
                    check = False
                    break
        if check:
            print("Okay")

    n = input().split()


# 1681527, 2022-11-12 11:28:25, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            elif n[i] in enem:
                if n[i+1] in enem[n[i]]:
                    print("No")
                    check = False
                    break
        if check:
            print("Okay")

    n = input().split()
#ยอมก็ได้ตรับ เคสเดียวทำมานานละครับ555    
# 1681552, 2022-11-12 11:28:50, P-PPPP (83%)

ally = {}
enem = {}
n = input().split()
while n[0] != "End":
    if n[0] == "Ally":
        n = n[1:]
        for i in range(len(n)):
            enem[n[i]] = []
            ally[n[i]] = n[0:i]+n[i+1:]
    elif n[0] == "Enemy":
        c1, c2 = n[1], n[2]
        if c1 not in ally:
            ally[c1] = []
        if c2 not in ally:
            ally[c2] = []
        if c1 not in enem:
            enem[c1] = []
        if c2 not in enem:
            enem[c2] = []
        enem[c1].append(c2)
        enem[c2].append(c1)
        for i in ally[c1]:
            enem[i].append(c2)
        for i in ally[c2]:
            enem[i].append(c1)
        for i in ally[c1]:
            enem[c2].append(i)
            for j in ally[c2]:
                enem[i].append(j)

        for i in ally[c2]:
            enem[c1].append(i)
            for j in ally[c1]:
                enem[i].append(j)

    elif n[0] == "Table":
        check = True
        n = n[1:]
        n += n[0]
        for i in range(len(n)-1):
            if n[i+1] in enem:
                if n[i] in enem[n[i+1]]:
                    print("No")
                    check = False
                    break
            elif n[i] in enem:
                if n[i+1] in enem[n[i]]:
                    print("No")
                    check = False
                    break
        if check:
            print("Okay")

    n = input().split()


6231422721
# 1680312, 2022-11-12 10:51:57, PP-P-- (50%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if h in enemy and i in enemy[h] :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
        
            
# 1680319, 2022-11-12 10:52:15, PP-P-- (50%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if h in enemy and i in enemy[h] :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
# 1680604, 2022-11-12 11:03:08, PP-PPP (83%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if e in enemy and i in enemy :
                enemy[e] = enemy[e].union(enemy[i])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if h in enemy and i in enemy[h] :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
         
# 1680732, 2022-11-12 11:07:29, PP-Pxx (50%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if e in enemy :
                enemy[e] = enemy[e].union(enemy[i])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if h in enemy and i in enemy[h] :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
# 1680746, 2022-11-12 11:07:46, PP-Pxx (50%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if i in enemy :
                enemy[e] = enemy[e].union(enemy[i])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if h in enemy and i in enemy[h] :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
# 1680755, 2022-11-12 11:08:04, PP-PPP (83%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if i in enemy and e in enemy :
                enemy[e] = enemy[e].union(enemy[i])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if h in enemy and i in enemy[h] :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
# 1680834, 2022-11-12 11:10:52, -xxxxx (0%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if e in enemy and i in enemy :
                enemy[e] = enemy[e].union(enemy[i])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if (h in enemy) and (i in enemy[h] or h in enemy[i]) :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
print(enemy)         
# 1680851, 2022-11-12 11:11:27, ------ (0%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if e in enemy and i in enemy :
                enemy[e] = enemy[e].union(enemy[i])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if (h in enemy and i in enemy) and (i in enemy[h] or h in enemy[i]) :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
print(enemy)
# 1680857, 2022-11-12 11:11:45, PP-PPP (83%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if e in enemy and i in enemy :
                enemy[e] = enemy[e].union(enemy[i])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if (h in enemy and i in enemy) and (i in enemy[h] or h in enemy[i]) :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")

# 1680905, 2022-11-12 11:13:32, PP-PPP (83%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
                  
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            else :
                enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if e in enemy and i in enemy :
                enemy[e] = enemy[e].union(enemy[i])
                enemy[i] = enemy[i].union(enemy[e])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if (h in enemy and i in enemy) and (i in enemy[h] or h in enemy[i]) :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
# 1681324, 2022-11-12 11:24:17, PP-PPP (83%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
                  
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if e in enemy and i in enemy :
                enemy[e] = enemy[e].union(enemy[i])
                enemy[i] = enemy[i].union(enemy[e])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if (h in enemy and i in enemy) and (i in enemy[h] or h in enemy[i]) :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
# 1681354, 2022-11-12 11:25:08, PP-PPP (83%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])
            else :
                ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
                  
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if e in enemy and i in enemy :
                enemy[e] = enemy[e].union(enemy[i])
                enemy[i] = enemy[i].union(enemy[e])
                enemy[e] = enemy[e].union(enemy[i])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if (h in enemy and i in enemy) and (i in enemy[h] or h in enemy[i]) :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")
# 1681411, 2022-11-12 11:26:06, PP-PPP (83%)

ally = dict()
enemy = dict()
while True :
    a = input().strip().split()
    check = True
    if a == ["End"] :
        break
    if a[0].lower() == "ally" :
        for i in a[1:] :
            if i not in ally :
                ally[i] = set([e for e in a if e != i and e!= a[0]])

            ally[i]=ally[i].union(set([e for e in a if e != i and e != a[0]]))
    
    if a[0].lower() == "enemy" :
        for i in a[1:] :
            if i not in enemy :
                enemy[i] = set([e for e in a if e!= i and e!= a[0]])
            for e in enemy[i] :
                if e in ally :
                    enemy[i] = enemy[i].union(ally[e])
                  
    c = dict(enemy)
    for i in c :
        for e in c[i] :
            if e not in enemy :
                enemy[e] = {i}
            enemy[e].add(i)
    for i in ally :
        for e in ally[i] :
            if e in enemy and i in enemy :
                enemy[e] = enemy[e].union(enemy[i])
                enemy[i] = enemy[i].union(enemy[e])
                enemy[e] = enemy[e].union(enemy[i])
            
    if a[0].lower() == "table" :
        b = list(a[1:]) + [a[1]]
        h = b[0]
        for i in b[1:] :
            if (h in enemy and i in enemy) and (i in enemy[h] or h in enemy[i]) :
                check = False
            h = i
        if check == True :
            print("Okay")
        else :
            print("No")

6530005821
# 1679624, 2022-11-12 10:20:51, ------ (0%)

print('No')
# 1679640, 2022-11-12 10:21:43, ------ (0%)

x = input()
while x!='End':
  x = input()
print('No')
# 1680174, 2022-11-12 10:45:08, P-PPP- (67%)

x = input().split()
ally ={};enermy={}
final=[]
while x[0]!='End':
    if x[0]=='Ally':
        for t in x[1:]:
            if t not in ally:
                ally[t]=set([e for e in x[1:] if e!=t])
    if x[0]=='Enemy':
        if x[1] not in enermy:
            enermy[x[1]]={x[2]}
            if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
    if x[0]=='Table':
        final.append(x)
    x=input().split()
enermy2 = enermy.copy()
for e in enermy:
    if e in ally:
        for j in ally[e]:
            enermy2[j]=enermy[e]
enermy.update(enermy2)

def check(t):
    for i in range(1,len(t)-1):
        one = t[i]
        two = t[i+1]
        if one in enermy:
            if two in enermy[one]:
                return 'No'
                break
        else:
            pass
    if t[-1] in enermy:
            if t[1] in enermy[t[-1]]:
                return 'No'
    return 'Okay'
for e in final:
    print(check(e))

# 1680330, 2022-11-12 10:52:37, P-PPP- (67%)

x = input().split()
ally ={};enermy={}
final=[]
while x[0]!='End':
    if x[0]=='Ally':
        for t in x[1:]:
            if t not in ally:
                ally[t]=set([e for e in x[1:] if e!=t])
    if x[0]=='Enemy':
        if x[1] not in enermy:
            enermy[x[1]]={x[2]}
            if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
    if x[0]=='Table':
        final.append(x)
    x=input().split()
enermy2 = enermy.copy()
for e in enermy:
    if e in ally:
        for j in ally[e]:
            enermy2[j]=enermy[e]
enermy.update(enermy2)

def check(t):
    for i in range(1,len(t)-1):
        one = t[i]
        two = t[i+1]
        if one in enermy:
            if two in enermy[one]:
                return 'No'
                break
            else:
              pass
        else:
            pass
    if t[-1] in enermy:
            if t[1] in enermy[t[-1]]:
                return 'No'
    return 'Okay'
for e in final:
    print(check(e))
# 1680624, 2022-11-12 11:03:50, P-PPxx (50%)

x = input().split()
ally ={};enermy={}
final=[]
while x[0]!='End':
    if x[0]=='Ally':
        for t in x[1:]:
            if t not in ally:
                ally[t]=set([e for e in x[1:] if e!=t])
    if x[0]=='Enemy':
        if x[1] not in enermy:
            enermy[x[1]]={x[2]}
            if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
        else:
          enermy[x[2]].add(x[2])
          if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
    if x[0]=='Table':
        final.append(x)
    x=input().split()
enermy2 = enermy.copy()
for e in enermy:
    if e in ally:
        for j in ally[e]:
            enermy2[j]=enermy[e]
enermy.update(enermy2)

def check(t):
    for i in range(1,len(t)-1):
        one = t[i]
        two = t[i+1]
        if one in enermy:
            if two in enermy[one]:
                return 'No'
                break
            else:
              pass
        else:
            pass
    if t[-1] in enermy:
            if t[1] in enermy[t[-1]]:
                return 'No'
    return 'Okay'
for e in final:
    print(check(e))
# 1680645, 2022-11-12 11:04:21, P-PPxx (50%)

x = input().split()
ally ={};enermy={}
final=[]
while x[0]!='End':
    if x[0]=='Ally':
        for t in x[1:]:
            if t not in ally:
                ally[t]=set([e for e in x[1:] if e!=t])
    if x[0]=='Enemy':
        if x[1] not in enermy:
            enermy[x[1]]={x[2]}
            if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
        else:
          enermy[x[2]].add(x[2])
    if x[0]=='Table':
        final.append(x)
    x=input().split()
enermy2 = enermy.copy()
for e in enermy:
    if e in ally:
        for j in ally[e]:
            enermy2[j]=enermy[e]
enermy.update(enermy2)

def check(t):
    for i in range(1,len(t)-1):
        one = t[i]
        two = t[i+1]
        if one in enermy:
            if two in enermy[one]:
                return 'No'
                break
            else:
              pass
        else:
            pass
    if t[-1] in enermy:
            if t[1] in enermy[t[-1]]:
                return 'No'
    return 'Okay'
for e in final:
    print(check(e))
# 1680961, 2022-11-12 11:15:35, PPPPP- (83%)

x = input().split()
ally ={};enermy={}
final=[]
while x[0]!='End':
    if x[0]=='Ally':
        for t in x[1:]:
            if t not in ally:
                ally[t]=set([e for e in x[1:] if e!=t])
    if x[0]=='Enemy':
        if x[1] not in enermy:
            enermy[x[1]]={x[2]}
            if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
    if x[0]=='Table':
        final.append(x)
    x=input().split()
enermy2 = enermy.copy()
for e in enermy:
    if e in ally:
        for j in ally[e]:
            enermy2[j]=enermy[e]
enermy.update(enermy2)
enermy3 = enermy.copy()
for e in enermy:
    for f in enermy[e]:
        if f in enermy:
            enermy[f].add(e)
        else:
            enermy3[f]={e}
enermy.update(enermy3)
def check(t):
    for i in range(1,len(t)-1):
        one = t[i]
        two = t[i+1]
        if one in enermy:
            if two in enermy[one]:
                return 'No'
                break
            else:
                pass
        else:
            pass
    if t[-1] in enermy:
            if t[1] in enermy[t[-1]]:
                return 'No'
    return 'Okay'

for e in final:
    print(check(e))

# 1681351, 2022-11-12 11:25:04, PP-P-- (50%)

x = input().split()
ally ={};enermy={}
final=[]
while x[0]!='End':
    if x[0]=='Ally':
        for t in x[1:]:
            if t not in ally:
                ally[t]=set([e for e in x[1:] if e!=t])
    if x[0]=='Enemy':
        if x[1] not in enermy:
            enermy[x[1]]={x[2]}
            if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
    if x[0]=='Table':
        final.append(x)
    x=input().split()
enermy2 = enermy.copy()
for e in enermy:
    if e in ally:
        for j in ally[e]:
          if j in enermy:
            enermy[j].add(e)
          else:
            enermy2[j]=enermy[e]
enermy.update(enermy2)
enermy3 = enermy.copy()
for e in enermy:
    for f in enermy[e]:
        if f in enermy:
            enermy[f].add(e)
        else:
            enermy3[f]={e}
enermy.update(enermy3)
def check(t):
    for i in range(1,len(t)-1):
        one = t[i]
        two = t[i+1]
        if one in enermy:
            if two in enermy[one]:
                return 'No'
                break
            else:
                pass
        else:
            pass
    if t[-1] in enermy:
            if t[1] in enermy[t[-1]]:
                return 'No'
    return 'Okay'

for e in final:
    print(check(e))
# 1681405, 2022-11-12 11:26:04, PP-PP- (67%)

x = input().split()
ally ={};enermy={}
final=[]
while x[0]!='End':
    if x[0]=='Ally':
        for t in x[1:]:
            if t not in ally:
                ally[t]=set([e for e in x[1:] if e!=t])
    if x[0]=='Enemy':
        if x[1] not in enermy:
            enermy[x[1]]={x[2]}
            if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
    if x[0]=='Table':
        final.append(x)
    x=input().split()
enermy2 = enermy.copy()
for e in enermy:
    if e in ally:
        for j in ally[e]:
          enermy2[j]=enermy[e]
enermy.update(enermy2)
enermy3 = enermy.copy()
for e in enermy:
    for f in enermy[e]:
        if f in enermy:
            enermy[f].add(e)
        else:
            enermy3[f]={e}
enermy.update(enermy3)
def check(t):
    for i in range(1,len(t)-1):
        one = t[i]
        two = t[i+1]
        if one in enermy:
            if two in enermy[one]:
                return 'No'
                break
            else:
                pass
        else:
            pass
    if t[-1] in enermy:
            if t[1] in enermy[t[-1]]:
                return 'No'
    return 'Okay'

for e in final:
    print(check(e))
# 1681457, 2022-11-12 11:26:56, PPPPP- (83%)

x = input().split()
ally ={};enermy={}
final=[]
while x[0]!='End':
    if x[0]=='Ally':
        for t in x[1:]:
            if t not in ally:
                ally[t]=set([e for e in x[1:] if e!=t])
    if x[0]=='Enemy':
        if x[1] not in enermy:
            enermy[x[1]]={x[2]}
            if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
    if x[0]=='Table':
        final.append(x)
    x=input().split()
enermy2 = enermy.copy()
for e in enermy:
    if e in ally:
        for j in ally[e]:
            enermy2[j]=enermy[e]
enermy.update(enermy2)
enermy3 = enermy.copy()
for e in enermy:
    for f in enermy[e]:
        if f in enermy:
            enermy[f].add(e)
        else:
            enermy3[f]={e}
enermy.update(enermy3)
def check(t):
    for i in range(1,len(t)-1):
        one = t[i]
        two = t[i+1]
        if one in enermy:
            if two in enermy[one]:
                return 'No'
                break
            else:
                pass
        else:
            pass
    if t[-1] in enermy:
            if t[1] in enermy[t[-1]]:
                return 'No'
    return 'Okay'

for e in final:
    print(check(e))

# 1681466, 2022-11-12 11:27:08, PPPPP- (83%)

x = input().split()
ally ={};enermy={}
final=[]
while x[0]!='End':
    if x[0]=='Ally':
        for t in x[1:]:
            if t not in ally:
                ally[t]=set([e for e in x[1:] if e!=t])
    if x[0]=='Enemy':
        if x[1] not in enermy:
            enermy[x[1]]={x[2]}
            if x[2] in ally:
                for e in ally[x[2]]:
                    enermy[x[1]].add(e)
    if x[0]=='Table':
        final.append(x)
    x=input().split()
enermy2 = enermy.copy()
for e in enermy:
    if e in ally:
        for j in ally[e]:
            enermy2[j]=enermy[e]
enermy.update(enermy2)
enermy3 = enermy.copy()
for e in enermy:
    for f in enermy[e]:
        if f in enermy:
            enermy[f].add(e)
        else:
            enermy3[f]={e}
enermy.update(enermy3)
def check(t):
    for i in range(1,len(t)-1):
        one = t[i]
        two = t[i+1]
        if one in enermy:
            if two in enermy[one]:
                return 'No'
                break
            else:
                pass
        else:
            pass
    if t[-1] in enermy:
            if t[1] in enermy[t[-1]]:
                return 'No'
    return 'Okay'

for e in final:
    print(check(e))

6530077021
# 1680085, 2022-11-12 10:40:55, P----- (17%)

team = {}
while True:
    x = input().strip().split()
    if x[0] not in ['Ally','Enemy']: break
    elif x[0] == 'Ally':
        team[' '.join(x[1:])] = []
    elif x[0] == 'Enemy':
        a,b = x[1:]
        ans = []
        ca = False
        cb = False
        for n in team:
            if a in n:
                ans.append(n)
                ca = True
            if b in n :
                ans.append(n)
                cb = True
        if ca and not cb:
            team[b] = [ans[0]]
            team[ans[0]].append(b)
        elif cb and not ca:
            team[a] = [ans[0]]
            team[ans[0]].append(a)
        elif not(ca or cb):
            team[a] = [b]
            team[b] = [a]
        else:
            team[ans[0]].append(ans[1])
            team[ans[1]].append(ans[0])
ans = {}
for n in team:
    for m in n.strip().split():
        ans[m] = ' '.join(team[n]).split()

while True:
    if x[0] == 'End' : break
    check = True
    for i in range(2,len(x)-1):
        if x[i] not in ans:
            pass
        elif ( x[i-1] in  ans[x[i]] ) or (x[i+1] in ans[x[i]]):
            check = False
            break
        else:
            pass
    if check:
        print('Okay')
    else:
        print('No')
    x = input().strip().split()

        
            
            
            
                    
# 1680134, 2022-11-12 10:43:11, PxPP-P (67%)

team = {}
while True:
    x = input().strip().split()
    if x[0] not in ['Ally','Enemy']: break
    elif x[0] == 'Ally':
        team[' '.join(x[1:])] = []
    elif x[0] == 'Enemy':
        a,b = x[1:]
        ans = []
        ca = False
        cb = False
        for n in team:
            if a in n:
                ans.append(n)
                ca = True
            if b in n :
                ans.append(n)
                cb = True
        if ca and not cb:
            team[b] = [ans[0]]
            team[ans[0]].append(b)
        elif cb and not ca:
            team[a] = [ans[0]]
            team[ans[0]].append(a)
        elif not(ca or cb):
            team[a] = [b]
            team[b] = [a]
        else:
            team[ans[0]].append(ans[1])
            team[ans[1]].append(ans[0])
ans = {}
for n in team:
    for m in n.strip().split():
        ans[m] = ' '.join(team[n]).split()

while True:
    if x[0] == 'End' : break
    check = True
    for i in range(2,len(x)-1):
        if x[i] not in ans:
            pass
        elif ( x[i-1] in  ans[x[i]] ) or (x[i+1] in ans[x[i]]):
            check = False
            break
        else:
            pass
    if x[-1] in ans[x[1]]:
        check = False
        
    if check:
        print('Okay')
    else:
        print('No')
    x = input().strip().split()

        
            
            
            
                    
# 1680169, 2022-11-12 10:44:55, P----P (33%)

team = {}
while True:
    x = input().strip().split()
    if x[0] not in ['Ally','Enemy']: break
    elif x[0] == 'Ally':
        team[' '.join(x[1:])] = []
    elif x[0] == 'Enemy':
        a,b = x[1:]
        ans = []
        ca = False
        cb = False
        for n in team:
            if a in n:
                ans.append(n)
                ca = True
            if b in n :
                ans.append(n)
                cb = True
        if ca and not cb:
            team[b] = [ans[0]]
            team[ans[0]].append(b)
        elif cb and not ca:
            team[a] = [ans[0]]
            team[ans[0]].append(a)
        elif not(ca or cb):
            team[a] = [b]
            team[b] = [a]
        else:
            team[ans[0]].append(ans[1])
            team[ans[1]].append(ans[0])
ans = {}
for n in team:
    for m in n.strip().split():
        ans[m] = ' '.join(team[n]).split()

while True:
    if x[0] == 'End' : break
    check = True
    for i in range(2,len(x)-1):
        if x[i] not in ans:
            pass
        elif ( x[i-1] in  ans[x[i]] ) or (x[i+1] in ans[x[i]]):
            check = False
            break
        else:
            pass
    if x[-1] in ans:
      if x[2] in ans[x[-1]]:
        check = False
      
        
    if check:
        print('Okay')
    else:
        print('No')
    x = input().strip().split()
# 1680204, 2022-11-12 10:46:37, PPPP-P (83%)

team = {}
while True:
    x = input().strip().split()
    if x[0] not in ['Ally','Enemy']: break
    elif x[0] == 'Ally':
        team[' '.join(x[1:])] = []
    elif x[0] == 'Enemy':
        a,b = x[1:]
        ans = []
        ca = False
        cb = False
        for n in team:
            if a in n:
                ans.append(n)
                ca = True
            if b in n :
                ans.append(n)
                cb = True
        if ca and not cb:
            team[b] = [ans[0]]
            team[ans[0]].append(b)
        elif cb and not ca:
            team[a] = [ans[0]]
            team[ans[0]].append(a)
        elif not(ca or cb):
            team[a] = [b]
            team[b] = [a]
        else:
            team[ans[0]].append(ans[1])
            team[ans[1]].append(ans[0])
ans = {}
for n in team:
    for m in n.strip().split():
        ans[m] = ' '.join(team[n]).split()

while True:
    if x[0] == 'End' : break
    check = True
    x.append(x[1])
    for i in range(2,len(x)-1):
        if x[i] not in ans:
            pass
        elif ( x[i-1] in  ans[x[i]] ) or (x[i+1] in ans[x[i]]):
            check = False
            break
        else:
            pass

        
    if check:
        print('Okay')
    else:
        print('No')
    x = input().strip().split()

        
            
            
            
                    
# 1680711, 2022-11-12 11:06:46, PPPP-P (83%)

team = {}
while True:
    x = input().strip().split()
    if x[0] not in ['Ally','Enemy']: break
    elif x[0] == 'Ally':
        team[' '.join(x[1:])] = []
    elif x[0] == 'Enemy':
        a,b = x[1:]
        ans = []
        ca = False
        cb = False
        for n in team:
            if a in n:
                ans.append(n)
                ca = True
            if b in n :
                ans.append(n)
                cb = True
        if ca and not cb:
            team[b] = [ans[0]]
            team[ans[0]].append(b)
        elif cb and not ca:
            team[a] = [ans[0]]
            team[ans[0]].append(a)
        elif not(ca or cb):
            team[a] = [b]
            team[b] = [a]
        else:
            team[ans[0]].append(ans[1])
            team[ans[1]].append(ans[0])
ans = {}
for n in team:
    for m in n.strip().split():
        ans[m] = ' '.join(team[n]).split()

while True:
    if x[0] == 'End' : break
    check = True
    x.append(x[1])
    for i in range(2,len(x)-1):
        if x[i] not in ans:
            pass
        elif ( x[i-1] in  ans[x[i]] ) or (x[i+1] in ans[x[i]]):
            check = False
            break
        else:
            pass

        
    if check:
        print('Okay')
    else:
        print('No')
    x = input().strip().split()
# 1680930, 2022-11-12 11:14:39, PPPP-P (83%)

team = {}
while True:
    x = input().strip().split()
    if x[0] not in ['Ally','Enemy']: break
    elif x[0] == 'Ally':
        team[' '.join(x[1:])] = []
    elif x[0] == 'Enemy':
        a,b = x[1:]
        ans = []
        ca = False
        cb = False
        for n in team:
            if a in n:
                ans.append(n)
                ca = True
            if b in n :
                ans.append(n)
                cb = True
        if ca and not cb:
            team[b] = [ans[0]]
            team[ans[0]].append(b)
        elif cb and not ca:
            team[a] = [ans[0]]
            team[ans[0]].append(a)
        elif not(ca and cb):
            team[a] = [b]
            team[b] = [a]
        else:
            team[ans[0]].append(ans[1])
            team[ans[1]].append(ans[0])
ans = {}
for n in team:
    for m in n.strip().split():
        ans[m] = ' '.join(team[n]).split()

while True:
    if x[0] == 'End' : break
    check = True
    x.append(x[1])
    for i in range(2,len(x)-1):
        if x[i] not in ans:
            pass
        elif ( x[i-1] in  ans[x[i]] ) or (x[i+1] in ans[x[i]]):
            check = False
            break

    if check:
        print('Okay')
    else:
        print('No')
    x = input().strip().split()


        
            
            
            
                    
# 1680939, 2022-11-12 11:14:56, PPPP-P (83%)

team = {}
while True:
    x = input().strip().split()
    if x[0] not in ['Ally','Enemy']: break
    elif x[0] == 'Ally':
        team[' '.join(x[1:])] = []
    elif x[0] == 'Enemy':
        a,b = x[1:]
        ans = []
        ca = False
        cb = False
        for n in team:
            if a in n:
                ans.append(n)
                ca = True
            if b in n :
                ans.append(n)
                cb = True
        if ca and not cb:
            team[b] = [ans[0]]
            team[ans[0]].append(b)
        elif cb and not ca:
            team[a] = [ans[0]]
            team[ans[0]].append(a)
        elif not(ca or cb):
            team[a] = [b]
            team[b] = [a]
        else:
            team[ans[0]].append(ans[1])
            team[ans[1]].append(ans[0])
ans = {}
for n in team:
    for m in n.strip().split():
        ans[m] = ' '.join(team[n]).split()

while True:
    if x[0] == 'End' : break
    check = True
    x.append(x[1])
    for i in range(2,len(x)-1):
        if x[i] not in ans:
            pass
        elif ( x[i-1] in  ans[x[i]] ) or (x[i+1] in ans[x[i]]):
            check = False
            break

    if check:
        print('Okay')
    else:
        print('No')
    x = input().strip().split()

6230259621
# 1680032, 2022-11-12 10:38:24, ----xx (0%)

data=input().split()
ally=[]
enemy={}
sol=[]
en=True
while data[0]!='End':
    if data[0]=='Ally':
        ally+=[set(data[1:])]
    if data[0]=='Enemy':
        for c in ally:
            if data[2] in c:
                if data[1] in enemy:
                    enemy[data[1]].add(list(c))
                else:
                    enemy[data[1]]=set(list(c))
            elif data[1] in c:
                if data[2] in enemy:
                    enemy[data[2]].add(list(c))
                else:
                    enemy[data[2]]=set(list(c))
            else:
                if data[1] in enemy:
                    enemy[data[1]].add(data[2])
                else:
                    enemy[data[1]]=set([data[2]])
                if data[2] in enemy:
                    enemy[data[2]].add(data[1])
                else:
                    enemy[data[2]]=set([data[1]])
    if data[0]=='Table':
        table=[data[-1]]+data[1:]
        en=True
        for i in range(len(table)-1):
            for c in ally:
                if table[i] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i+1] in enemy[t]:
                                en=False
                else:
                    if table[i] in enemy.keys():
                        if table[i+1] in enemy[table[i]]:
                            en=False       
        if en==True:
            sol+=['Okey']
        else:
            sol+=['No']
    data=input().split()
for s in sol:
    print(s)
# 1680048, 2022-11-12 10:39:18, P-PPxx (50%)

data=input().split()
ally=[]
enemy={}
sol=[]
en=True
while data[0]!='End':
    if data[0]=='Ally':
        ally+=[set(data[1:])]
    if data[0]=='Enemy':
        for c in ally:
            if data[2] in c:
                if data[1] in enemy:
                    enemy[data[1]].add(list(c))
                else:
                    enemy[data[1]]=set(list(c))
            elif data[1] in c:
                if data[2] in enemy:
                    enemy[data[2]].add(list(c))
                else:
                    enemy[data[2]]=set(list(c))
            else:
                if data[1] in enemy:
                    enemy[data[1]].add(data[2])
                else:
                    enemy[data[1]]=set([data[2]])
                if data[2] in enemy:
                    enemy[data[2]].add(data[1])
                else:
                    enemy[data[2]]=set([data[1]])
    if data[0]=='Table':
        table=[data[-1]]+data[1:]
        en=True
        for i in range(len(table)-1):
            for c in ally:
                if table[i] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i+1] in enemy[t]:
                                en=False
                else:
                    if table[i] in enemy.keys():
                        if table[i+1] in enemy[table[i]]:
                            en=False       
        if en==True:
            sol+=['Okay']
        else:
            sol+=['No']
    data=input().split()
for s in sol:
    print(s)
# 1680313, 2022-11-12 10:51:58, P-PPPP (83%)

data=input().split()
ally=[]
enemy={}
sol=[]
en=True
while data[0]!='End':
    if data[0]=='Ally':
        ally+=[set(data[1:])]
    if data[0]=='Enemy':
        for c in ally:
            for v in c:
                if data[2] in c:
                    if data[1] in enemy:
                        enemy[data[1]]+=[v]
                    else:
                        enemy[data[1]]=[v]
                elif data[1] in c:
                    if data[2] in enemy:
                        enemy[data[2]]+=[v]
                    else:
                        enemy[data[2]]=[v]
                else:
                    if data[1] in enemy:
                        enemy[data[1]]+=[data[2]]
                    else:
                        enemy[data[1]]=[data[2]]
                    if data[2] in enemy:
                        enemy[data[2]]+=[data[1]]
                    else:
                        enemy[data[2]]=[data[1]]
    if data[0]=='Table':
        table=[data[-1]]+data[1:]
        en=True
        for i in range(len(table)-1):
            for c in ally:
                if table[i] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i+1] in enemy[t]:
                                en=False
                else:
                    if table[i] in enemy.keys():
                        if table[i+1] in enemy[table[i]]:
                            en=False
                if table[i+1] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i] in enemy[t]:
                                en=False
        if en==True:
            sol+=['Okay']
        else:
            sol+=['No']
    data=input().split()
for s in sol:
    print(s)
# 1680353, 2022-11-12 10:53:18, P-PPPP (83%)

data=input().split()
ally=[]
enemy={}
sol=[]
en=True
while data[0]!='End':
    if data[0]=='Ally':
        ally+=[set(data[1:])]
    if data[0]=='Enemy':
        for c in ally:
            for v in c:
                if data[2] in c:
                    if data[1] in enemy:
                        enemy[data[1]]+=[v]
                    else:
                        enemy[data[1]]=[v]
                elif data[1] in c:
                    if data[2] in enemy:
                        enemy[data[2]]+=[v]
                    else:
                        enemy[data[2]]=[v]
                else:
                    if data[1] in enemy:
                        enemy[data[1]]+=[data[2]]
                    else:
                        enemy[data[1]]=[data[2]]
                    if data[2] in enemy:
                        enemy[data[2]]+=[data[1]]
                    else:
                        enemy[data[2]]=[data[1]]
    if data[0]=='Table':
        table=[data[-1]]+data[1:]
        en=True
        for i in range(len(table)-1):
            for c in ally:
                if table[i] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i+1] in enemy[t]:
                                en=False
                else:
                    if table[i] in enemy.keys():
                        if table[i+1] in enemy[table[i]]:
                            en=False
                if table[i+1] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i] in enemy[t]:
                                en=False
                else:
                    if table[i+1] in enemy.keys():
                        if table[i] in enemy[table[i+1]]:
                            en=False
        if en==True:
            sol+=['Okay']
        else:
            sol+=['No']
    data=input().split()
for s in sol:
    print(s)
# 1680384, 2022-11-12 10:54:19, compilation error (0%)

data=input().split()
ally=[]
enemy={}
sol=[]
en=True
while data[0]!='End':
    if data[0]=='Ally':
        ally+=[set(data[1:])]
    if data[0]=='Enemy':
        for c in ally:
            for v in c:
                if data[2] in c:
                    if data[1] in enemy:
                        enemy[data[1]]+=[v]
                    else:
                        enemy[data[1]]=[v]
                elif data[1] in c:
                    if data[2] in enemy:
                        enemy[data[2]]+=[v]
                    else:
                        enemy[data[2]]=[v]
                else:
                    if data[1] in enemy:
                        enemy[data[1]]+=[data[2]]
                    else:
                        enemy[data[1]]=[data[2]]
                    if data[2] in enemy:
                        enemy[data[2]]+=[data[1]]
                    else:
                        enemy[data[2]]=[data[1]]
    if data[0]=='Table':
        table=[data[-1]]+data[1:]
        en=True
        for i in range(len(table)-1):
            for c in ally:
                if table[i] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i+1] in enemy[t]:
                                en=False
                elif:
                    if table[i] in enemy.keys():
                        if table[i+1] in enemy[table[i]]:
                            en=False
                elif table[i+1] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i] in enemy[t]:
                                en=False
                else:
                    if table[i+1] in enemy.keys():
                        if table[i] in enemy[table[i+1]]:
                            en=False
        if en==True:
            sol+=['Okay']
        else:
            sol+=['No']
    data=input().split()
for s in sol:
    print(s)
# 1680406, 2022-11-12 10:54:51, P-PPPP (83%)

data=input().split()
ally=[]
enemy={}
sol=[]
en=True
while data[0]!='End':
    if data[0]=='Ally':
        ally+=[set(data[1:])]
    if data[0]=='Enemy':
        for c in ally:
            for v in c:
                if data[2] in c:
                    if data[1] in enemy:
                        enemy[data[1]]+=[v]
                    else:
                        enemy[data[1]]=[v]
                elif data[1] in c:
                    if data[2] in enemy:
                        enemy[data[2]]+=[v]
                    else:
                        enemy[data[2]]=[v]
                else:
                    if data[1] in enemy:
                        enemy[data[1]]+=[data[2]]
                    else:
                        enemy[data[1]]=[data[2]]
                    if data[2] in enemy:
                        enemy[data[2]]+=[data[1]]
                    else:
                        enemy[data[2]]=[data[1]]
    if data[0]=='Table':
        table=[data[-1]]+data[1:]
        en=True
        for i in range(len(table)-1):
            for c in ally:
                if table[i] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i+1] in enemy[t]:
                                en=False
                elif table[i] in enemy.keys():
                        if table[i+1] in enemy[table[i]]:
                            en=False
                elif table[i+1] in c:
                    for t in c:
                        if t in enemy.keys():
                            if table[i] in enemy[t]:
                                en=False
                else:
                    if table[i+1] in enemy.keys():
                        if table[i] in enemy[table[i+1]]:
                            en=False
        if en==True:
            sol+=['Okay']
        else:
            sol+=['No']
    data=input().split()
for s in sol:
    print(s)

6530008721
# 1679546, 2022-11-12 10:16:10, PP---- (33%)

countries = set()
ally = []
enemy = []
output = []
while True:
    c = input().strip().split()
    if len(c) == 1 and c[0] == 'End': break
    for e in c[1:]:
        countries.add(e)
    if c[0] == 'Ally':
        ally.append(set(c[1:]))
    if c[0] == 'Enemy':
        enemy.append(tuple(c[1:]))
    if c[0] == 'Table':
        this = c[1:]
        fx = True
        for i in range(len(this) - 1):
            if (this[i],this[i+1]) in enemy or (this[i+1], this[i]) in enemy:
                output.append('No')
                fx = False
                break
        if fx:
            if (this[len(this) - 1], this[0]) in enemy or (this[0], this[len(this) - 1]) in enemy:
                output.append('No')
                fx = False
        if fx:
            output.append('Okay')

for e in output:
    print(e)
        
            

# 1679949, 2022-11-12 10:34:43, PP---- (33%)

countries = set()
ally = []
enemy = []
output = []
while True:
    c = input().strip().split()
    if len(c) == 1 and c[0] == 'End': break
    for e in c[1:]:
        countries.add(e)
    if c[0] == 'Ally':
        ally.append(set(c[1:]))
    if c[0] == 'Enemy':
        enemy.append(set(c[1:]))
    if c[0] == 'Table':
        t = c[1:]
        fx = True
        for i in range(len(t) - 1):
            compare = t[i]
            comparewith = t[i + 1]
            for s in ally:
                if t[i] in s:
                    compare = s
            
            compare = set(compare)
            comparewith = set([t[i + 1]])
            for v in enemy:
                if len((compare | comparewith) & v) != 0:
                    output.append('No')
                    fx = False
                    break
            if not fx:
                break
        if fx:
            output.append('Okay')

for e in output:
    print(e)
        
            

# 1680471, 2022-11-12 10:57:43, PPPP-- (67%)

countries = set()
ally = []
enemy = []
output = []
while True:
    c = input().strip().split()
    if len(c) == 1 and c[0] == 'End': break
    for e in c[1:]:
        countries.add(e)
    if c[0] == 'Ally':
        ally.append(set(c[1:]))
    if c[0] == 'Enemy':
        enemy.append(set(c[1:]))
    if c[0] == 'Table':
        t = c[1:]
        fx = True
        dx = True
        gx = True
        #First step check
        for i in range(len(t) - 1):
            compare = t[i]
            comparewith = t[i + 1]
            for s in ally:
                if t[i] in s:
                    compare = s
                    dx = False
                    break
            for s in ally:
                if t[i + 1] in s:
                    comparewith = s
                    gx = False
                    break
            if dx:
                compare = set([compare])
            else:
                compare = set(compare)
            if gx:
                comparewith = set([comparewith])
            else:
                comparewith = set(comparewith)
            for v in enemy:
                if len(v - (compare | comparewith) ) == 0:
                    output.append('No')
                    fx = False
                    break
            if not fx:
                break
        #Second step check
        if fx:
            dx = True
            gx = True
            comp2 = t[len(t) - 1]
            compwith2 = t[0]
            for s in ally:
                if comp2 in s:
                    comp2 = s
                    dx = False
                    break
            for s in ally:
                if t[i + 1] in s:
                    compwith2 = s
                    gx = False
                    break
            if dx:
                comp2 = set([comp2])
            else:
                comp2 = set(comp2)
            if gx:
                compwith2 = set([compwith2])
            else:
                compwith2 = set(compwith2)
            
            comp2 = set(comp2)
            compwith2 = set(compwith2)
            for v in enemy:
                if len(v - (comp2 | compwith2)) == 0:
                        output.append('No')
                        fx = False
                        break
                    
        #Third step check
        if fx:
            output.append('Okay')

for e in output:
    print(e)
        
            

# 1680666, 2022-11-12 11:04:57, PPPPP- (83%)

countries = set()
ally = []
enemy = []
output = []
while True:
    c = input().strip().split()
    if len(c) == 1 and c[0] == 'End': break
    for e in c[1:]:
        countries.add(e)
    if c[0] == 'Ally':
        ally.append(set(c[1:]))
    if c[0] == 'Enemy':
        enemy.append(set(c[1:]))
    if c[0] == 'Table':
        t = c[1:]
        fx = True
        dx = True
        gx = True
        #First step check
        for i in range(len(t) - 1):
            compare = t[i]
            comparewith = t[i + 1]
            for s in ally:
                if t[i] in s:
                    compare = s
                    dx = False
                    break
            for s in ally:
                if t[i + 1] in s:
                    comparewith = s
                    gx = False
                    break
            if dx:
                compare = set([compare])
            else:
                compare = set(compare)
            if gx:
                comparewith = set([comparewith])
            else:
                comparewith = set(comparewith)
            for v in enemy:
                if compare != comparewith:
                    if len(v - (compare | comparewith) ) == 0:
                        output.append('No')
                        #print('here1')
                        fx = False
                        break
            dx = True
            gx = True
            if not fx:
                break
        #Second step check
        if fx:
            dx = True
            gx = True
            comp2 = t[len(t) - 1]
            compwith2 = t[0]
            for s in ally:
                if comp2 in s:
                    comp2 = s
                    dx = False
                    break
            for s in ally:
                if compwith2 in s:
                    compwith2 = s
                    gx = False
                    break
            if dx:
                comp2 = set([comp2])
            else:
                comp2 = set(comp2)
            if gx:
                compwith2 = set([compwith2])
            else:
                compwith2 = set(compwith2)
            
            comp2 = set(comp2)
            compwith2 = set(compwith2)
            for v in enemy:
                if compare != comparewith and len(v - (comp2 | compwith2)) == 0:
                        output.append('No')
                        #print('here2')
                        fx = False
                        break
                    
        #Third step check
        if fx:
            output.append('Okay')

for e in output:
    print(e)
        
            

# 1680791, 2022-11-12 11:09:18, PPPPP- (83%)

countries = set()
ally = []
enemy = []
output = []
while True:
    c = input().strip().split()
    if len(c) == 1 and c[0] == 'End': break
    for e in c[1:]:
        countries.add(e)
    if c[0] == 'Ally':
        ally.append(set(c[1:]))
    if c[0] == 'Enemy':
        enemy.append(set(c[1:]))
    if c[0] == 'Table':
        t = c[1:]
        fx = True
        dx = True
        gx = True
        #First step check
        for i in range(len(t) - 1):
            compare = t[i]
            comparewith = t[i + 1]
            for s in ally:
                if t[i] in s:
                    compare = s
                    dx = False
                    break
            for s in ally:
                if t[i + 1] in s:
                    comparewith = s
                    gx = False
                    break
            if dx:
                compare = set([compare])
            else:
                compare = set(compare)
            if gx:
                comparewith = set([comparewith])
            else:
                comparewith = set(comparewith)
            for v in enemy:
                if compare != comparewith:
                    if len(v - (compare | comparewith) ) == 0:
                        output.append('No')
                        #print('here1')
                        fx = False
                        break
            dx = True
            gx = True
            if not fx:
                break
        #Second step check
        if fx:
            dx = True
            gx = True
            comp2 = t[len(t) - 1]
            compwith2 = t[0]
            for s in ally:
                if comp2 in s:
                    comp2 = s
                    dx = False
                    break
            for s in ally:
                if compwith2 in s:
                    compwith2 = s
                    gx = False
                    break
            if dx:
                comp2 = set([comp2])
            else:
                comp2 = set(comp2)
            if gx:
                compwith2 = set([compwith2])
            else:
                compwith2 = set(compwith2)
            
            comp2 = set(comp2)
            compwith2 = set(compwith2)
            for v in enemy:
                if compare != comparewith and len(v - (comp2 | compwith2)) == 0:
                        output.append('No')
                        #print('here2')
                        fx = False
                        break
                    
        #Third step check
        if fx:
            output.append('Okay')

for e in output:
    print(e)
        
            

# 1680856, 2022-11-12 11:11:42, PPPPP- (83%)

countries = set()
ally = []
enemy = []
output = []
while True:
    c = input().strip().split()
    if len(c) == 1 and c[0] == 'End': break
    for e in c[1:]:
        countries.add(e)
    if c[0] == 'Ally':
        ally.append(set(c[1:]))
    if c[0] == 'Enemy':
        enemy.append(set(c[1:]))
    if c[0] == 'Table':
        t = c[1:]
        fx = True
        dx = True
        gx = True
        #First step check
        for i in range(len(t) - 1):
            compare = t[i]
            comparewith = t[i + 1]
            for s in ally:
                if t[i] in s:
                    compare = s
                    dx = False
                    break
            for s in ally:
                if t[i + 1] in s:
                    comparewith = s
                    gx = False
                    break
            if dx: compare = set([compare])
            else: compare = set(compare)
            if gx: comparewith = set([comparewith])
            else: comparewith = set(comparewith)
            for v in enemy:
                if compare != comparewith:
                    if len(v - (compare | comparewith) ) == 0:
                        output.append('No')
                        #print('here1')
                        fx = False
                        break
            dx = True
            gx = True
            if not fx:
                break
        #Second step check
        if fx:
            dx = True
            gx = True
            comp2 = t[len(t) - 1]
            compwith2 = t[0]
            for s in ally:
                if comp2 in s:
                    comp2 = s
                    dx = False
                    break
            for s in ally:
                if compwith2 in s:
                    compwith2 = s
                    gx = False
                    break
            if dx: comp2 = set([comp2])
            else: comp2 = set(comp2)
            if gx: compwith2 = set([compwith2])
            else: compwith2 = set(compwith2)
            for v in enemy:
                if compare != comparewith and len(v - (comp2 | compwith2)) == 0:
                        output.append('No')
                        #print('here2')
                        fx = False
                        break
                    
        #Third step check
        if fx:
            output.append('Okay')

for e in output:
    print(e)
        
            


6530115121
# 1680903, 2022-11-12 11:13:27, PP---- (33%)

GA={}
Hate={}
Country=input().strip().split()
while Country[0] != "Table":
    if Country[0] == "Ally":
        ALLY=set(Country[1::])
        for e in range(1,len(Country)):
            Hate[Country[e]] = set()
            GA[Country[e]]=(ALLY)
    if Country[0] == "Enemy":
        Hate[Country[1]] = {Country[2]}
        Hate[Country[2]] = {Country[1]}
    Country=input().strip().split()
for G in GA:
    for H in Hate:
        if G in Hate[H]:
            Hate[H]= Hate[H] | (GA[G])
for e in GA:
    for G in GA[e]:
      Hate[G]=Hate[G] | Hate[e]
while Country[0] != "End":
    T=True
    c=[]
    for i in range(1,len(Country)):
        if Country[i] not in Hate:
            Hate[Country[i]] = set()
        c.append(Country[i])
    c.append(Country[1])
    for e in range (1,len(c)-1,1):
        if c[e-1] in Hate[c[e]] or  c[e+1] in Hate[c[e]]:
            print("No")
            T=False
            break
    if T == True:
        print("Okay")
    Country=input().strip().split()
        
    
        



# 1681136, 2022-11-12 11:19:43, PPPPP- (83%)

GA={}
Hate={}
Country=input().strip().split()
while Country[0] != "Table":
    if Country[0] == "Ally":
        ALLY=set(Country[1::])
        for e in range(1,len(Country)):
            Hate[Country[e]] = set()
            GA[Country[e]]=(ALLY)
    if Country[0] == "Enemy":
        Hate[Country[1]] = {Country[2]}
        Hate[Country[2]] = {Country[1]}
    Country=input().strip().split()
for G in GA:
    for H in Hate:
        if G in Hate[H]:
            Hate[H]= Hate[H] | (GA[G])
for e in GA:
    for G in GA[e]:
      Hate[G]=Hate[G] | Hate[e]
while Country[0] != "End":
    T=True
    c=[]
    for i in range(1,len(Country)):
        if Country[i] not in Hate:
            Hate[Country[i]] = set()
        c.append(Country[i])
    c.append(Country[1])
    for e in range (1,len(c),1):
        if c[e] in Hate[c[e-1]]:
            print("No")
            T=False
            break
    if T == True:
        print("Okay")
    Country=input().strip().split()
        
    
        



# 1681178, 2022-11-12 11:20:55, compilation error (0%)

GA={}
Hate={}
Country=input().strip().split()
while Country[0] != "Table":
    if Country[0] == "Ally":
        ALLY=set(Country[1::])
        for e in range(1,len(Country)):
            Hate[Country[e]] = set()
            GA[Country[e]]=(ALLY)
    if Country[0] == "Enemy":
        Hate[Country[1]] = {Country[2]}
        Hate[Country[2]] = {Country[1]}
    Country=input().strip().split()
for G in GA:
    for H in Hate:
        if G in Hate[H]:
            Hate[H]= Hate[H] | (GA[G])
for e in GA:
    for G in GA[e]:
      Hate[G]=Hate[G] | Hate[e]
while Country[0] != "End":
    T=True
    c=[]
    for i in range(1,len(Country)):
        if Country[i] not in Hate:
            Hate[Country[i]] = set()
        c.append(Country[i])
    c.append(Country[1])
    if len(c)>1
        for e in range (1,len(c),1):
            if c[e] in Hate[c[e-1]]:
                print("No")
                T=False
                break
        if T == True:
            print("Okay")
    else:
        print("Okay")
    Country=input().strip().split()
        
    
        



# 1681190, 2022-11-12 11:21:08, PPPPP- (83%)

GA={}
Hate={}
Country=input().strip().split()
while Country[0] != "Table":
    if Country[0] == "Ally":
        ALLY=set(Country[1::])
        for e in range(1,len(Country)):
            Hate[Country[e]] = set()
            GA[Country[e]]=(ALLY)
    if Country[0] == "Enemy":
        Hate[Country[1]] = {Country[2]}
        Hate[Country[2]] = {Country[1]}
    Country=input().strip().split()
for G in GA:
    for H in Hate:
        if G in Hate[H]:
            Hate[H]= Hate[H] | (GA[G])
for e in GA:
    for G in GA[e]:
      Hate[G]=Hate[G] | Hate[e]
while Country[0] != "End":
    T=True
    c=[]
    for i in range(1,len(Country)):
        if Country[i] not in Hate:
            Hate[Country[i]] = set()
        c.append(Country[i])
    c.append(Country[1])
    if len(c)>1:
        for e in range (1,len(c),1):
            if c[e] in Hate[c[e-1]]:
                print("No")
                T=False
                break
        if T == True:
            print("Okay")
    else:
        print("Okay")
    Country=input().strip().split()
        
    
        



# 1681222, 2022-11-12 11:21:47, PPPPP- (83%)

GA={}
Hate={}
Country=input().strip().split()
while Country[0] != "Table":
    if Country[0] == "Ally":
        ALLY=set(Country[1::])
        for e in range(1,len(Country)):
            Hate[Country[e]] = set()
            GA[Country[e]]=(ALLY)
    if Country[0] == "Enemy":
        Hate[Country[1]] = {Country[2]}
        Hate[Country[2]] = {Country[1]}
    Country=input().strip().split()
for G in GA:
    for H in Hate:
        if G in Hate[H]:
            Hate[H]= Hate[H] | (GA[G])
for e in GA:
    for G in GA[e]:
      Hate[G]=Hate[G] | Hate[e]
while Country[0] != "End":
    T=True
    c=[]
    for i in range(1,len(Country)):
        if Country[i] not in Hate:
            Hate[Country[i]] = set()
        c.append(Country[i])
    c.append(Country[1])
    if len(c)>2:
        for e in range (1,len(c),1):
            if c[e] in Hate[c[e-1]]:
                print("No")
                T=False
                break
        if T == True:
            print("Okay")
    else:
        print("Okay")
    Country=input().strip().split()
        
    
        



# 1681555, 2022-11-12 11:28:51, PPPPP- (83%)

GA={}
Hate={}
Country=input().strip().split()
while Country[0] != "Table":
    if Country[0] == "Ally":
        ALLY=set(Country[1::])
        for e in range(1,len(Country)):
            Hate[Country[e]] = set()
            GA[Country[e]]=(ALLY)
    if Country[0] == "Enemy":
        Hate[Country[1]] = {Country[2]}
        Hate[Country[2]] = {Country[1]}
    Country=input().strip().split()
for G in GA:
    for H in Hate:
        if G in Hate[H]:
            Hate[H]= Hate[H] | (GA[G])
for e in GA:
    for G in GA[e]:
      Hate[G]=Hate[G] | Hate[e]
while Country[0] != "End":
    T=True
    c=[]
    for i in range(1,len(Country)):
        if Country[i] not in Hate:
            Hate[Country[i]] = set()
        c.append(Country[i])
    c.append(Country[1])
    if len(c)>2:
        for e in range (1,len(c),1):
            if c[e] in Hate[c[e-1]]:
                print("No") #A,C,A
                T=False
                break
        if T == True:
            print("Okay")
    elif len(c)==2:
        print("Okay")
    Country=input().strip().split()
        
    
        




6531322921
# 1679883, 2022-11-12 10:31:17, PP--PP (67%)

ally = list()
enemy = set()
def check(a,b):
    allied = False
    for c in ally:
        if a in c:
            for d in ally:
                if b in d:
                    allied = True
                    break
            break
        if b in c:
            for d in ally:
                if a in d:
                    allied = True
                    break
            break
    if allied:
        for e in enemy:
            if (e[0] in c) and (e[1] in d) or (e[0] in d) and (e[1] in c):
                return False
        return True
    else:
        for e in enemy:
            if a in e and b in e:
                return False
        return True
while True:
    line = input().split()
    if line[0] == "End":
        break
    if line[0] == "Ally":
        ally.append(set(line[1:]))
    elif line[0] == "Enemy":
        enemy.add(tuple(line[1:]))
    elif line[0] == "Table":
        skip = False
        for x in range(1,len(line[1:])):
            if not check(line[x],line[x+1]):
                print("No")
                skip = True
                break
        if not skip:
            if not check(line[len(line[1:])],line[1]):
                print("No")
            else:
                print("Okay")
# 1680119, 2022-11-12 10:42:28, PP--PP (67%)

ally = list()
enemy = set()
def check(a,b):
    allied = False
    for c in ally:
        if a in c:
            for d in ally:
                if b in d:
                    allied = True
                    break
            break
        if b in c:
            for d in ally:
                if a in d:
                    allied = True
                    break
            break
    if allied:
        for e in enemy:
            if ((e[0] in c) and (e[1] in d)) or ((e[0] in d) and (e[1] in c)):
                return False
        return True
    else:
        for e in enemy:
            if a in e and b in e:
                return False
        return True
while True:
    line = input().split()
    if line[0] == "End":
        break
    if line[0] == "Ally":
        ally.append(set(line[1:]))
    elif line[0] == "Enemy":
        enemy.add(tuple(line[1:]))
    elif line[0] == "Table":
        skip = False
        for x in range(1,len(line[1:])):
            if not check(line[x],line[x+1]):
                print("No")
                skip = True
                break
        if not skip:
            if not check(line[len(line[1:])],line[1]):
                print("No")
            else:
                print("Okay")
# 1680310, 2022-11-12 10:51:55, PP--PP (67%)

ally = list()
enemy = set()
def check(a,b):
    ally1 = False
    ally2 = False
    for c in ally:
        if a in c:
            ally1 = True
            for d in ally:
                if b in d:
                    ally2 = True
                    break
            break
        if b in c:
            ally2 = True
            for d in ally:
                if a in d:
                    ally1 = True
                    break
            break
    if ally1 and ally2:
        for e in enemy:
            if (e[0] in c) and (e[1] in d) or (e[0] in d) and (e[1] in c):
                return False
        return True
    elif not(ally1 and ally2):
        for e in enemy:
            if a in e and b in e:
                return False
        return True
    else:
        for e in enemy:
            if e[0] in c or e[1] in c:
                if ally1:
                    if b in e:
                        return False
                else:
                    if a in e:
                        return False
        return True
while True:
    line = input().split()
    if line[0] == "End":
        break
    if line[0] == "Ally":
        ally.append(set(line[1:]))
    elif line[0] == "Enemy":
        enemy.add(tuple(line[1:]))
    elif line[0] == "Table":
        skip = False
        for x in range(1,len(line[1:])):
            if not check(line[x],line[x+1]):
                print("No")
                skip = True
                break
        if not skip:
            if not check(line[len(line[1:])],line[1]):
                print("No")
            else:
                print("Okay")
# 1680342, 2022-11-12 10:52:53, PP--PP (67%)

ally = list()
enemy = set()
def check(a,b):
    ally1 = False
    ally2 = False
    for c in ally:
        if a in c:
            ally1 = True
            for d in ally:
                if b in d:
                    ally2 = True
                    break
            break
        if b in c:
            ally2 = True
            for d in ally:
                if a in d:
                    ally1 = True
                    break
            break
    if ally1 and ally2:
        for e in enemy:
            if (e[0] in c) and (e[1] in d) or (e[0] in d) and (e[1] in c):
                return False
        return True
    elif not(ally1 and ally2):
        for e in enemy:
            if a in e and b in e:
                return False
        return True
    else:
        for e in enemy:
            if (e[0] in c) or (e[1] in c):
                if ally1:
                    if b in e:
                        return False
                else:
                    if a in e:
                        return False
        return True
while True:
    line = input().split()
    if line[0] == "End":
        break
    if line[0] == "Ally":
        ally.append(set(line[1:]))
    elif line[0] == "Enemy":
        enemy.add(tuple(line[1:]))
    elif line[0] == "Table":
        skip = False
        for x in range(1,len(line[1:])):
            if not check(line[x],line[x+1]):
                print("No")
                skip = True
                break
        if not skip:
            if not check(line[len(line[1:])],line[1]):
                print("No")
            else:
                print("Okay")
# 1680446, 2022-11-12 10:56:29, PPP-PP (83%)

ally = list()
enemy = set()
def check(a,b):
    ally1 = False
    ally2 = False
    for c in ally:
        if a in c:
            ally1 = True
            for d in ally:
                if b in d:
                    ally2 = True
                    break
            break
        if b in c:
            ally2 = True
            for d in ally:
                if a in d:
                    ally1 = True
                    break
            break
    if ally1 and ally2:
        for e in enemy:
            if (e[0] in c) and (e[1] in d) or (e[0] in d) and (e[1] in c):
                return False
        return True
    elif not(ally1 or ally2):
        for e in enemy:
            if a in e and b in e:
                return False
        return True
    else:
        for e in enemy:
            if (e[0] in c) or (e[1] in c):
                if ally1:
                    if b in e:
                        return False
                else:
                    if a in e:
                        return False
        return True
while True:
    line = input().split()
    if line[0] == "End":
        break
    if line[0] == "Ally":
        ally.append(set(line[1:]))
    elif line[0] == "Enemy":
        enemy.add(tuple(line[1:]))
    elif line[0] == "Table":
        skip = False
        for x in range(1,len(line[1:])):
            if not check(line[x],line[x+1]):
                print("No")
                skip = True
                break
        if not skip:
            if not check(line[len(line[1:])],line[1]):
                print("No")
            else:
                print("Okay")
# 1680562, 2022-11-12 11:01:46, PPP-PP (83%)

ally = list()
enemy = set()
def check(a,b):
    ally1 = False
    ally2 = False
    for c in ally:
        if a in c:
            ally1 = True
            for d in ally:
                if b in d:
                    ally2 = True
                    break
            break
        if b in c:
            ally2 = True
            for d in ally:
                if a in d:
                    ally1 = True
                    break
            break
    if ally1 and ally2:
        for e in enemy:
            if ((e[0] in c) and (e[1] in d)) or ((e[0] in d) and (e[1] in c)):
                return False
        return True
    elif not(ally1 or ally2):
        for e in enemy:
            if a in e and b in e:
                return False
        return True
    else:
        for e in enemy:
            if (e[0] in c) or (e[1] in c):
                if ally1:
                    if b in e:
                        return False
                else:
                    if a in e:
                        return False
        return True
while True:
    line = input().split()
    if line[0] == "End":
        break
    if line[0] == "Ally":
        ally.append(set(line[1:]))
    elif line[0] == "Enemy":
        enemy.add(tuple(line[1:]))
    elif line[0] == "Table":
        skip = False
        for x in range(1,len(line[1:])):
            if not check(line[x],line[x+1]):
                print("No")
                skip = True
                break
        if not skip:
            if not check(line[len(line[1:])],line[1]):
                print("No")
            else:
                print("Okay")

6530071121
# 1680691, 2022-11-12 11:05:50, TTTTTT (0%)

x = input().split()
ally = {} # {coun : [allally]}
enemy = {} # {coun : enemy}
while x[0] != "End":
    if x[0] == "Ally":
        for e in x[1:]:
            for k in x[1:]:
                if e != k and e not in ally:
                    ally[e] = {k}
                elif e != k and e in ally:
                    ally[e].add(k)
                    
    if x[0] == "Enemy":
        if x[1] not in enemy:
            enemy[x[1]] = {x[2]}
        else :
            enemy[x[1]].add(x[2])    
        if x[2] in ally:
            enemy[x[1]] |= (ally[x[2]])
#             for e in sorted(ally[x[2]]):
#                 if e not in enemy:
#                     enemy[e] = enemy[x[1]]
#                 else :
#                     enemy[e] |= enemy[x[1]]
                            
        if x[2] not in enemy:
            enemy[x[2]] = {x[1]}
        else :
            enemy[x[2]].add(x[1])
        if x[1] in ally:
            enemy[x[2]] |= (ally[x[1]])
#             for e in sorted(ally[x[1]]):
#                 if e not in enemy:
#                     enemy[e] = enemy[x[2]]
#                 else :
#                     enemy[e] |= enemy[x[2]]
#         
        for e in sorted(enemy.keys()):
            if e in ally:
                for k in sorted(ally[e]):
                    if k not in enemy:
                        enemy[k] = enemy[e]
                    else :
                        enemy[k] |= enemy[e]
                
    if x[0] == "Table":
        table = list(x[1:])
        out = False
        for i in range(len(table)-1) :
            if table[i+1] not in enemy:
                enemy[table[i+1]] = set()
            if table[i] in enemy[table[i+1]]:
                out = True
                break
        if table[-1] in enemy[table[1]]:
            out = True
        if out == True:
            print("No")
        else :
            print("Okay")  
# 1680759, 2022-11-12 11:08:11, P-PPPP (83%)

x = input().split()
ally = {} # {coun : [allally]}
enemy = {} # {coun : enemy}
while x[0] != "End":
    if x[0] == "Ally":
        for e in x[1:]:
            for k in x[1:]:
                if e != k and e not in ally:
                    ally[e] = {k}
                elif e != k and e in ally:
                    ally[e].add(k)
                    
    if x[0] == "Enemy":
        if x[1] not in enemy:
            enemy[x[1]] = {x[2]}
        else :
            enemy[x[1]].add(x[2])    
        if x[2] in ally:
            enemy[x[1]] |= (ally[x[2]])
#             for e in sorted(ally[x[2]]):
#                 if e not in enemy:
#                     enemy[e] = enemy[x[1]]
#                 else :
#                     enemy[e] |= enemy[x[1]]
                            
        if x[2] not in enemy:
            enemy[x[2]] = {x[1]}
        else :
            enemy[x[2]].add(x[1])
        if x[1] in ally:
            enemy[x[2]] |= (ally[x[1]])
#             for e in sorted(ally[x[1]]):
#                 if e not in enemy:
#                     enemy[e] = enemy[x[2]]
#                 else :
#                     enemy[e] |= enemy[x[2]]
#         
        for e in sorted(enemy.keys()):
            if e in ally:
                for k in sorted(ally[e]):
                    if k not in enemy:
                        enemy[k] = enemy[e]
                    else :
                        enemy[k] |= enemy[e]
                
    if x[0] == "Table":
        table = list(x[1:])
        out = False
        if table[1] not in enemy:
            enemy[table[1]] = set()
        for i in range(len(table)-1) :
            if table[i+1] not in enemy:
                enemy[table[i+1]] = set()
            if table[i] in enemy[table[i+1]]:
                out = True
                break
        if table[-1] in enemy[table[1]]:
            out = True
        if out == True:
            print("No")
        else :
            print("Okay")  
   
    x = input().split()
# 1681076, 2022-11-12 11:18:16, P-PPPP (83%)

x = input().split()
ally = {} # {coun : [allally]}
enemy = {} # {coun : enemy}
while x[0] != "End":
    if x[0] == "Ally":
        for e in x[1:]:
            for k in x[1:]:
                if e != k and e not in ally:
                    ally[e] = {k}
                elif e != k and e in ally:
                    ally[e].add(k)
                    
    if x[0] == "Enemy":
        if x[1] not in enemy:
            enemy[x[1]] = {x[2]}
        else :
            enemy[x[1]].add(x[2])    
        if x[2] in ally:
            enemy[x[1]] |= (ally[x[2]])
#             for e in sorted(ally[x[2]]):
#                 if e not in enemy:
#                     enemy[e] = enemy[x[1]]
#                 else :
#                     enemy[e] |= enemy[x[1]]
                            
        if x[2] not in enemy:
            enemy[x[2]] = {x[1]}
        else :
            enemy[x[2]].add(x[1])
        if x[1] in ally:
            enemy[x[2]] |= (ally[x[1]])
#             for e in sorted(ally[x[1]]):
#                 if e not in enemy:
#                     enemy[e] = enemy[x[2]]
#                 else :
#                     enemy[e] |= enemy[x[2]]
#         
        for e in sorted(enemy.keys()):
            if e in ally:
                for k in sorted(ally[e]):
                    if k not in enemy:
                        enemy[k] = enemy[e]
                    else :
                        enemy[k] |= enemy[e]
                
    if x[0] == "Table":
        table = list(x[1:])
        if len(table) == 1 :
            print(table[0])
        else :
            out = False
            if table[1] not in enemy:
                enemy[table[1]] = set()
            for i in range(len(table)-1) :
                if table[i+1] not in enemy:
                    enemy[table[i+1]] = set()
                if table[i] in enemy[table[i+1]]:
                    out = True
                    break
            if table[-1] in enemy[table[1]]:
                out = True
            if out == True:
                print("No")
            else :
                print("Okay")  
   
    x = input().split()
# 1681106, 2022-11-12 11:19:05, P-PPPP (83%)

x = input().split()
ally = {} # {coun : [allally]}
enemy = {} # {coun : enemy}
while x[0] != "End":
    if x[0] == "Ally":
        for e in x[1:]:
            for k in x[1:]:
                if e != k and e not in ally:
                    ally[e] = {k}
                elif e != k and e in ally:
                    ally[e].add(k)
                    
    if x[0] == "Enemy":
        if x[1] not in enemy:
            enemy[x[1]] = {x[2]}
        else :
            enemy[x[1]].add(x[2])    
        if x[2] in ally:
            enemy[x[1]] |= (ally[x[2]])
#             for e in sorted(ally[x[2]]):
#                 if e not in enemy:
#                     enemy[e] = enemy[x[1]]
#                 else :
#                     enemy[e] |= enemy[x[1]]
                            
        if x[2] not in enemy:
            enemy[x[2]] = {x[1]}
        else :
            enemy[x[2]].add(x[1])
        if x[1] in ally:
            enemy[x[2]] |= (ally[x[1]])
#             for e in sorted(ally[x[1]]):
#                 if e not in enemy:
#                     enemy[e] = enemy[x[2]]
#                 else :
#                     enemy[e] |= enemy[x[2]]
#         
        for e in sorted(enemy.keys()):
            if e in ally:
                for k in sorted(ally[e]):
                    if k not in enemy:
                        enemy[k] = enemy[e]
                    else :
                        enemy[k] |= enemy[e]
                
    if x[0] == "Table":
        table = list(x[1:])
        if len(table) == 1 :
            print("Okay")
        else :
            out = False
            if table[1] not in enemy:
                enemy[table[1]] = set()
            for i in range(len(table)-1) :
                if table[i+1] not in enemy:
                    enemy[table[i+1]] = set()
                if table[i] in enemy[table[i+1]]:
                    out = True
                    break
            if table[-1] in enemy[table[1]]:
                out = True
            if out == True:
                print("No")
            else :
                print("Okay")  
   
    x = input().split()

6532201821
# 1680936, 2022-11-12 11:14:47, P---PP (50%)

ally=[]
enemy=[]
cou=0
cou2=0
while(True):
    a=input()
    if a=='End' : break
    a=a.split()
    k=a[0]
    a=a[1::]
    if k=='Ally' :
        tmp=[]
        for x in a: tmp.append(x) #;cou+=1
        ally.append(tmp)
    if k=='Enemy' :
        ind=-1
        ind2=-1
        for i in range(len(ally)) : 
            if a[0] in ally[i] : ind=i  
            if a[1] in ally[i] : ind2=i 
        tmp=[]
        if ind!=-1 : 
            for x in ally[ind] :
               tmp.append(x)
        else : tmp.append(a[0])
        
        if ind2!=-1 : 
            for x in ally[ind2] :
               tmp.append(x)
        else : tmp.append(a[1])
        enemy.append(tmp)
    if k=='Table' :
       # print(enemy)
       # print(ally)
        tr=1
        for i in range(len(a)) :
            if 1<=i<len(a)-1 :
                for x in enemy :
                    if a[i]in x and a[i-1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i-1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
                    if a[i]in x and a[i+1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i+1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
            elif i==0 :
                for x in enemy :
                    if a[i]in x and a[len(a)-1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[len(a)-1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
                    if a[i]in x and a[i+1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i+1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
            elif i==len(a)-1 :
                for x in enemy :
                    if a[i]in x and a[i-1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i-1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
                    if a[i]in x and a[0] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[0] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
            if tr==0 : print('No');break    
        
        if tr==1 : print('Okay')
        

# print(ally)
# print(enemy)
# 1680988, 2022-11-12 11:16:06, P---PP (50%)

ally=[]
enemy=[]
anw=[]
cou=0
cou2=0
while(True):
    a=input()
    if a=='End' : break
    a=a.split()
    k=a[0]
    a=a[1::]
    if k=='Ally' :
        tmp=[]
        for x in a: tmp.append(x) #;cou+=1
        ally.append(tmp)
    if k=='Enemy' :
        ind=-1
        ind2=-1
        for i in range(len(ally)) : 
            if a[0] in ally[i] : ind=i  
            if a[1] in ally[i] : ind2=i 
        tmp=[]
        if ind!=-1 : 
            for x in ally[ind] :
               tmp.append(x)
        else : tmp.append(a[0])
        
        if ind2!=-1 : 
            for x in ally[ind2] :
               tmp.append(x)
        else : tmp.append(a[1])
        enemy.append(tmp)
    if k=='Table' :
       # print(enemy)
       # print(ally)
        tr=1
        for i in range(len(a)) :
            if 1<=i<len(a)-1 :
                for x in enemy :
                    if a[i]in x and a[i-1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i-1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
                    if a[i]in x and a[i+1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i+1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
            elif i==0 :
                for x in enemy :
                    if a[i]in x and a[len(a)-1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[len(a)-1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
                    if a[i]in x and a[i+1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i+1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
            elif i==len(a)-1 :
                for x in enemy :
                    if a[i]in x and a[i-1] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i-1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
                    if a[i]in x and a[0] in x: 
                        r1=105;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[0] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
            if tr==0 : anw.append('No');break    
        
        if tr==1 : anw.append('Okay')
        
for i in anw : print(i)
# print(ally)
# print(enemy)
# 1681108, 2022-11-12 11:19:07, PPP-PP (83%)

ally=[]
enemy=[]
anw=[]
cou=0
cou2=0
while(True):
    a=input()
    if a=='End' : break
    a=a.split()
    k=a[0]
    a=a[1::]
    if k=='Ally' :
        tmp=[]
        for x in a: tmp.append(x) #;cou+=1
        ally.append(tmp)
    if k=='Enemy' :
        ind=-1
        ind2=-1
        for i in range(len(ally)) : 
            if a[0] in ally[i] : ind=i  
            if a[1] in ally[i] : ind2=i 
        tmp=[]
        if ind!=-1 : 
            for x in ally[ind] :
               tmp.append(x)
        else : tmp.append(a[0])
        
        if ind2!=-1 : 
            for x in ally[ind2] :
               tmp.append(x)
        else : tmp.append(a[1])
        enemy.append(tmp)
    if k=='Table' :
       # print(enemy)
       # print(ally)
        tr=1
        for i in range(len(a)) :
            if 1<=i<len(a)-1 :
                for x in enemy :
                    if a[i]in x and a[i-1] in x: 
                        r1=109;r2=105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i-1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
                    if a[i]in x and a[i+1] in x: 
                        r1=1091;r2=1055
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i+1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
            elif i==0 :
                for x in enemy :
                    if a[i]in x and a[len(a)-1] in x: 
                        r1=1093;r2=1035
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[len(a)-1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
                    if a[i]in x and a[i+1] in x: 
                        r1=1069;r2=1305
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i+1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
            elif i==len(a)-1 :
                for x in enemy :
                    if a[i]in x and a[i-1] in x: 
                        r1=1089;r2=1505
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i-1] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
                    if a[i]in x and a[0] in x: 
                        r1=1039;r2=1105
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[0] in ally[d] : r2=d
                        if r1!=r2 : tr=0;break
            if tr==0 : anw.append('No');break    
        
        if tr==1 : anw.append('Okay')
        
for i in anw : print(i)
# print(ally)
# print(enemy)
# 1681219, 2022-11-12 11:21:43, PPP-PP (83%)

ally=[]
enemy=[]
anw=[]
cou=0
cou2=0
while(True):
    a=input()
    if a=='End' : break
    a=a.split()
    k=a[0]
    a=a[1::]
    if k=='Ally' :
        tmp=[]
        for x in a: tmp.append(x) #;cou+=1
        ally.append(tmp)
    if k=='Enemy' :
        ind=-1
        ind2=-1
        for i in range(len(ally)) : 
            if a[0] in ally[i] : ind=i  
            if a[1] in ally[i] : ind2=i 
        tmp=[]
        if ind!=-1 : 
            for x in ally[ind] :
               tmp.append(x)
        else : tmp.append(a[0])
        
        if ind2!=-1 : 
            for x in ally[ind2] :
               tmp.append(x)
        else : tmp.append(a[1])
        enemy.append(tmp)
    if k=='Table' :
       # print(enemy)
       # print(ally)
        tr=1
        for i in range(len(a)) :
            if 1<=i<len(a)-1 :
                for x in enemy :
                    if a[i]in x and a[i-1] in x: 
                        r1=-1;r2=-1
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i-1] in ally[d] : r2=d
                        if r1!=r2 or r1==-1 or r2==-1: tr=0;break
                    if a[i]in x and a[i+1] in x: 
                        r1=-1;r2=-1
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i+1] in ally[d] : r2=d
                        if r1!=r2 or r1==-1 or r2==-1 : tr=0;break
            elif i==0 :
                for x in enemy :
                    if a[i]in x and a[len(a)-1] in x: 
                        r1=-1;r2=-1
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[len(a)-1] in ally[d] : r2=d
                        if r1!=r2 or r1==-1 or r2==-1 : tr=0;break
                    if a[i]in x and a[i+1] in x: 
                        r1=-1;r2=-1
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i+1] in ally[d] : r2=d
                        if r1!=r2 or r1==-1 or r2==-1 : tr=0;break
            elif i==len(a)-1 :
                for x in enemy :
                    if a[i]in x and a[i-1] in x: 
                        r1=-1;r2=-1
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[i-1] in ally[d] : r2=d
                        if r1!=r2 or r1==-1 or r2==-1 : tr=0;break
                    if a[i]in x and a[0] in x: 
                        r1=-1;r2=-1
                        for d in range(len(ally)) : 
                            if a[i] in ally[d] : r1=d
                            if a[0] in ally[d] : r2=d
                        if r1!=r2 or r1==-1 or r2==-1 : tr=0;break
            if tr==0 : anw.append('No');break    
        
        if tr==1 : anw.append('Okay')
        
for i in anw : print(i)
# print(ally)
# print(enemy)

6430201321
# 1680920, 2022-11-12 11:14:01, PPPP-P (83%)

ally={}
enemy={}
#t={america:[[ally1,ally2],[enermy1.enermy2]]}
while True:
    a = input().split()
    
    if a == ['End']:
        break

    elif a[0] == 'Ally':
        for i in range(1,len(a)):
            #not remove itself
            ally[a[i]] = a[1:]
    
    elif a[0] == 'Enemy':
        if a[1] in enemy:
            if a[2] in ally:
                enemy[a[1]] += ally[a[2]]
            else:
                enemy[a[1]] += [a[2]]        
        else:
            if a[2] in ally:
                enemy[a[1]] = ally[a[2]]
            else:
                enemy[a[1]] = [a[2]]
                
        if a[2] in enemy:
            if a[1] in ally:
                enemy[a[2]] += ally[a[1]]
            else:
                enemy[a[2]] += [a[1]]        
        else:
            if a[1] in ally:
                enemy[a[2]] = ally[a[1]]
            else:
                enemy[a[2]] = [a[1]]
            
    for i in ally:
        if i in enemy:
            for j in ally[i]:
                enemy[j] = enemy[i]
    
    if a[0] == 'Table':
        check = 0
        for i in range(1,len(a)):
            if a[i] not in enemy:
                check += 0
            else:
                if i == 1:
                    if a[-1] in enemy[a[1]] or a[2] in enemy[a[1]]:
                        check += 1
                elif a[i] == a[-1]:
                    if a[-2] in enemy[a[-1]] or a[1] in enemy[a[-1]]:
                        check += 1
                elif a[i-1] in enemy[a[i]] or a[i+1] in enemy[a[i]]:
                    check += 1
        if check > 0:
            print('No')
        elif check == 0:
            print('Okay')
# 1680926, 2022-11-12 11:14:18, PPPP-P (83%)

ally={}
enemy={}

while True:
    a = input().split()
    
    if a == ['End']:
        break

    elif a[0] == 'Ally':
        for i in range(1,len(a)):

            ally[a[i]] = a[1:]
    
    elif a[0] == 'Enemy':
        if a[1] in enemy:
            if a[2] in ally:
                enemy[a[1]] += ally[a[2]]
            else:
                enemy[a[1]] += [a[2]]        
        else:
            if a[2] in ally:
                enemy[a[1]] = ally[a[2]]
            else:
                enemy[a[1]] = [a[2]]
                
        if a[2] in enemy:
            if a[1] in ally:
                enemy[a[2]] += ally[a[1]]
            else:
                enemy[a[2]] += [a[1]]        
        else:
            if a[1] in ally:
                enemy[a[2]] = ally[a[1]]
            else:
                enemy[a[2]] = [a[1]]
            
    for i in ally:
        if i in enemy:
            for j in ally[i]:
                enemy[j] = enemy[i]
    
    if a[0] == 'Table':
        check = 0
        for i in range(1,len(a)):
            if a[i] not in enemy:
                check += 0
            else:
                if i == 1:
                    if a[-1] in enemy[a[1]] or a[2] in enemy[a[1]]:
                        check += 1
                elif a[i] == a[-1]:
                    if a[-2] in enemy[a[-1]] or a[1] in enemy[a[-1]]:
                        check += 1
                elif a[i-1] in enemy[a[i]] or a[i+1] in enemy[a[i]]:
                    check += 1
        if check > 0:
            print('No')
        elif check == 0:
            print('Okay')

6531341821
# 1681193, 2022-11-12 11:21:10, P-PPPP (83%)

Ally=[]
Enemy=[]
All=[]
while True:
    s=input().split()
    if s[0]=='Table':
        break
    if s[0]=='End':
        exit
    if s[0]=='Ally':
        Ally.append(s[1:])
    elif s[0]=='Enemy':
        Enemy.append(s[1:])
    s=s[1:]
    for i in s:
        if i not in All:
            All.append(i)

Enemy1={}
for i in All:
    Enemy1[i]=[]
for i in All:
    temp=[]
    for j in Enemy: 
        if i in j:
            for k in j:
                if k!=i:
                    temp.append(k)

    Enemy1[i]=temp


Ally1={}
for i in All:
    Ally1[i]=[]
for i in All:
    for j in Ally:
        if i in j:
            temp=[]
            for k in j:
                if k!=i:
                    temp.append(k)
            Ally1[i]=temp

Enemy2={}
for i in All:
    temp=[]
    for j in Ally1[i]:
        for k in Enemy1[j]:
            temp.append(k)
            for m in Ally1[k]:
                temp.append(m)
    for l in Enemy1[i]:
        temp.append(l)
        for m in Ally1[l]:
                temp.append(m)
    Enemy2[i]=temp

while True:
    
    
    if s[0]=='End':
        break
    s=s[1:]
    s.append(s[1])
    Okay=0
    for i in range(len(s)-1):
        if s[i] in All:
            if s[i+1] in Enemy2[s[i]]:
                Okay=1
                break
    if Okay==1:
        print('No')
    else:
        print('Okay')
    s=input().split()  


   
                        
                        
    


# 1681290, 2022-11-12 11:23:46, P-PPPP (83%)

Ally=[]
Enemy=[]
All=[]
while True:
    s=input().split()
    if s[0]=='Table':
        break
    if s[0]=='End':
        break
    if s[0]=='Ally':
        Ally.append(s[1:])
    elif s[0]=='Enemy':
        Enemy.append(s[1:])
    s=s[1:]
    for i in s:
        if i not in All:
            All.append(i)

Enemy1={}
for i in All:
    Enemy1[i]=[]
for i in All:
    temp=[]
    for j in Enemy: 
        if i in j:
            for k in j:
                if k!=i:
                    temp.append(k)
    Enemy1[i]=temp


Ally1={}
for i in All:
    Ally1[i]=[]
for i in All:
    for j in Ally:
        if i in j:
            temp=[]
            for k in j:
                if k!=i:
                    temp.append(k)
            Ally1[i]=temp

Enemy2={}
for i in All:
    temp=[]
    for j in Ally1[i]:
        for k in Enemy1[j]:
            temp.append(k)
            for m in Ally1[k]:
                temp.append(m)
    for l in Enemy1[i]:
        temp.append(l)
        for m in Ally1[l]:
                temp.append(m)
    Enemy2[i]=temp

while True:
    
    
    if s[0]=='End':
        break
    s=s[1:]
    s.append(s[1])
    Okay=0
    for i in range(len(s)-1):
        if s[i] in All:
            if s[i+1] in Enemy2[s[i]]:
                Okay=1
                break
    if Okay==1:
        print('No')
    else:
        print('Okay')
    s=input().split()  


   
                        
                        
    



6530101321
# 1680976, 2022-11-12 11:15:55, PPPPPx (83%)

ally = {}
enemy = {}


dt = input().split()

while dt[0] == "Ally" :
    for x in dt[1:] :
        grp = []
        for y in dt[1:] :
            grp.append(y)
        ally[x] = grp
    dt = input().split()

while dt[0] == "Enemy" :
    blue, red = dt[1], dt[2]
    if blue and red in ally :
        for name in ally[blue] :
            if name not in enemy :
                enemy[name] = []
            for x in ally[red] :
                enemy[name].append(x)
        for name in ally[red] :
            if name not in enemy :
                enemy[name] = []
            for x in ally[blue] :
                enemy[name].append(x)
    elif blue in ally and red not in ally :
        for name in ally[blue] :
            if name not in enemy :
                enemy[name] = []
            enemy[name].append(red)
        if red not in enemy :
            enemy[red] = []
        for x in ally[blue] :
            enemy[red].append(x)
    elif blue not in ally and red in ally :
        for name in ally[red] :
            if name not in enemy :
                enemy[name] = []
            enemy[name].append(blue)
        if red not in enemy :
            enemy[blue] = []
        for x in ally[red] :
            enemy[blue].append(x)
    elif blue and red not in ally :
        if blue not in enemy :
            enemy[blue] = []
        if red not in enemy :
            enemy[red] = []
        enemy[blue].append(red)
        enemy[red].append(blue)
    dt = input().split()

while dt[0] == "Table" :
    table = dt[1:]
    pss = False
    for i in range(len(table)) :
        if table[i] in enemy :
            if table[i-1] in enemy[table[i]] :
                print("No")
                pss = True
                break
            elif table[(i+1)%len(table)] in enemy[table[i]] :
                print("No")
                pss = True
                break
    if pss == False : print("Okay")
    dt = input().split()


6530171221
# 1681028, 2022-11-12 11:17:01, P-PPPP (83%)

teams = list()
enermys = list()
def ttt(c):
    a = ''
    j = True
    for i in teams:
        if j == False: break
        for l in i :
            if c == l:
                a = i
                j = False
                break
            elif not c in l :a = c
    return a
def en(f,s):
    x = ''
    for i,v in enermys:
        if ((f in i) and (s in v)) or ((f in v) and (s in i)):
            return 'No'
        else : x = 'Okay'
    return x 
def fi(l):
    for i in l :
        if i == 'No' :return 'No'
    return 'Okay'
final = []
while True :
    allys = set()
    x = input()
    if x == 'End': break
    x = x.split()
    if x[0] == 'Ally':
        for i in x[1:]:
            allys.add(i)
    teams.append(allys)
    if x[0] == 'Enemy':
        enermys.append((ttt(x[1]),ttt(x[2])))
    if x[0] == 'Table':
        so = []
        for i in x[1:]:
            so.append(i)
        so.append(x[1])
        l = []
        for k in range(len(so)-1):
            l.append(en(so[k],so[k+1]))
        final.append(fi(l))
for ff in final:
    print(ff)

Max Score = 67


6531019821
# 1680321, 2022-11-12 10:52:22, P----- (17%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                  ae = da[enemy]
                  de[ue[i]] = ae
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        for i in range(1,len(ut)):
            if ut[i] in nde:
                if ut[i-1] in nde[ut[i]]:
                    out.append('No')
                else:
                    out.append('Okay')
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e)
# 1680365, 2022-11-12 10:53:45, P----- (17%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                  ae = da[enemy]
                  de[ue[i]] = ae
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        for i in range(1,len(ut)-1):
            if ut[i] in nde:
                if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                    out.append('No')
                else:
                    out.append('Okay')
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e)
# 1680412, 2022-11-12 10:54:59, P----- (17%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                  ae = da[enemy]
                  de[ue[i]] = ae
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        for i in range(1,len(ut)-1):
            if ut[i] in nde:
                if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                    out.append('No')
                else:
                    out.append('Okay')
            else:
                out.append('Okay')
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e + '\n')
# 1680430, 2022-11-12 10:55:27, P----- (17%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                  ae = da[enemy]
                  de[ue[i]] = ae
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        for i in range(1,len(ut)-1):
            if ut[i] in nde:
                if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                    out.append('No')
                else:
                    out.append('Okay')
            else:
                out.append('Okay')
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e + '\n')
# 1680539, 2022-11-12 11:00:31, P---P- (33%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                  ae = da[enemy]
                  de[ue[i]] = ae
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        if len(ut) > 2:
            for i in range(1,len(ut)-1):
                if ut[i] in nde:
                    if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                        out.append('No')
                    else:
                        out.append('Okay')
                else:
                    out.append('Okay')
        else:
            for o in range(len(ut)):
                if o == 0:
                    if ut[o] in de:
                        if ut[1] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay')
                elif o == 1:
                    if ut[o] in de:
                        if ut[0] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay') 
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e + '\n')
# 1680651, 2022-11-12 11:04:31, P---P- (33%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                  ae = da[enemy]
                  de[ue[i]] = ae
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        if len(ut) > 2:
            for i in range(1,len(ut)-1):
                if ut[i] in nde:
                    if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                        out.append('No')
                    else:
                        out.append('Okay')
                else:
                    out.append('Okay')
            if ut[0] in nde and ut[-1] in nde[ut[0]]:
                out.append('No')
        else:
            for o in range(len(ut)):
                if o == 0:
                    if ut[o] in de:
                        if ut[1] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay')
                elif o == 1:
                    if ut[o] in de:
                        if ut[0] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay') 
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e + '\n')
# 1680700, 2022-11-12 11:06:25, P---P- (33%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                  ae = da[enemy]
                  de[ue[i]] = ae
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        if len(ut) > 2:
            for i in range(1,len(ut)-1):
                if ut[i] in nde:
                    if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                        out.append('No')
                    else:
                        out.append('Okay')
                else:
                    out.append('Okay')
            if (ut[0] in nde and ut[-1] in nde[ut[0]]) or (ut[-1] in nde and ut[0] in nde[ut[-1]]):
                out.append('No')
        else:
            for o in range(len(ut)):
                if o == 0:
                    if ut[o] in de:
                        if ut[1] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay')
                elif o == 1:
                    if ut[o] in de:
                        if ut[0] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay') 
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e + '\n')
# 1680846, 2022-11-12 11:11:19, ------ (0%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                ae = da[enemy]
                de[ue[i]] = ae
            elif enemy not in da:
                if ue[i] in de:
                    de[ue[i]] += [enemy]
                else:
                    de[ue[i]] = [enemy]
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        if len(ut) > 2:
            for i in range(1,len(ut)-1):
                if ut[i] in nde:
                    if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                        out.append('No')
                    else:
                        out.append('Okay')
                else:
                    out.append('Okay')
            if (ut[0] in nde and ut[-1] in nde[ut[0]]) or (ut[-1] in nde and ut[0] in nde[ut[-1]]):
                out.append('No')
        else:
            for o in range(len(ut)):
                if o == 0:
                    if ut[o] in de:
                        if ut[1] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay')
                elif o == 1:
                    if ut[o] in de:
                        if ut[0] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay') 
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
print(nde)
for e in output:
    print(e + '\n')
# 1680875, 2022-11-12 11:12:20, PP-PP- (67%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                ae = da[enemy]
                de[ue[i]] = ae
            elif enemy not in da:
                if ue[i] in de:
                    de[ue[i]] += [enemy]
                else:
                    de[ue[i]] = [enemy]
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        if len(ut) > 2:
            for i in range(1,len(ut)-1):
                if ut[i] in nde:
                    if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                        out.append('No')
                    else:
                        out.append('Okay')
                else:
                    out.append('Okay')
            if (ut[0] in nde and ut[-1] in nde[ut[0]]) or (ut[-1] in nde and ut[0] in nde[ut[-1]]):
                out.append('No')
        else:
            for o in range(len(ut)):
                if o == 0:
                    if ut[o] in de:
                        if ut[1] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay')
                elif o == 1:
                    if ut[o] in de:
                        if ut[0] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay') 
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e + '\n')
# 1681020, 2022-11-12 11:16:51, P--PP- (50%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                ae = da[enemy]
                de[ue[i]] = ae
            elif enemy not in da:
                if ue[i] in de:
                    de[ue[i]] += [enemy]
                else:
                    de[ue[i]] = [enemy]
    elif z[0] == 'Table':
        if len(de) != 0 and len(da) != 0:
            for key in de.keys():
                if key in da:
                    for e in da[key]:
                        nde[e] = de[key]
                else:
                    nde[key] = de[key]
            ut = z[1::]
            out = []
            if len(ut) > 2:
                for i in range(1,len(ut)-1):
                    if ut[i] in nde:
                        if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay')
                if (ut[0] in nde and ut[-1] in nde[ut[0]]) or (ut[-1] in nde and ut[0] in nde[ut[-1]]):
                    out.append('No')
            else:
                for o in range(len(ut)):
                    if o == 0:
                        if ut[o] in de:
                            if ut[1] in de[ut[o]]:
                                out.append('No')
                            else:
                                out.append('Okay')
                        else:
                            out.append('Okay')
                    elif o == 1:
                        if ut[o] in de:
                            if ut[0] in de[ut[o]]:
                                out.append('No')
                            else:
                                out.append('Okay')
                        else:
                            out.append('Okay') 
            if 'No' in out:
                output.append('No')
            else:
                output.append('Okay')
        elif len(de) == 0:
            output.append('Okay')
for e in output:
    print(e + '\n')
# 1681056, 2022-11-12 11:17:39, compilation error (0%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                ae = da[enemy]
                de[ue[i]] = ae
            elif enemy not in da:
                if ue[i] in de:
                    de[ue[i]] += [enemy]
                else:
                    de[ue[i]] = [enemy]
    elif z[0] == 'Table':
        if len(de) != 0:
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        if len(ut) > 2:
            for i in range(1,len(ut)-1):
                if ut[i] in nde:
                    if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                        out.append('No')
                    else:
                        out.append('Okay')
                else:
                    out.append('Okay')
            if (ut[0] in nde and ut[-1] in nde[ut[0]]) or (ut[-1] in nde and ut[0] in nde[ut[-1]]):
                out.append('No')
        else:
            for o in range(len(ut)):
                if o == 0:
                    if ut[o] in de:
                        if ut[1] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay')
                elif o == 1:
                    if ut[o] in de:
                        if ut[0] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay') 
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e + '\n')
# 1681083, 2022-11-12 11:18:28, PP-PP- (67%)

da =dict()
de = dict()
nde = dict() 
output = []
while True:
    x = input()
    if x == 'End':
        break
    z = x.split()
    if z[0] == 'Ally':
        uu = z[1::]
        for e in uu:
            n = list(uu)
            da[e] = n
    elif z[0] == 'Enemy':
        ue = z[1::]
        for i in range(len(ue)):
            ae = []
            if i == 0:
                enemy = ue[1]
            else:
                enemy = ue[0]
            if enemy in da: 
                ae = da[enemy]
                de[ue[i]] = ae
            elif enemy not in da:
                if ue[i] in de:
                    de[ue[i]] += [enemy]
                else:
                    de[ue[i]] = [enemy]
    elif z[0] == 'Table':
        for key in de.keys():
            if key in da:
                for e in da[key]:
                    nde[e] = de[key]
            else:
                nde[key] = de[key]
        ut = z[1::]
        out = []
        if len(ut) > 2:
            for i in range(1,len(ut)-1):
                if ut[i] in nde:
                    if ut[i+1] in nde[ut[i]] or ut[i-1] in nde[ut[i]]:
                        out.append('No')
                    else:
                        out.append('Okay')
                else:
                    out.append('Okay')
            if (ut[0] in nde and ut[-1] in nde[ut[0]]) or (ut[-1] in nde and ut[0] in nde[ut[-1]]):
                out.append('No')
        else:
            for o in range(len(ut)):
                if o == 0:
                    if ut[o] in de:
                        if ut[1] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay')
                elif o == 1:
                    if ut[o] in de:
                        if ut[0] in de[ut[o]]:
                            out.append('No')
                        else:
                            out.append('Okay')
                    else:
                        out.append('Okay') 
        if 'No' in out:
            output.append('No')
        else:
            output.append('Okay')
for e in output:
    print(e + '\n')

6230089221
# 1679992, 2022-11-12 10:36:57, ------ (0%)

ally={}
enemy={}
s=input().strip()
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    if s[0]=="Table":
        print("No")
        
    s=input().strip()
# 1680005, 2022-11-12 10:37:29, P----- (17%)

ally={}
enemy={}
s=input().strip()
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    if s[0]=="Table":
        print("Okay")
        
    s=input().strip()
# 1680056, 2022-11-12 10:39:36, ------ (0%)

ally={}
enemy={}
s=input().strip()
c=0
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    if s[0]=="Table":
        if c%2==0:
            print("No")
        else:
            print("Okay")
        
    s=input().strip()
# 1680061, 2022-11-12 10:39:46, P----- (17%)

ally={}
enemy={}
s=input().strip()
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    if s[0]=="Table":
        print("Okay")
        
    s=input().strip()
# 1681113, 2022-11-12 11:19:20, ------ (0%)

ally={}
enemy={}
data={}
s=input().strip()
c=0
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    for e in ally:
        if e not in data:
            data[e]=set()
    for e in enemy:
        if e not in data:
            data[e]=set()
    for e in data:
        if e in enemy:
            data[e]=data[e].union(enemy[e])
    for e in data:
        for k in data[e]:
            if k in ally:
                data[e]=data[e].union(ally[k])
    if s[0]=="Table":
        c=True
        s=s[1::1]
        s+=[s[0]]
        print(s)
        for i in range(0,len(s)-1,1):
            if s[i] in data and s[i+1] in data:
                if s[i] in data[s[i+1]] or s[i+1] in data[s[i]]:
                    c=False

    if c==True:
        print("Okay")
    else:
        print("No")
        
                
            
    s=input().strip()
# 1681165, 2022-11-12 11:20:38, ------ (0%)

ally={}
enemy={}
data={}
s=input().strip()
c=0
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    for e in ally:
        if e not in data:
            data[e]=set()
    for e in enemy:
        if e not in data:
            data[e]=set()
    for e in data:
        if e in enemy:
            data[e]=data[e].union(enemy[e])
    for e in data:
        for k in data[e]:
            if k in ally:
                data[e]=data[e].union(ally[k])
    if s[0]=="Table":
        c=True
        s=s[1::1]
        s+=[s[0]]
        print(s)
        for i in range(0,len(s)-1,1):
            if s[i] in data and s[i+1] in data:
                if s[i] in data[s[i+1]] or s[i+1] in data[s[i]]:
                    c=False

        if c==True:
            print("Okay")
        else:
            print("No")
        
                
            
    s=input().strip()
# 1681231, 2022-11-12 11:22:09, PPPP-- (67%)

ally={}
enemy={}
data={}
s=input().strip()
c=0
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    for e in ally:
        if e not in data:
            data[e]=set()
    for e in enemy:
        if e not in data:
            data[e]=set()
    for e in data:
        if e in enemy:
            data[e]=data[e].union(enemy[e])
    for e in data:
        for k in data[e]:
            if k in ally:
                data[e]=data[e].union(ally[k])
    if s[0]=="Table":
        c=True
        s=s[1::1]
        s+=[s[0]]
        for i in range(0,len(s)-1,1):
            if s[i] in data and s[i+1] in data:
                if s[i] in data[s[i+1]] or s[i+1] in data[s[i]]:
                    c=False
        if c==True:
            print("Okay")
        else:
            print("No")
        
                
            
    s=input().strip()
# 1681284, 2022-11-12 11:23:35, PPPP-- (67%)

ally={}
enemy={}
data={}
s=input().strip()
c=0
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    for e in ally:
        if e not in data:
            data[e]=set()
    for e in enemy:
        if e not in data:
            data[e]=set()
    for e in data:
        if e in enemy:
            data[e]=data[e].union(enemy[e])
    for e in data:
        for k in data[e]:
            if k in ally:
                data[e]=data[e].union(ally[k])
    if s[0]=="Table":
        c=True
        s=s[1::1]
        s+=[s[0]]
        for i in range(0,len(s)-1,1):
            if s[i] in data and s[i+1] in data:
                if s[i] in data[s[i+1]] or s[i+1] in data[s[i]]:
                    c=False
        if c==True:
            print("Okay")
        else:
            print("No")
    s=input().strip()
# 1681468, 2022-11-12 11:27:10, PxPP-- (50%)

ally={}
enemy={}
data={}
s=input().strip()
c=0
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    for e in ally:
        if e not in data:
            data[e]=set()
    for e in enemy:
        if e not in data:
            data[e]=set()
    for e in data:
        if e in enemy:
            data[e]=data[e].union(enemy[e])
    for e in data:
        for k in data[e]:
            if k in ally:
                data[e]=data[e].union(ally[k])
    for e in ally[e]:
        for k in ally[e]:
            if k in enemy:
                data[e]=data[e].union(enemy[k])
    if s[0]=="Table":
        c=True
        s=s[1::1]
        s+=[s[0]]
        for i in range(0,len(s)-1,1):
            if s[i] in data and s[i+1] in data:
                if s[i] in data[s[i+1]] or s[i+1] in data[s[i]]:
                    c=False
        if c==True:
            print("Okay")
        else:
            print("No")
    s=input().strip()
# 1681495, 2022-11-12 11:27:40, PPPP-- (67%)

ally={}
enemy={}
data={}
s=input().strip()
c=0
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    for e in ally:
        if e not in data:
            data[e]=set()
    for e in enemy:
        if e not in data:
            data[e]=set()
    for e in data:
        if e in enemy:
            data[e]=data[e].union(enemy[e])
    for e in data:
        for k in data[e]:
            if k in ally:
                data[e]=data[e].union(ally[k])
    if s[0]=="Table":
        c=True
        s=s[1::1]
        s+=[s[0]]
        for i in range(0,len(s)-1,1):
            if s[i] in data and s[i+1] in data:
                if s[i] in data[s[i+1]] or s[i+1] in data[s[i]]:
                    c=False
        if c==True:
            print("Okay")
        else:
            print("No")
    s=input().strip()
# 1681513, 2022-11-12 11:28:07, PPPP-- (67%)

ally={}
enemy={}
data={}
s=input().strip()
c=0
while s!="End":
    s=s.split(" ")
    if s[0]=="Ally":
        for i in range(1,len(s),1):
            ally[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    ally[s[i]].add(s[j])
    if s[0]=="Enemy":
        for i in range(1,len(s),1):
            enemy[s[i]]=set()
            for j in range(1,len(s),1):
                if s[j]!=s[i]:
                    enemy[s[i]].add(s[j])
    for e in ally:
        if e not in data:
            data[e]=set()
    for e in enemy:
        if e not in data:
            data[e]=set()
    for e in data:
        if e in enemy:
            data[e]=data[e].union(enemy[e])
    for e in data:
        for k in data[e]:
            if k in ally:
                data[e]=data[e].union(ally[k])
    if s[0]=="Table":
        c=True
        s=s[1::1]
        s+=[s[0]]
        for i in range(0,len(s)-1,1):
            if s[i] in data and s[i+1] in data:
                if s[i] in data[s[i+1]] or s[i+1] in data[s[i]]:
                    c=False
        if c==True:
            print("Okay")
        else:
            print("No")
    s=input().strip()

6531318421
# 1680140, 2022-11-12 10:43:21, ------ (0%)

print('No')
print('Okay')
print('Okay')
# 1680147, 2022-11-12 10:43:30, ------ (0%)

print('No')
print('No')
print('Okay')
# 1680528, 2022-11-12 11:00:07, PP--Px (50%)

allys = {}  # {country: [Allys...]}
ems = {}

while True:
    n = input().split()
    if n[0] == 'End':
        break
# allys = {'America': ['England', 'Ukraine', 'France'], 'England': ['America', 'Ukraine', 'France'],
#     'Ukraine': ['America', 'England', 'France'], 'France': ['America', 'England', 'Ukraine'],
#  'Russia': ['China']}
# ems = {'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif n[0] == 'Ally':
        for i in n[1:]:
            allys[i] = [x for x in n[1:] if x != i]
    elif n[0] == 'Enemy':
        ems[n[1]] = [n[2]]
        ems[n[2]] = [n[1]]
        if n[2] in allys:
            for t in allys[n[2]]:
                if t not in ems:
                    ems[t] = []
                ems[t].append(n[1])
                ems[n[1]].append(t)
                for e in allys[n[1]]:
                    ems[t].append(e)
                    if e not in ems:
                        ems[e] = []
                    ems[e].append(t)
            for x in allys[n[1]]:
                if x not in ems:
                    ems[x] = []
                ems[x].append(n[2])
                ems[n[2]].append(x)
    elif n[0] == 'Table':
        cansit = True
        ts = n[1:] + [n[1]]
        for i in range(len(ts)-1):
            if ts[i] in ems and ts[i+1] in ems:
                if ts[i+1] in ems[ts[i]] or ts[i] in ems[ts[i+1]]:
                    cansit = False
                    break
        if cansit:
            print('Okay')
        else:
            print('No')


# Table America England Iceland France Iran Russia Iraq
#                                 |      |
# Table America England Russia America


# print(allys)
# print(ems)

# 1680637, 2022-11-12 11:04:11, PP-PPx (67%)

allys = {}  # {country: [Allys...]}
ems = {}

while True:
    n = input().split()
    if n[0] == 'End':
        break
# allys = {'America': ['England', 'Ukraine', 'France'], 'England': ['America', 'Ukraine', 'France'],
#     'Ukraine': ['America', 'England', 'France'], 'France': ['America', 'England', 'Ukraine'],
#  'Russia': ['China']}
# ems = {'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif n[0] == 'Ally':
        for i in n[1:]:
            allys[i] = [x for x in n[1:] if x != i]
    elif n[0] == 'Enemy':
        ems[n[1]] = [n[2]]
        ems[n[2]] = [n[1]]
        if n[2] in allys:
            for t in allys[n[2]]:
                if t not in ems:
                    ems[t] = []
                ems[t].append(n[1])
                ems[n[1]].append(t)
                for e in allys[n[1]]:
                    ems[t].append(e)
                    if e not in ems:
                        ems[e] = []
                    ems[e].append(t)
        if n[1] in allys:
            for x in allys[n[1]]:
                if x not in ems:
                    ems[x] = []
                ems[x].append(n[2])
                ems[n[2]].append(x)
    elif n[0] == 'Table':
        cansit = True
        ts = n[1:] + [n[1]]
        for i in range(len(ts)-1):
            if ts[i] in ems and ts[i+1] in ems:
                if ts[i+1] in ems[ts[i]] or ts[i] in ems[ts[i+1]]:
                    cansit = False
                    break
        if cansit:
            print('Okay')
        else:
            print('No')


# Table America England Iceland France Iran Russia Iraq
#                                 |      |
# Table America England Russia America


# print(allys)
# print(ems)

# 1680672, 2022-11-12 11:05:11, PP-PPx (67%)

allys = {}  # {country: [Allys...]}
ems = {}

while True:
    n = input().split()
    if n[0] == 'End':
        break
# allys = {'America': ['England', 'Ukraine', 'France'], 'England': ['America', 'Ukraine', 'France'],
#     'Ukraine': ['America', 'England', 'France'], 'France': ['America', 'England', 'Ukraine'],
#  'Russia': ['China']}
# ems = {'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif n[0] == 'Ally':
        for i in n[1:]:
            allys[i] = [x for x in n[1:] if x != i]
    elif n[0] == 'Enemy':
        ems[n[1]] = [n[2]]
        ems[n[2]] = [n[1]]
        if n[2] in allys:
            for t in allys[n[2]]:
                if t not in ems:
                    ems[t] = []
                ems[t].append(n[1])
                ems[n[1]].append(t)
                for e in allys[n[1]]:
                    ems[t].append(e)
                    if e not in ems:
                        ems[e] = []
                    ems[e].append(t)
        else:
            allys[n[2]] = []
        if n[1] in allys:
            for x in allys[n[1]]:
                if x not in ems:
                    ems[x] = []
                ems[x].append(n[2])
                ems[n[2]].append(x)
        else:
            allys[n[1]] = []
    elif n[0] == 'Table':
        cansit = True
        ts = n[1:] + [n[1]]
        for i in range(len(ts)-1):
            if ts[i] in ems and ts[i+1] in ems:
                if ts[i+1] in ems[ts[i]] or ts[i] in ems[ts[i+1]]:
                    cansit = False
                    break
        if cansit:
            print('Okay')
        else:
            print('No')


# Table America England Iceland France Iran Russia Iraq
#                                 |      |
# Table America England Russia America


# print(allys)
# print(ems)

# 1680753, 2022-11-12 11:07:57, ------ (0%)

allys = {}  # {country: [Allys...]}
ems = {}

while True:
    n = input().split()
    if n[0] == 'End':
        break
# allys = {'America': ['England', 'Ukraine', 'France'], 'England': ['America', 'Ukraine', 'France'],
#     'Ukraine': ['America', 'England', 'France'], 'France': ['America', 'England', 'Ukraine'],
#  'Russia': ['China']}
# ems = {'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif n[0] == 'Ally':
        for i in n[1:]:
            allys[i] = [x for x in n[1:] if x != i]
    elif n[0] == 'Enemy':
        ems[n[1]] = [n[2]]
        ems[n[2]] = [n[1]]
        if n[2] in allys:
            for t in allys[n[2]]:
                if t not in ems:
                    ems[t] = []
                ems[t].append(n[1])
                ems[n[1]].append(t)
                # for e in allys[n[1]]:
                #     ems[t].append(e)
                #     if e not in ems:
                #         ems[e] = []
                #     ems[e].append(t)
        if n[1] in allys:
            for x in allys[n[1]]:
                if x not in ems:
                    ems[x] = []
                ems[x].append(n[2])
                ems[n[2]].append(x)
    elif n[0] == 'Table':
        cansit = True
        ts = n[1:] + [n[1]]
        for i in range(len(ts)-1):
            if ts[i] in ems and ts[i+1] in ems:
                if ts[i+1] in ems[ts[i]] or ts[i] in ems[ts[i+1]]:
                    cansit = False
                    break
        if cansit:
            print('Okay')
        else:
            print('No')


# Table America England Iceland France Iran Russia Iraq
#                                 |      |
# Table America England Russia America


# print(allys)
print(ems)

# 1680761, 2022-11-12 11:08:14, PP-P-- (50%)

allys = {}  # {country: [Allys...]}
ems = {}

while True:
    n = input().split()
    if n[0] == 'End':
        break
# allys = {'America': ['England', 'Ukraine', 'France'], 'England': ['America', 'Ukraine', 'France'],
#     'Ukraine': ['America', 'England', 'France'], 'France': ['America', 'England', 'Ukraine'],
#  'Russia': ['China']}
# ems = {'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif n[0] == 'Ally':
        for i in n[1:]:
            allys[i] = [x for x in n[1:] if x != i]
    elif n[0] == 'Enemy':
        ems[n[1]] = [n[2]]
        ems[n[2]] = [n[1]]
        if n[2] in allys:
            for t in allys[n[2]]:
                if t not in ems:
                    ems[t] = []
                ems[t].append(n[1])
                ems[n[1]].append(t)
                # for e in allys[n[1]]:
                #     ems[t].append(e)
                #     if e not in ems:
                #         ems[e] = []
                #     ems[e].append(t)
        if n[1] in allys:
            for x in allys[n[1]]:
                if x not in ems:
                    ems[x] = []
                ems[x].append(n[2])
                ems[n[2]].append(x)
    elif n[0] == 'Table':
        cansit = True
        ts = n[1:] + [n[1]]
        for i in range(len(ts)-1):
            if ts[i] in ems and ts[i+1] in ems:
                if ts[i+1] in ems[ts[i]] or ts[i] in ems[ts[i+1]]:
                    cansit = False
                    break
        if cansit:
            print('Okay')
        else:
            print('No')


# Table America England Iceland France Iran Russia Iraq
#                                 |      |
# Table America England Russia America


# print(allys)
# print(ems)
# 1680771, 2022-11-12 11:08:43, PP-PPx (67%)

allys = {}  # {country: [Allys...]}
ems = {}

while True:
    n = input().split()
    if n[0] == 'End':
        break
# allys = {'America': ['England', 'Ukraine', 'France'], 'England': ['America', 'Ukraine', 'France'],
#     'Ukraine': ['America', 'England', 'France'], 'France': ['America', 'England', 'Ukraine'],
#  'Russia': ['China']}
# ems = {'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif n[0] == 'Ally':
        for i in n[1:]:
            allys[i] = [x for x in n[1:] if x != i]
    elif n[0] == 'Enemy':
        ems[n[1]] = [n[2]]
        ems[n[2]] = [n[1]]
        if n[2] in allys:
            for t in allys[n[2]]:
                if t not in ems:
                    ems[t] = []
                ems[t].append(n[1])
                ems[n[1]].append(t)
                for e in allys[n[1]]:
                    ems[t].append(e)
                    if e not in ems:
                        ems[e] = []
                    ems[e].append(t)
        if n[1] in allys:
            for x in allys[n[1]]:
                if x not in ems:
                    ems[x] = []
                ems[x].append(n[2])
                ems[n[2]].append(x)
    elif n[0] == 'Table':
        cansit = True
        ts = n[1:] + [n[1]]
        for i in range(len(ts)-1):
            if ts[i] in ems and ts[i+1] in ems:
                if ts[i+1] in ems[ts[i]] or ts[i] in ems[ts[i+1]]:
                    cansit = False
                    break
        if cansit:
            print('Okay')
        else:
            print('No')


# Table America England Iceland France Iran Russia Iraq
#                                 |      |
# Table America England Russia America


# print(allys)
# print(ems)

# 1680927, 2022-11-12 11:14:27, PP-PPx (67%)

allys = {}  # {country: [Allys...]}
ems = {}

while True:
    n = input().split()
    if n[0] == 'End':
        break
# allys = {'America': ['England', 'Ukraine', 'France'], 'England': ['America', 'Ukraine', 'France'],
#     'Ukraine': ['America', 'England', 'France'], 'France': ['America', 'England', 'Ukraine'],
#  'Russia': ['China']}
# ems = {'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif n[0] == 'Ally':
        for i in n[1:]:
            allys[i] = [x for x in n[1:] if x != i]
    elif n[0] == 'Enemy':
        ems[n[1]] = [n[2]]
        ems[n[2]] = [n[1]]
        if n[2] in allys:
            for t in allys[n[2]]:
                if t not in ems:
                    ems[t] = []
                ems[t].append(n[1])
                ems[n[1]].append(t)
                for e in allys[n[1]]:
                    ems[t].append(e)
                    if e not in ems:
                        ems[e] = []
                    ems[e].append(t)
        if n[1] in allys:
            for x in allys[n[1]]:
                if x not in ems:
                    ems[x] = []
                for t in ems[n[1]]:
                    ems[x].append(t)
                # ems[x].append(n[2])
                # ems[n[2]].append(x)
    elif n[0] == 'Table':
        cansit = True
        ts = n[1:] + [n[1]]
        for i in range(len(ts)-1):
            if ts[i] in ems and ts[i+1] in ems:
                if ts[i+1] in ems[ts[i]] or ts[i] in ems[ts[i+1]]:
                    cansit = False
                    break
        if cansit:
            print('Okay')
        else:
            print('No')


# Table America England Iceland France Iran Russia Iraq
#                                 |      |
# Table America England Russia America


# print(allys)
# print(ems)

# 1681585, 2022-11-12 11:29:19, PP-PPx (67%)

allys = {}  # {country: [Allys...]}
ems = {}

while True:
    n = input().split()
    if n[0] == 'End':
        break
# allys = {'America': ['England', 'Ukraine', 'France'], 'England': ['America', 'Ukraine', 'France'],
#     'Ukraine': ['America', 'England', 'France'], 'France': ['America', 'England', 'Ukraine'],
#  'Russia': ['China']}
# ems = {'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif n[0] == 'Ally':
        for i in n[1:]:
            allys[i] = [x for x in n[1:] if x != i]
    elif n[0] == 'Enemy':
        ems[n[1]] = [n[2]]
        ems[n[2]] = [n[1]]
        if n[2] in allys:
            for t in allys[n[2]]:
                if t not in ems:
                    ems[t] = []
                ems[t].append(n[1])
                ems[n[1]].append(t)
                for e in allys[n[1]]:
                    ems[t].append(e)
                    if e not in ems:
                        ems[e] = []
                    ems[e].append(t)
        if n[1] in allys:
            for x in allys[n[1]]:
                if x not in ems:
                    ems[x] = []
                for t in ems[n[1]]:
                    ems[x].append(t)
                ems[x].append(n[2])
                ems[n[2]].append(x)
    elif n[0] == 'Table':
        cansit = True
        ts = n[1:] + [n[1]]
        for i in range(len(ts)-1):
            if ts[i] in ems and ts[i+1] in ems:
                if ts[i+1] in ems[ts[i]] or ts[i] in ems[ts[i+1]]:
                    cansit = False
                    break
        if cansit:
            print('Okay')
        else:
            print('No')


# Table America England Iceland France Iran Russia Iraq
#                                 |      |
# Table America England Russia America


# print(allys)
# print(ems)
# 1681669, 2022-11-12 11:30:09, PP-PPx (67%)

allys = {}  # {country: [Allys...]}
ems = {}

while True:
    n = input().split()
    if n[0] == 'End':
        break
# allys = {'America': ['England', 'Ukraine', 'France'], 'England': ['America', 'Ukraine', 'France'],
#     'Ukraine': ['America', 'England', 'France'], 'France': ['America', 'England', 'Ukraine'],
#  'Russia': ['China']}
# ems = {'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif n[0] == 'Ally':
        for i in n[1:]:
            allys[i] = [x for x in n[1:] if x != i]
    elif n[0] == 'Enemy':
        ems[n[1]] = [n[2]]
        ems[n[2]] = [n[1]]
        if n[2] in allys:
            for t in allys[n[2]]:
                if t not in ems:
                    ems[t] = []
                ems[t].append(n[1])
                ems[n[1]].append(t)
                for e in allys[n[1]]:
                    ems[t].append(e)
                    if e not in ems:
                        ems[e] = []
                    ems[e].append(t)
        if n[1] in allys:
            for x in allys[n[1]]:
                if x not in ems:
                    ems[x] = []
                ems[x].append(n[2])
                ems[n[2]].append(x)
    elif n[0] == 'Table':
        cansit = True
        ts = n[1:] + [n[1]]
        for i in range(len(ts)-1):
            if ts[i] in ems and ts[i+1] in ems:
                if ts[i+1] in ems[ts[i]] or ts[i] in ems[ts[i+1]]:
                    cansit = False
                    break
        if cansit:
            print('Okay')
        else:
            print('No')


# Table America England Iceland France Iran Russia Iraq
#                                 |      |
# Table America England Russia America


# print(allys)
# print(ems)

6531321221
# 1680369, 2022-11-12 10:53:50, x----x (0%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            for t2 in a[1:]:
                if t1 not in ally and t1!=t2:
                    ally[t1] = {t2}
                elif t1 in ally and t1!=t2:
                    ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = a[1]
        e2 = a[2]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
        if l:
            print('Okay')
    a=input().split()
# 1680435, 2022-11-12 10:55:48, xPPPPx (67%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            for t2 in a[1:]:
                if t1 not in ally and t1!=t2:
                    ally[t1] = {t2}
                elif t1 in ally and t1!=t2:
                    ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = a[1]
        e2 = a[2]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()
# 1680608, 2022-11-12 11:03:16, xPPPPx (67%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            for t2 in a[1:]:
                if t1 not in ally and t1!=t2:
                    ally[t1] = {t2}
                elif t1 in ally and t1!=t2:
                    ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
      if len(a) == 3:
        e1 = a[1]
        e2 = a[2]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()
# 1680764, 2022-11-12 11:08:22, xPPPPx (67%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            if t1 not in ally:
                ally[t1] = set()
        for t1 in a[1:]:
            for t2 in a[1:]:
                ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = a[1]
        e2 = a[2]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()
# 1680908, 2022-11-12 11:13:41, xxxxxx (0%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            if t1 not in ally:
                ally[t1] = set()
        for t1 in a[1:]:
            for t2 in a[1:]:
                ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = a[1:2]
        e2 = a[2:3]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()
# 1680914, 2022-11-12 11:13:52, xPPPPx (67%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            if t1 not in ally:
                ally[t1] = set()
        for t1 in a[1:]:
            for t2 in a[1:]:
                ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = a[1]
        e2 = a[2]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()
# 1680969, 2022-11-12 11:15:49, xPPPPx (67%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            if t1 not in ally:
                ally[t1] = set()
        for t1 in a[1:]:
            for t2 in a[1:]:
                ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = a[1:2][0]
        e2 = a[2:3][0]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()
# 1681014, 2022-11-12 11:16:46, x-PPPx (50%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            if t1 not in ally:
                ally[t1] = set()
        for t1 in a[1:]:
            for t2 in a[1:]:
                ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = a[1:2][0]
        e2 = a[2:3][0]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] 
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()
# 1681032, 2022-11-12 11:17:04, xPPPPx (67%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            if t1 not in ally:
                ally[t1] = set()
        for t1 in a[1:]:
            for t2 in a[1:]:
                ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = a[1:2][0]
        e2 = a[2:3][0]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()
# 1681182, 2022-11-12 11:20:59, xxxxxx (0%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            if t1 not in ally:
                ally[t1] = set()
        for t1 in a[1:]:
            for t2 in a[1:]:
                ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = []
        e2 = []
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()
# 1681202, 2022-11-12 11:21:19, xPPPPx (67%)

a = input().split()
ally= {}
enemy = {}
while a[0] != 'End':
    if a[0] == 'Ally':
        for t1 in a[1:]:
            if t1 not in ally:
                ally[t1] = set()
        for t1 in a[1:]:
            for t2 in a[1:]:
                ally[t1].add(t2)
        # print(ally)
    if a[0] == 'Enemy':
        e1 = a[1]
        e2 = a[2]
        if e1 not in ally:
            ally[e1] = set()
        if e2 not in ally:
            ally[e2] = set()
        if e1 not in enemy:
            enemy[e1] = {e2}
        else:
            enemy[e1].add(e2)
        if e2 not in enemy:
            enemy[e2] = {e1}
        else:
            enemy[e2].add(e1)
        for al in ally[e1]:
            if al not in enemy:
                enemy[al] = {e2}
            else:
                enemy[al].add(e2)
            for e in ally[e2]:
                enemy[e1].add(e)
                enemy[al].add(e)
        for al in ally[e2]:
            if al not in enemy:
                enemy[al] = {e1}
            else:
                enemy[al].add(e1)
            for e in ally[e1]:
                enemy[e2].add(e)
                enemy[al].add(e)
        if len(ally[e1]) == 0:
            for al in ally[e2]:
                enemy[e1].add(al)
        if len(ally[e2]) == 0:
            for al in ally[e1]:
                enemy[e2].add(al)
        # print(enemy)
    if a[0] == 'Table':
        table = a[1:] + [a[1]]
        for c in table:
            if c not in ally:
                enemy[c] = set()
        l = 1
        for i in range(len(table)-1):
            if table[i+1] not in enemy[table[i]]:
                pass
            elif table[i+1] in enemy[table[i]]:
                print('No')
                l = 0
                break
        if l:
            print('Okay')
    a=input().split()

6530118021
# 1680198, 2022-11-12 10:46:10, xPPPPx (67%)

n = input().split()
good = {}
bad = {}
while n[0] != 'Table':
    if n[0] == 'Ally':
        al = n[1:]
        for e in al:
            good[e] = set(al)
    else:
        en = n[1:]
        for e in en:
            if e not in bad:
                bad[e] = set(en)
                bad[e].remove(e)
            else:
                for b in set(en):
                    bad[e].add(b)
                bad[e].remove(e)
            ph = set()
            for a in bad[e]:
                if a not in bad:
                    bad[a] = set()   
                bad[a].add(e)
                if a in good:
                    ph |= good[a]
            bad[e] |= ph
            for a in ph:
                if a not in bad:
                    bad[a] = set()
                if e in good:
                    for j in good[e]:
                        bad[a].add(j)
                else:
                    bad[a].add(e)
    n = input().split()
out = []
while n != ['End']:
    table = n[1:]+[n[1]]
    c = True
    for i in range(len(table)-1):
        if (table[i] not in good and table[i] not in bad)\
           or(table[i+1] not in good and table[i+1] not in bad):
            pass
        elif table[i+1] in bad[table[i]]:
            out.append('No')
            c = False
            break
    if c:
        out.append('Okay')
    n = input().split()
for e in out:
    print(e)
# 1680223, 2022-11-12 10:47:29, xxxxxx (0%)

n = input().split()
good = {}
bad = {}
while n[0] != 'Table':
    if n[0] == 'Ally':
        al = n[1:]
        for e in al:
            good[e] = set(al)
    else:
        en = n[1:]
        for e in en:
            if e not in bad:
                bad[e] = set(en)
                bad[e].remove(e)
            else:
                for b in set(en):
                    bad[e].add(b)
                bad[e].remove(e)
            ph = set()
            for a in bad[e]:
                if a not in bad:
                    bad[a] = set()   
                bad[a].add(e)
                if a in good:
                    ph |= good[a]
            bad[e] |= ph
            for a in ph:
                if a not in bad:
                    bad[a] = set()
                if e in good:
                    for j in good[e]:
                        bad[a].add(j)
                else:
                    bad[a].add(e)
    n = input().split()
out = []
while n != ['End']:
    table = n[1:]+[n[1]]
    c = True
    for i in range(len(table)-1):
        if (table[i] not in good and table[i] not in bad)\
           and(table[i+1] not in good and table[i+1] not in bad):
            pass
        elif table[i+1] in bad[table[i]]:
            out.append('No')
            c = False
            break
    if c:
        out.append('Okay')
    n = input().split()
for e in out:
    print(e)
# 1680228, 2022-11-12 10:47:48, xPPPPx (67%)

n = input().split()
good = {}
bad = {}
while n[0] != 'Table':
    if n[0] == 'Ally':
        al = n[1:]
        for e in al:
            good[e] = set(al)
    else:
        en = n[1:]
        for e in en:
            if e not in bad:
                bad[e] = set(en)
                bad[e].remove(e)
            else:
                for b in set(en):
                    bad[e].add(b)
                bad[e].remove(e)
            ph = set()
            for a in bad[e]:
                if a not in bad:
                    bad[a] = set()   
                bad[a].add(e)
                if a in good:
                    ph |= good[a]
            bad[e] |= ph
            for a in ph:
                if a not in bad:
                    bad[a] = set()
                if e in good:
                    for j in good[e]:
                        bad[a].add(j)
                else:
                    bad[a].add(e)
    n = input().split()
out = []
while n != ['End']:
    table = n[1:]+[n[1]]
    c = True
    for i in range(len(table)-1):
        if (table[i] not in good and table[i] not in bad)\
           or(table[i+1] not in good and table[i+1] not in bad):
            pass
        elif table[i+1] in bad[table[i]]:
            out.append('No')
            c = False
            break
    if c:
        out.append('Okay')
    n = input().split()
for e in out:
    print(e)
# 1680449, 2022-11-12 10:56:38, xPPPPx (67%)

n = input().split()
good = {}
bad = {}
All = set()
while n[0] != 'Table':
    if n[0] == 'Ally':
        al = n[1:]
        for e in al:
            good[e] = set(al)
    else:
        en = n[1:]
        for e in en:
            if e not in bad:
                bad[e] = set(en)
                bad[e].remove(e)
            else:
                for b in set(en):
                    bad[e].add(b)
                bad[e].remove(e)
            ph = set()
            for a in bad[e]:
                if a not in bad:
                    bad[a] = set()   
                bad[a].add(e)
                if a in good:
                    ph |= good[a]
            bad[e] |= ph
            for a in ph:
                if a not in bad:
                    bad[a] = set()
                if e in good:
                    for j in good[e]:
                        bad[a].add(j)
                else:
                    bad[a].add(e)
    n = input().split()
for e in list(good.values()):
    All |= e
for e in list(bad.values()):
    All |= e
out = []
while n != ['End']:
    table = n[1:]+[n[1]]
    c = True
    for i in range(len(table)-1):
        if table[i] not in All or table[i+1] not in All:
            pass
        elif table[i+1] in bad[table[i]]:
            out.append('No')
            c = False
            break
    if c:
        out.append('Okay')
    n = input().split()
for e in out:
    print(e)
# 1680858, 2022-11-12 11:11:49, xxxxxx (0%)

n = input().split()
good = {}
bad = {}
All = set()
while n[0] != 'Table':
    if n[0] == 'Ally':
        al = n[1:]
        for e in al:
            good[e] = set(al)
    else:
        e1,e2 = n[1],n[2]
        if e[1] not in bad:
            bad[e1] = set()
        bad[e1].add(e2)
        if e2 in good:
            for k in good[e2]:
                bad[e1].add(k)
                if k not in bad:
                    bad[k] = set()
                bad[k].add(e1)
        if e[2] not in bad:
            bad[e2] = set()
        bad[e2].add(e1)
        if e1 in good:
            for k in good[e1]:
                bad[e2].add(k)
                if k not in bad:
                    bad[k] = set()
                bad[k].add(e2)
    n = input().split()
for e in list(good.values()):
    All |= e
for e in list(bad.values()):
    All |= e
out = []
while n != ['End']:
    table = n[1:]+[n[1]]
    c = True
    for i in range(len(table)-1):
        if table[i] not in All or table[i+1] not in All:
            pass
        elif table[i+1] in bad[table[i]]:
            out.append('No')
            c = False
            break
    if c:
        out.append('Okay')
    n = input().split()
for e in out:
    print(e)
# 1680883, 2022-11-12 11:12:36, xPPPPx (67%)

n = input().split()
good = {}
bad = {}
All = set()
while n[0] != 'Table':
    if n[0] == 'Ally':
        al = n[1:]
        for e in al:
            good[e] = set(al)
    else:
        en = n[1:]
        for e in en:
            if e not in bad:
                bad[e] = set(en)
                bad[e].remove(e)
            else:
                for b in set(en):
                    bad[e].add(b)
                bad[e].remove(e)
            ph = set()
            for a in bad[e]:
                if a not in bad:
                    bad[a] = set()   
                bad[a].add(e)
                if a in good:
                    ph |= good[a]
            bad[e] |= ph
            for a in ph:
                if a not in bad:
                    bad[a] = set()
                if e in good:
                    for j in good[e]:
                        bad[a].add(j)
                else:
                    bad[a].add(e)
    n = input().split()
for e in list(good.values()):
    All |= e
for e in list(bad.values()):
    All |= e
out = []
while n != ['End']:
    table = n[1:]+[n[1]]
    c = True
    for i in range(len(table)-1):
        if table[i] not in All or table[i+1] not in All:
            pass
        elif table[i+1] in bad[table[i]]:
            out.append('No')
            c = False
            break
    if c:
        out.append('Okay')
    n = input().split()
for e in out:
    print(e)

# 1681308, 2022-11-12 11:24:02, xPPPPx (67%)

n = input().split()
good = {}
bad = {}
All = set()
while n[0] != 'Table':
    if n[0] == 'Ally':
        al = n[1:]
        for e in al:
            good[e] = set(al)
    else:
        en = n[1:]
        for e in en:
            if e not in bad:
                bad[e] = set(en)
                bad[e].remove(e)
            else:
                for b in set(en):
                    bad[e].add(b)
                bad[e].remove(e)
            ph = set()
            for a in bad[e]:
                if a not in bad:
                    bad[a] = set()   
                bad[a].add(e)
                if a in good:
                    ph |= good[a]
            bad[e] |= ph
            for a in ph:
                if a not in bad:
                    bad[a] = set()
                if e in good:
                    for j in good[e]:
                        bad[a].add(j)
                else:
                    bad[a].add(e)
    n = input().split()
for e in list(good.values()):
    All |= e
for e in list(bad.values()):
    All |= e
out = []
while n != ['End']:
    p = True
    if len(n) == 1: #nnnnn
      out.append('OK')
      p = False
    if p:
        table = n[1:]+[n[1]]
        c = True
        for i in range(len(table)-1):
            if table[i] not in All or table[i+1] not in All:
                pass
            elif table[i+1] in bad[table[i]]:
                out.append('No')
                c = False
                break
        if c:
            out.append('Okay')
    n = input().split()
for e in out:
    print(e)
# 1681337, 2022-11-12 11:24:42, xPPPPx (67%)

n = input().split()
good = {}
bad = {}
All = set()
while n[0] != 'Table':
    if n[0] == 'Ally':
        al = n[1:]
        for e in al:
            good[e] = set(al)
    else:
        en = n[1:]
        for e in en:
            if e not in bad:
                bad[e] = set(en)
                bad[e].remove(e)
            else:
                for b in set(en):
                    bad[e].add(b)
                bad[e].remove(e)
            ph = set()
            for a in bad[e]:
                if a not in bad:
                    bad[a] = set()   
                bad[a].add(e)
                if a in good:
                    ph |= good[a]
            bad[e] |= ph
            for a in ph:
                if a not in bad:
                    bad[a] = set()
                if e in good:
                    for j in good[e]:
                        bad[a].add(j)
                else:
                    bad[a].add(e)
    n = input().split()
for e in list(good.values()):
    All |= e
for e in list(bad.values()):
    All |= e
out = []
while n != ['End']:
    table = n[1:]+[n[1]]
    c = True
    for i in range(len(table)-1):
        if table[i] not in All or table[i+1] not in All:
            pass
        elif table[i+1] in bad[table[i]]:
            out.append('No')
            c = False
            break
    if c:
        out.append('Okay')
    n = input().split()
for e in out:
    print(e)
# 1681710, 2022-11-12 11:30:50, compilation error (0%)

n = input().split()
good = {}
bad = {}
All = set()
while n[0] != 'Table':
    if n[0] == 'Ally':
        al = n[1:]
        for e in al:
            if e in good:
                for f in al:
                    good[e].add(f)
            else:
            good[e] = set(al)
    else:
        en = n[1:]
        for e in en:
            if e not in bad:
                bad[e] = set(en)
                bad[e].remove(e)
            else:
                for b in set(en):
                    bad[e].add(b)
                bad[e].remove(e)
            ph = set()
            for a in bad[e]:
                if a not in bad:
                    bad[a] = set()   
                bad[a].add(e)
                if a in good:
                    ph |= good[a]
            bad[e] |= ph
            for a in ph:
                if a not in bad:
                    bad[a] = set()
                if e in good:
                    for j in good[e]:
                        bad[a].add(j)
                else:
                    bad[a].add(e)
    n = input().split()
for e in list(good.values()):
    All |= e
for e in list(bad.values()):
    All |= e
out = []
while n != ['End']:
    table = n[1:]+[n[1]]
    c = True
    for i in range(len(table)-1):
        if table[i] not in All or table[i+1] not in All:
            pass
        elif table[i+1] in bad[table[i]]:
            out.append('No')
            c = False
            break
    if c:
        out.append('Okay')
    n = input().split()
for e in out:
    print(e)

6530151721
# 1679763, 2022-11-12 10:26:33, PxPx-- (33%)

team=[]
al={}
while True:
    a=input().split()
    if a[0]=='End':
        break
    elif a[0]=='Ally':
        team.append(a[1:])
    elif a[0]=='Enemy':
        enemy1=[e for e in team if a[1] not in e][0]
        enemy2=[e for e in team if a[2] not in e][0]
        for i in enemy1:
            if a[1] not in al: al[a[1]]=[]
            al[a[1]].append(i)
            
        for i in enemy2:
            if a[2] not in al: al[a[2]]=[]
            al[a[2]].append(i)
        if a[1] not in al[a[2]]:
            al[a[2]].append(a[1])
        if a[2] not in al[a[1]]:
            al[a[1]].append(a[2])
    elif a[0]=='Table':
        d=0
        x=a[1:]
        x.append(x[0])
        x.insert(0,x[-2])
        for i in range(1,len(x)-1):
            if x[i] in al:    
                if x[i-1] in al[x[i]] or x[i+1] in al[x[i]]:
                    print('No')
                    d=1
                    break
        if d ==0:print('Okay')


# 1680238, 2022-11-12 10:48:28, PP-x-- (33%)

team=[]
al={}
while True:
    a=input().split()
    if a[0]=='End':
        break
    elif a[0]=='Ally':
        team.append(a[1:])
    elif a[0]=='Enemy':
        b=0
        enemy1=[]
        enemy2=[]
        c=0
        for i in team:
            if a[1]in i:
                b+=1
        for i in team:
            if a[2]in i:
                c+=1
        if b>0:enemy1=[e for e in team if a[1] not in e][0]
        if c>0:enemy2=[e for e in team if a[2] not in e][0]
        for i in enemy1:
            if a[1] not in al: al[a[1]]=[]
            al[a[1]].append(i)
            
        for i in enemy2:
            if a[2] not in al: al[a[2]]=[]
            al[a[2]].append(i)
        if a[2] not in al:
            al[a[2]]=[]
        if a[1] not in al:
            al[a[1]]=[]
        if a[1] not in al[a[2]]:
            al[a[2]].append(a[1])
        if a[2] not in al[a[1]]:
            al[a[1]].append(a[2])
    elif a[0]=='Table':
        d=0
        x=a[1:]
        x.append(x[0])
        x.insert(0,x[-2])
        for i in range(1,len(x)-1):
            if x[i] in al:    
                if x[i-1] in al[x[i]] or x[i+1] in al[x[i]]:
                    print('No')
                    d=1
                    break
        if d ==0:print('Okay')


# 1680395, 2022-11-12 10:54:37, PPPx-- (50%)

team=[]
al={}
while True:
    a=input().split()
    if a[0]=='End':
        break
    elif a[0]=='Ally':
        team.append(a[1:])
    elif a[0]=='Enemy':
        b=0
        enemy1=[]
        enemy2=[]
        c=0
        for i in team:
            if a[1]in i:
                b+=1
        for i in team:
            if a[2]in i:
                c+=1
        if b>0:enemy1=[e for e in team if a[1] not in e][0]
        if c>0:enemy2=[e for e in team if a[2] not in e][0]
        for i in enemy1:
            if a[1] not in al: al[a[1]]=[]
            al[a[1]].append(i)
            
        for i in enemy2:
            if a[2] not in al: al[a[2]]=[]
            al[a[2]].append(i)
        if a[2] not in al:
            al[a[2]]=[]
        if a[1] not in al:
            al[a[1]]=[]
        if a[1] not in al[a[2]]:
            al[a[2]].append(a[1])
        if a[2] not in al[a[1]]:
            al[a[1]].append(a[2])
        for i in team:
            for k in i:
                if a[1] in i:
                    if k not in al: al[k] =[]
                    al[k].append(a[2])
                if a[2] in i:
                    if k not in al: al[k]=[]
                    al[k].append(a[1])
    elif a[0]=='Table':
        d=0
        x=a[1:]
        x.append(x[0])
        x.insert(0,x[-2])
        for i in range(1,len(x)-1):
            if x[i] in al:    
                if x[i-1] in al[x[i]] or x[i+1] in al[x[i]]:
                    print('No')
                    d=1
                    break
        if d ==0:print('Okay')


# 1680499, 2022-11-12 10:58:57, PPPx-- (50%)

team=[]
al={}
while True:
    a=input().split()
    if a[0]=='End':
        break
    elif a[0]=='Ally':
        team.append(a[1:])
    elif a[0]=='Enemy':
        b=0
        enemy1=[]
        enemy2=[]
        c=0
        for i in team:
            if a[1]in i:
                b+=1
        for i in team:
            if a[2]in i:
                c+=1
        if b>0:enemy1=[e for e in team if a[1] not in e][0]
        if c>0:enemy2=[e for e in team if a[2] not in e][0]
        for i in enemy1:
            if a[1] not in al: al[a[1]]=[]
            al[a[1]].append(i)
            
        for i in enemy2:
            if a[2] not in al: al[a[2]]=[]
            al[a[2]].append(i)
        if a[2] not in al:
            al[a[2]]=[]
        if a[1] not in al:
            al[a[1]]=[]
        if a[1] not in al[a[2]]:
            al[a[2]].append(a[1])
        if a[2] not in al[a[1]]:
            al[a[1]].append(a[2])
        for i in team:
            for k in i:
                if a[1] in i:
                    if k not in al: al[k] =[]
                    al[k].append(a[2])
                    al[k].append(enemy1)
                if a[2] in i:
                    if k not in al: al[k]=[]
                    al[k].append(a[1])
                    al[k].append(enemy2)
    elif a[0]=='Table':
        d=0
        x=a[1:]
        x.append(x[0])
        x.insert(0,x[-2])
        for i in range(1,len(x)-1):
            if x[i] in al:    
                if x[i-1] in al[x[i]] or x[i+1] in al[x[i]]:
                    print('No')
                    d=1
                    break
        if d ==0:print('Okay')


# 1680669, 2022-11-12 11:04:59, PPPx-P (67%)

team=[]
al={}
while True:
    a=input().split()
    if a[0]=='End':
        break
    elif a[0]=='Ally':
        team.append(a[1:])
    elif a[0]=='Enemy':
        b=0
        enemy1=[]
        enemy2=[]
        c=0
        for i in team:
            if a[1]in i:
                b+=1
        for i in team:
            if a[2]in i:
                c+=1
        if b>0:enemy1=[e for e in team if a[1] not in e][0]
        if c>0:enemy2=[e for e in team if a[2] not in e][0]
        for i in team:
            for k in i:
                if a[1] in i:
                    if k not in al: al[k] =[]
                    al[k].append(a[2])
                    if enemy1 not in al[k]: al[k].extend(enemy1)
                if a[2] in i:
                    if k not in al: al[k]=[]
                    al[k].append(a[1])
                    if enemy1 not in al[k]: al[k].extend(enemy2)
        if a[2] not in al:
            al[a[2]]=[]
        if a[1] not in al:
            al[a[1]]=[]
        if a[1] not in al[a[2]]:
            al[a[2]].append(a[1])
        if a[2] not in al[a[1]]:
            al[a[1]].append(a[2])
    elif a[0]=='Table':
        d=0
        x=a[1:]
        x.append(x[0])
        x.insert(0,x[-2])
        for i in range(1,len(x)-1):
            if x[i] in al:    
                if x[i-1] in al[x[i]] or x[i+1] in al[x[i]]:
                    print('No')
                    d=1
                    break
        if d ==0:print('Okay')



# 1680835, 2022-11-12 11:10:54, PPPx-P (67%)

team=[]
al={}
while True:
    a=input().split()
    if a[0]=='End':
        break
    elif a[0]=='Ally':
        team.append(a[1:])
    elif a[0]=='Enemy':
        b=0
        enemy1=[]
        enemy2=[]
        c=0
        for i in team:
            if a[1]in i:
                b+=1
        for i in team:
            if a[2]in i:
                c+=1
        if b>0:enemy1=[e for e in team if a[1] not in e][0]
        if c>0:enemy2=[e for e in team if a[2] not in e][0]
        for i in team:
            for k in i:
                if a[1] in i:
                    if k not in al: al[k] =[]
                    al[k].append(a[2])
                    for j in enemy1:
                        if j not in al[k]: al[k].append(j)
                if a[2] in i:
                    if k not in al: al[k]=[]
                    al[k].append(a[1])
                    for j in enemy2:
                        if j not in al[k]: al[k].append(j)
        if a[2] not in al:
            al[a[2]]=[]
        if a[1] not in al:
            al[a[1]]=[]
        if a[1] not in al[a[2]]:
            al[a[2]].append(a[1])
        if a[2] not in al[a[1]]:
            al[a[1]].append(a[2])
    elif a[0]=='Table':
        d=0
        x=a[1:]
        x.append(x[0])
        x.insert(0,x[-2])
        for i in range(1,len(x)-1):
            if x[i] in al:    
                if x[i-1] in al[x[i]] or x[i+1] in al[x[i]]:
                    print('No')
                    d=1
                    break
        if d ==0:print('Okay')




# 1681058, 2022-11-12 11:17:46, PPPx-P (67%)

team=[]
al={}
while True:
    a=input().split()
    if a[0]=='End':
        break
    elif a[0]=='Ally':
        team.append(a[1:])
    elif a[0]=='Enemy':
        b=0
        enemy1=[]
        enemy2=[]
        c=0
        for i in team:
            if a[1]in i:
                b+=1
        for i in team:
            if a[2]in i:
                c+=1
        if b>0:enemy1=[e for e in team if a[1] not in e][0]
        if c>0:enemy2=[e for e in team if a[2] not in e][0]
        for i in team:
            for k in i:
                
                if a[1] in i:
                    if a[2] not in al: al[a[2]]=[]
                    if i not in al[a[2]]: al[a[2]].append(k)
                    if k not in al: al[k] =[]
                    al[k].append(a[2])
                    for j in enemy1:
                        if j not in al[k]: al[k].append(j)
                if a[2] in i:
                    if a[1] not in al: al[a[1]]=[]
                    if i not in al[a[1]]: al[a[1]].append(k)                    
                    if k not in al: al[k]=[]
                    al[k].append(a[1])
                    for j in enemy2:
                        if j not in al[k]: al[k].append(j)
        if a[2] not in al:
            al[a[2]]=[]
        if a[1] not in al:
            al[a[1]]=[]
        if a[1] not in al[a[2]]:
            al[a[2]].append(a[1])
        if a[2] not in al[a[1]]:
            al[a[1]].append(a[2])
    elif a[0]=='Table':
        d=0
        x=a[1:]
        x.append(x[0])
        x.insert(0,x[-2])
        for i in range(1,len(x)-1):
            if x[i] in al:    
                if x[i-1] in al[x[i]] or x[i+1] in al[x[i]]:
                    print('No')
                    d=1
                    break
        if d ==0:print('Okay')




# 1681073, 2022-11-12 11:18:10, PPPx-P (67%)

team=[]
al={}
while True:
    a=input().split()
    if a[0]=='End':
        break
    elif a[0]=='Ally':
        team.append(a[1:])
    elif a[0]=='Enemy':
        b=0
        enemy1=[]
        enemy2=[]
        c=0
        for i in team:
            if a[1]in i:
                b+=1
        for i in team:
            if a[2]in i:
                c+=1
        if b>0:enemy1=[e for e in team if a[1] not in e][0]
        if c>0:enemy2=[e for e in team if a[2] not in e][0]
        for i in team:
            for k in i:
                
                if a[1] in i:
                    if a[2] not in al: al[a[2]]=[]
                    if i not in al[a[2]]: al[a[2]].append(k)
                    if k not in al: al[k] =[]
                    al[k].append(a[2])
                    for j in enemy1:
                        if j not in al[k]: al[k].append(j)
                if a[2] in i:
                    if a[1] not in al: al[a[1]]=[]
                    if i not in al[a[1]]: al[a[1]].append(k)                    
                    if k not in al: al[k]=[]
                    al[k].append(a[1])
                    for j in enemy2:
                        if j not in al[k]: al[k].append(j)
        if a[2] not in al:
            al[a[2]]=[]
        if a[1] not in al:
            al[a[1]]=[]
        if a[1] not in al[a[2]]:
            al[a[2]].append(a[1])
        if a[2] not in al[a[1]]:
            al[a[1]].append(a[2])
    elif a[0]=='Table':
        d=0
        x=a[1:]
        x.append(x[0])
        x.insert(0,x[-2])
        for i in range(1,len(x)-1):
            if x[i] in al:    
                if x[i-1] in al[x[i]] or x[i+1] in al[x[i]]:
                    print('No')
                    d=1
                    break
        if d ==0:print('Okay')




# 1681314, 2022-11-12 11:24:07, PPPx-P (67%)

team=[]
al={}
while True:
    a=input().split()
    if a[0]=='End':
        break
    elif a[0]=='Ally':
        team.append(a[1:])
    elif a[0]=='Enemy':
        b=0
        enemy1=[]
        enemy2=[]
        c=0
        for i in team:
            if a[1]in i:
                b+=1
        for i in team:
            if a[2]in i:
                c+=1
        if b>0:enemy1=[e for e in team if a[1] not in e][0]
        if c>0:enemy2=[e for e in team if a[2] not in e][0]
        if a[2] not in al:
            al[a[2]]=[]
        if a[1] not in al:
            al[a[1]]=[]        
        for i in team:
            for k in i:
                
                if a[1] in i:
                    if i not in al[a[2]]: al[a[2]].append(k)
                    if k not in al: al[k] =[]
                    if a[2] not in al[k]:al[k].append(a[2])
                    for j in enemy1:
                        if j not in al[k]: al[k].append(j)
                if a[2] in i:
                    if a[1] not in al: al[a[1]]=[]
                    if i not in al[a[1]]: al[a[1]].append(k)                    
                    if k not in al: al[k]=[]
                    if a[1] not in al[k]:al[k].append(a[1])
                    
                    for j in enemy2:
                        if j not in al[k]: al[k].append(j)

        if a[1] not in al[a[2]]:
            al[a[2]].append(a[1])
        if a[2] not in al[a[1]]:
            al[a[1]].append(a[2])
    elif a[0]=='Table':
        d=0
        x=a[1:]
        x.append(x[0])
        x.insert(0,x[-2])
        for i in range(1,len(x)-1):
            if x[i] in al:    
                if x[i-1] in al[x[i]] or x[i+1] in al[x[i]]:
                    print('No')
                    d=1
                    break
        if d ==0:print('Okay')





6230098921
# 1680266, 2022-11-12 10:49:58, P--PP- (50%)

ally = {}
enemy = []
table = []
group = []
check = {}
m = True
while m == True :
    k = input().strip().split()
    if k[0] == 'Ally' :
        for e in k[1:] :
            ally[e] = k[1:]
    elif k[0] == 'Enemy' :
        enemy.append(k[1:])
    elif k[0] == 'Table' :
        table.append(k[1:])
    elif k[0] == 'End' :
        m = False
for e in enemy :
    for i in range(len(e)) :
        if e[i] in ally :
            e[i] = ally[e[i]]
for e in enemy :
    for i in range(len(e[0])) :
        check[e[0][i]] = e[1]
    for i in range(len(e[1])) :
        check[e[1][i]] = e[0]
k = 0
for c in table :
    for i in range(len(c)-1) :
        if c[i] in check :
            if c[i+1] in check[c[i]] :
                print('No')
                k = 0
                break
        if c[i] not in check :
            k += 1
        elif c[i+1] not in check[c[i]] :
            k += 1
        if k == len(c) - 1 :
            print('Okay')
            k = 0
# 1680370, 2022-11-12 10:53:53, PxxPxx (33%)

ally = {}
enemy = []
table = []
group = []
check = {}
m = True
while m == True :
    k = input().strip().split()
    if k[0] == 'Ally' :
        for e in k[1:] :
            ally[e] = k[1:]
    elif k[0] == 'Enemy' :
        enemy.append(k[1:])
    elif k[0] == 'Table' :
        table.append(k[1:])
    elif k[0] == 'End' :
        m = False
for e in enemy :
    for i in range(len(e)) :
        if e[i] in ally :
            e[i] = ally[e[i]]
for e in enemy :
    for i in range(len(e[0])) :
        if e[0][i] not in check :
            check[e[0][i]] = e[1]
        else :
            check[e[0][i]].append(e[1])
    for i in range(len(e[1])) :
        if e[1][i] not in check :
            check[e[1][i]] = e[0]
        else :
            check[e[1][i]].append(e[0]) 
k = 0
for c in table :
    for i in range(len(c)-1) :
        if c[i] in check :
            if c[i+1] in check[c[i]] :
                print('No')
                k = 0
                break
        if c[i] not in check :
            k += 1
        elif c[i+1] not in check[c[i]] :
            k += 1
        if k == len(c) - 1 :
            print('Okay')
            k = 0
# 1680392, 2022-11-12 10:54:32, P--PP- (50%)

ally = {}
enemy = []
table = []
group = []
check = {}
m = True
while m == True :
    k = input().strip().split()
    if k[0] == 'Ally' :
        for e in k[1:] :
            ally[e] = k[1:]
    elif k[0] == 'Enemy' :
        enemy.append(k[1:])
    elif k[0] == 'Table' :
        table.append(k[1:])
    elif k[0] == 'End' :
        m = False
for e in enemy :
    for i in range(len(e)) :
        if e[i] in ally :
            e[i] = ally[e[i]]
for e in enemy :
    for i in range(len(e[0])) :
        check[e[0][i]] = e[1]
    for i in range(len(e[1])) :
        check[e[1][i]] = e[0]
k = 0
for c in table :
    for i in range(len(c)-1) :
        if c[i] in check :
            if c[i+1] in check[c[i]] :
                print('No')
                k = 0
                break
        if c[i] not in check :
            k += 1
        elif c[i+1] not in check[c[i]] :
            k += 1
        if k == len(c) - 1 :
            print('Okay')
            k = 0
# 1680704, 2022-11-12 11:06:36, P-PPP- (67%)

ally = {}
enemy = []
table = []
group = []
check = {}
m = True
while m == True :
    k = input().strip().split()
    if k[0] == 'Ally' :
        for e in k[1:] :
            ally[e] = k[1:]
    elif k[0] == 'Enemy' :
        enemy.append(k[1:])
    elif k[0] == 'Table' :
        table.append(k[1:])
    elif k[0] == 'End' :
        m = False
for e in enemy :
    for i in range(len(e)) :
        if e[i] in ally :
            e[i] = ally[e[i]]
for e in enemy :
    for i in range(len(e[0])) :
        if e[0][i] not in check :
            check[e[0][i]] = list(e[1])
        else :
            check[e[0][i]].append(e[1])
    for i in range(len(e[1])) :
        if e[1][i] not in check :
            check[e[1][i]] = list(e[0])
        else :
            check[e[1][i]].append(e[0]) 
k = 0
for c in table :
    for i in range(len(c)-1) :
        if c[i] in check :
            if c[i+1] in check[c[i]] :
                print('No')
                k = 0
                break
        if c[i] not in check :
            k += 1
        elif c[i+1] not in check[c[i]] :
            k += 1
        if k == len(c) - 1 :
            print('Okay')
            k = 0
# 1681082, 2022-11-12 11:18:27, P-PPP- (67%)

ally = {}
enemy = []
table = []
group = []
check = {}
m = True
while m == True :
    k = input().strip().split()
    if k[0] == 'Ally' :
        for e in k[1:] :
            ally[e] = k[1:]
    elif k[0] == 'Enemy' :
        enemy.append(k[1:])
    elif k[0] == 'Table' :
        table.append(k[1:]+[k[0]])
    elif k[0] == 'End' :
        m = False
for e in enemy :
    for i in range(len(e)) :
        if e[i] in ally :
            e[i] = ally[e[i]]
for e in enemy :
    for i in range(len(e[0])) :
        if e[0][i] not in check :
            check[e[0][i]] = list(e[1])
        else :
            check[e[0][i]].append(e[1])
    for i in range(len(e[1])) :
        if e[1][i] not in check :
            check[e[1][i]] = list(e[0])
        else :
            check[e[1][i]].append(e[0]) 
k = 0
for c in table :
    for i in range(len(c)-1) :
        if c[i] in check :
            if c[i+1] in check[c[i]] :
                print('No')
                k = 0
                break
        if c[i] not in check :
            k += 1
        elif c[i+1] not in check[c[i]] :
            k += 1
        if k == len(c) - 1 :
            print('Okay')
            k = 0
# 1681116, 2022-11-12 11:19:22, P-PPP- (67%)

ally = {}
enemy = []
table = []
group = []
check = {}
m = True
while m == True :
    k = input().strip().split()
    if k[0] == 'Ally' :
        for e in k[1:] :
            ally[e] = k[1:]
    elif k[0] == 'Enemy' :
        enemy.append(k[1:])
    elif k[0] == 'Table' :
        table.append(k[1:]+[k[1]])
    elif k[0] == 'End' :
        m = False
for e in enemy :
    for i in range(len(e)) :
        if e[i] in ally :
            e[i] = ally[e[i]]
for e in enemy :
    for i in range(len(e[0])) :
        if e[0][i] not in check :
            check[e[0][i]] = list(e[1])
        else :
            check[e[0][i]].append(e[1])
    for i in range(len(e[1])) :
        if e[1][i] not in check :
            check[e[1][i]] = list(e[0])
        else :
            check[e[1][i]].append(e[0]) 
k = 0
for c in table :
    for i in range(len(c)-1) :
        if c[i] in check :
            if c[i+1] in check[c[i]] :
                print('No')
                k = 0
                break
        if c[i] not in check :
            k += 1
        elif c[i+1] not in check[c[i]] :
            k += 1
        if k == len(c) - 1 :
            print('Okay')
            k = 0
# 1681174, 2022-11-12 11:20:47, P-PPP- (67%)

ally = {}
enemy = []
table = []
group = []
check = {}
m = True
while m == True :
    k = input().strip().split()
    if k[0] == 'Ally' :
        for e in k[1:] :
            ally[e] = k[1:]
    elif k[0] == 'Enemy' :
        enemy.append(k[1:])
    elif k[0] == 'Table' :
        table.append([k[-1]]+k[1:]+[k[1]])
    elif k[0] == 'End' :
        m = False
for e in enemy :
    for i in range(len(e)) :
        if e[i] in ally :
            e[i] = ally[e[i]]
for e in enemy :
    for i in range(len(e[0])) :
        if e[0][i] not in check :
            check[e[0][i]] = list(e[1])
        else :
            check[e[0][i]].append(e[1])
    for i in range(len(e[1])) :
        if e[1][i] not in check :
            check[e[1][i]] = list(e[0])
        else :
            check[e[1][i]].append(e[0]) 
k = 0
for c in table :
    for i in range(len(c)-1) :
        if c[i] in check :
            if c[i+1] in check[c[i]] :
                print('No')
                k = 0
                break
        if c[i] not in check :
            k += 1
        elif c[i+1] not in check[c[i]] :
            k += 1
        if k == len(c) - 1 :
            print('Okay')
            k = 0
# 1681335, 2022-11-12 11:24:41, P-PPP- (67%)

ally = {}
enemy = []
table = []
group = []
check = {}
m = True
while m == True :
    k = input().strip().split()
    if k[0] == 'Ally' :
        for e in k[1:] :
            ally[e] = k[1:]
    elif k[0] == 'Enemy' :
        enemy.append(k[1:])
    elif k[0] == 'Table' :
        table.append([k[-1]]+k[1:])
    elif k[0] == 'End' :
        m = False
for e in enemy :
    for i in range(len(e)) :
        if e[i] in ally :
            e[i] = ally[e[i]]
for e in enemy :
    for i in range(len(e[0])) :
        if e[0][i] not in check :
            check[e[0][i]] = list(e[1])
        else :
            check[e[0][i]].append(e[1])
    for i in range(len(e[1])) :
        if e[1][i] not in check :
            check[e[1][i]] = list(e[0])
        else :
            check[e[1][i]].append(e[0]) 
k = 0
for c in table :
    for i in range(len(c)-1) :
        if c[i] in check :
            if c[i+1] in check[c[i]] :
                print('No')
                k = 0
                break
        if c[i] not in check :
            k += 1
        elif c[i+1] not in check[c[i]] :
            k += 1
        if k == len(c) - 1 :
            print('Okay')
            k = 0

6531342421
# 1680394, 2022-11-12 10:54:37, --xxxx (0%)


k1=0
ally={}
enmy1={}
enmy2={}
while(True):
    
    x = input().split()
    if x[0] == 'End':
        break
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            ally[x[i]] = x[1:]
    if x[0] == 'Enemy':
        if x[1] in enmy1:
            enmy1[x[1]].append(ally[x[2]])
        if x[1] not in enmy1:
            if x[2] not in ally:
                enmy1[x[1]] = [x[2]]
            else:
                enmy1[x[1]] = ally[x[2]]


        if x[2] in enmy2:
            enmy2[x[2]].append(ally[x[1]])
        if x[2] not in enmy2:
            if x[1] not in ally:
                enmy2[x[2]] = [x[1]]
            else:
                enmy2[x[2]] = ally[x[1]]
    if x[0] == 'Table':
        ch=0
        t = x[1:] + x[1::99999]
        print(t)
        for i in range(1,len(t)):
            if t[i] in enmy1 :
                for j in enmy1[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
            if t[i] in enmy2 :
                for j in enmy2[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
        if ch==0:
            print('OK')
# 1680451, 2022-11-12 10:56:38, --xxxx (0%)


k1=0
ally={}
enmy1={}
enmy2={}
while(True):
    
    x = input().split()
    if x[0] == 'End':
        break
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            ally[x[i]] = x[1:]
    if x[0] == 'Enemy':
        if x[1] in enmy1:
            enmy1[x[1]].append(ally[x[2]])
        if x[1] not in enmy1:
            if x[2] not in ally:
                enmy1[x[1]] = [x[2]]
            else:
                enmy1[x[1]] = ally[x[2]]


        if x[2] in enmy2:
            enmy2[x[2]].append(ally[x[1]])
        if x[2] not in enmy2:
            if x[1] not in ally:
                enmy2[x[2]] = [x[1]]
            else:
                enmy2[x[2]] = ally[x[1]]
    if x[0] == 'Table':
        ch=0
        t = x[1:] + x[1::99999]
        for i in range(1,len(t)):
            if t[i] in enmy1 :
                for j in enmy1[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
            if t[i] in enmy2 :
                for j in enmy2[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
        if ch==0:
            print('OK')
# 1680465, 2022-11-12 10:57:26, PPxxxx (33%)


k1=0
ally={}
enmy1={}
enmy2={}
while(True):
    
    x = input().split()
    if x[0] == 'End':
        break
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            ally[x[i]] = x[1:]
    if x[0] == 'Enemy':
        if x[1] in enmy1:
            enmy1[x[1]].append(ally[x[2]])
        if x[1] not in enmy1:
            if x[2] not in ally:
                enmy1[x[1]] = [x[2]]
            else:
                enmy1[x[1]] = ally[x[2]]


        if x[2] in enmy2:
            enmy2[x[2]].append(ally[x[1]])
        if x[2] not in enmy2:
            if x[1] not in ally:
                enmy2[x[2]] = [x[1]]
            else:
                enmy2[x[2]] = ally[x[1]]
    if x[0] == 'Table':
        ch=0
        t = x[1:] + x[1::99999]
        for i in range(1,len(t)):
            if t[i] in enmy1 :
                for j in enmy1[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
            if t[i] in enmy2 :
                for j in enmy2[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
        if ch==0:
            print('Okay')
# 1680550, 2022-11-12 11:01:05, PPxxx- (33%)


k1=0
ally={}
enmy1={}
enmy2={}
while(True):
    
    x = input().split()
    if x[0] == 'End':
        break
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            ally[x[i]] = x[1:]
    if x[0] == 'Enemy':
        if x[1] in enmy1:
            if x[2] not in ally:
                enmy1[x[1]].append([x[2]])
            else:
                enmy1[x[1]].append(ally[x[2]])
        if x[1] not in enmy1:
            if x[2] not in ally:
                enmy1[x[1]] = [x[2]]
            else:
                enmy1[x[1]] = ally[x[2]]


        if x[2] in enmy2:
            if x[1] not in ally:
                enmy1[x[2]].append([x[1]])
            else:
                enmy1[x[2]].append(ally[x[1]])
        if x[2] not in enmy2:
            if x[1] not in ally:
                enmy2[x[2]] = [x[1]]
            else:
                enmy2[x[2]] = ally[x[1]]
    if x[0] == 'Table':
        ch=0
        t = x[1:] + x[1::99999]
        for i in range(1,len(t)):
            if t[i] in enmy1 :
                for j in enmy1[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
            if t[i] in enmy2 :
                for j in enmy2[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
        if ch==0:
            print('Okay')
# 1680568, 2022-11-12 11:02:01, PPPP-- (67%)


k1=0
ally={}
enmy1={}
enmy2={}
while(True):
    
    x = input().split()
    if x[0] == 'End':
        break
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            ally[x[i]] = x[1:]
    if x[0] == 'Enemy':
        if x[1] in enmy1:
            if x[2] not in ally:
                enmy1[x[1]].append([x[2]])
            else:
                enmy1[x[1]].append(ally[x[2]])
        if x[1] not in enmy1:
            if x[2] not in ally:
                enmy1[x[1]] = [x[2]]
            else:
                enmy1[x[1]] = ally[x[2]]


        if x[2] in enmy2:
            if x[1] not in ally:
                enmy2[x[2]].append([x[1]])
            else:
                enmy2[x[2]].append(ally[x[1]])
        if x[2] not in enmy2:
            if x[1] not in ally:
                enmy2[x[2]] = [x[1]]
            else:
                enmy2[x[2]] = ally[x[1]]
    if x[0] == 'Table':
        ch=0
        t = x[1:] + x[1::99999]
        for i in range(1,len(t)):
            if t[i] in enmy1 :
                for j in enmy1[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
            if t[i] in enmy2 :
                for j in enmy2[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
        if ch==0:
            print('Okay')
# 1680708, 2022-11-12 11:06:42, P----- (17%)


k1=0
ally={}
enmy1={}
enmy2={}
while(True):
    
    x = input().split()
    if x[0] == 'End':
        break
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            ally[x[i]] = x[1:]
    if x[0] == 'Enemy':
        if x[1] in enmy1:
            if x[2] not in ally:
                enmy1[x[1]].append([x[2]])
            else:
                enmy1[x[1]].append(ally[x[2]])
        if x[1] not in enmy1:
            if x[2] not in ally:
                enmy1[x[1]] = [x[2]]
            else:
                enmy1[x[1]] = ally[x[2]]


        if x[2] in enmy2:
            if x[1] not in ally:
                enmy2[x[2]].append([x[1]])
            else:
                enmy2[x[2]].append(ally[x[1]])
        if x[2] not in enmy2:
            if x[1] not in ally:
                enmy2[x[2]] = [x[1]]
            else:
                enmy2[x[2]] = ally[x[1]]
    if x[0] == 'Table':
        ch=0
        t = x[1:] + x[1::99999]
        for i in range(1,len(t)):
            if t[i] in enmy1 and t[i-1] in enmy1:
                for j in enmy1[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
            if t[i] in enmy2 and t[i-1] in enmy2:
                for j in enmy2[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
        if ch==0:
            print('Okay')
# 1680736, 2022-11-12 11:07:32, PPPP-- (67%)


k1=0
ally={}
enmy1={}
enmy2={}
while(True):
    
    x = input().split()
    if x[0] == 'End':
        break
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            ally[x[i]] = x[1:]
    if x[0] == 'Enemy':
        if x[1] in enmy1:
            if x[2] not in ally:
                enmy1[x[1]].append([x[2]])
            else:
                enmy1[x[1]].append(ally[x[2]])
        if x[1] not in enmy1:
            if x[2] not in ally:
                enmy1[x[1]] = [x[2]]
            else:
                enmy1[x[1]] = ally[x[2]]


        if x[2] in enmy2:
            if x[1] not in ally:
                enmy2[x[2]].append([x[1]])
            else:
                enmy2[x[2]].append(ally[x[1]])
        if x[2] not in enmy2:
            if x[1] not in ally:
                enmy2[x[2]] = [x[1]]
            else:
                enmy2[x[2]] = ally[x[1]]
    if x[0] == 'Table':
        ch=0
        t = x[1:] + x[1::99999]
        for i in range(1,len(t)):
            if t[i] in enmy1 :
                for j in enmy1[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
            if t[i] in enmy2 :
                for j in enmy2[t[i]]:
                    if t[i-1] == j:
                        print('No')
                        ch=1
                    if ch==1:
                        break
            if ch==1:
                break
        if ch==0:
            print('Okay')

6530015021
# 1679894, 2022-11-12 10:31:34, PPPP-- (67%)

out = []
allyEachCountry = {}
enemyEachCountry = {}
while True:
    x = input().strip()
    if x == 'End': break
    x = x.split()
    groupType = x[0]
    countries = x[1:]
    if groupType == 'Ally':
        for c in countries:
            if c not in allyEachCountry:
                allyEachCountry[c] = set()
            allyEachCountry[c] |= set(countries)
            allyEachCountry[c].remove(c)
    if groupType == 'Enemy':
        for c in countries:
            if c not in enemyEachCountry:
                enemyEachCountry[c] = set()
            enemyEachCountry[c] |= set(countries)
            enemyEachCountry[c].remove(c)
        for country,enemies in enemyEachCountry.items():
            addition = set()
            for enemy in enemies:
                if enemy in allyEachCountry:
                    addition |= allyEachCountry[enemy]
            enemyEachCountry[country] |= addition
    if groupType == 'Table':
        canhappen = True
        for i in range(len(countries)):
            if countries[i-1] in enemyEachCountry:
                if countries[i] in enemyEachCountry[countries[i-1]]:
                    canhappen = False
                    break
            if countries[i] in enemyEachCountry:
                if countries[i-1] in enemyEachCountry[countries[i]]:
                    canhappen = False
                    break 
        if canhappen :
            out.append('Okay')
        else:
            out.append('No')
'''print(allyEachCountry)
print()
print(enemyEachCountry)'''
print('\n'.join(out))

# 1679957, 2022-11-12 10:35:14, PPPP-- (67%)

out = []
allyEachCountry = {}
enemyEachCountry = {}
while True:
    x = input().strip()
    if x == 'End': break
    x = x.split()
    groupType = x[0]
    countries = x[1:]
    if groupType == 'Ally':
        for c in countries:
            if c not in allyEachCountry:
                allyEachCountry[c] = set()
            allyEachCountry[c] |= set(countries)
            allyEachCountry[c].remove(c)
    if groupType == 'Enemy':
        for c in countries:
            if c not in enemyEachCountry:
                enemyEachCountry[c] = set()
            enemyEachCountry[c] |= set(countries)
            enemyEachCountry[c].remove(c)
        for country,enemies in enemyEachCountry.items():
            addition = set()
            for enemy in enemies:
                if enemy in allyEachCountry:
                    addition |= allyEachCountry[enemy]
            enemyEachCountry[country] |= addition
    if groupType == 'Table':
        canhappen = True
        for i in range(len(countries)-1):
            if countries[i-1] in enemyEachCountry:
                if countries[i] in enemyEachCountry[countries[i-1]]:
                    canhappen = False
                    break
            if countries[i] in enemyEachCountry:
                if countries[i-1] in enemyEachCountry[countries[i]]:
                    canhappen = False
                    break
            if countries[i+1] in enemyEachCountry:
                if countries[i] in enemyEachCountry[countries[i+1]]:
                    canhappen = False
                    break
            if countries[i] in enemyEachCountry:
                if countries[i+1] in enemyEachCountry[countries[i]]:
                    canhappen = False
                    break   
        if canhappen :
            out.append('Okay')
        else:
            out.append('No')
'''print(allyEachCountry)
print()
print(enemyEachCountry)'''
print('\n'.join(out))

# 1680885, 2022-11-12 11:12:46, PPPP-- (67%)

out = []
allyEachCountry = {}
enemyEachCountry = {}
while True:
    x = input().strip()
    if x == 'End': break
    x = x.split()
    groupType = x[0]
    countries = x[1:]
    if groupType == 'Ally':
        for c in countries:
            if c not in allyEachCountry:
                allyEachCountry[c] = set()
            allyEachCountry[c] |= set(countries)
            allyEachCountry[c].remove(c)
    if groupType == 'Enemy':
        for c in countries:
            if c not in enemyEachCountry:
                enemyEachCountry[c] = set()
            enemyEachCountry[c] |= set(countries)
            enemyEachCountry[c].remove(c)
        for country,enemies in enemyEachCountry.items():
            addition = set()
            for enemy in enemies:
                if enemy in allyEachCountry:
                    addition |= allyEachCountry[enemy]
            enemyEachCountry[country] |= addition
    if groupType == 'Table':
        canhappen = True
        d = len(countries)
        for i in range(len(countries)):
            previous = countries[i-1]
            at = countries[i]
            after = countries[(i+1)%d]
            #print(previous,at,after)
            if previous in enemyEachCountry:
                if at in enemyEachCountry[previous]:
                    canhappen = False
                    #if not canhappen:print(1)
            if at in enemyEachCountry:
                if previous in enemyEachCountry[at]:
                    canhappen = False
                    #if not canhappen:print(2)
                if after in enemyEachCountry[at]:
                    canhappen = False
                    #if not canhappen:print(3)
            if after in enemyEachCountry:
                if at in enemyEachCountry[after]:
                    canhapen = False
                    #if not canhappen:print(4)
            if not canhappen:break
            #print(previous,at,after,canhappen)
        #print(countries,canhappen)   
        if canhappen :
            out.append('Okay')
        else:
            out.append('No')
            
            
'''print(allyEachCountry)
print()
print(enemyEachCountry)
print()'''
print('\n'.join(out))

# 1681647, 2022-11-12 11:29:56, ------ (0%)

out = []
allyEachCountry = {}
enemyEachCountry = {}
tables = []
while True:
    x = input().strip()
    if x == 'End': break
    x = x.split()
    groupType = x[0]
    countries = x[1:]
    if groupType == 'Ally':
        for c in countries:
            if c not in allyEachCountry:
                allyEachCountry[c] = set()
            allyEachCountry[c] |= set(countries)
            allyEachCountry[c].remove(c)
    
    if groupType == 'Enemy':
        for c in countries:
            if c not in enemyEachCountry:
                enemyEachCountry[c] = set()
            enemyEachCountry[c] |= set(countries)
            enemyEachCountry[c].remove(c)
        for country,enemies in enemyEachCountry.items():
            addition = set()
            for enemy in enemies:
                if enemy in allyEachCountry:
                    addition |= allyEachCountry[enemy]
            enemyEachCountry[country] |= addition
    
    if groupType == 'Table':
        
        tables.append(countries)
        
        '''canhappen = True
        d = len(countries)
        for i in range(len(countries)):
            previous = countries[i-1]
            at = countries[i]
            after = countries[(i+1)%d]
            #print(previous,at,after)
            if previous in enemyEachCountry:
                if at in enemyEachCountry[previous]:
                    canhappen = False
                    #if not canhappen:print(1)
            if at in enemyEachCountry:
                if previous in enemyEachCountry[at]:
                    canhappen = False
                    #if not canhappen:print(2)
                if after in enemyEachCountry[at]:
                    canhappen = False
                    #if not canhappen:print(3)
            if after in enemyEachCountry:
                if at in enemyEachCountry[after]:
                    canhapen = False
                    #if not canhappen:print(4)
            if not canhappen:break
            #print(previous,at,after,canhappen)
        #print(countries,canhappen)   
        if canhappen :
            out.append('Okay')
        else:
            out.append('No')'''
print(enemyEachCountry)            
d = {}
for ct in enemyEachCountry:
    for en in enemyEachCountry[ct]:
        if en not in enemyEachCountry:
            if en not in d:
                d[en] = set()
            d[en].add(ct)
for k,v in d.items():
    enemyEachCountry[k] = v

for t in tables:
    canhappen = True
    d = len(t)
    for i in range(len(t)):
        previous = t[i-1]
        at = t[i]
        after = t[(i+1)%d]
        #print(previous,at,after)
        if previous in enemyEachCountry:
            if at in enemyEachCountry[previous]:
                canhappen = False
                #if not canhappen:print(1)
        if at in enemyEachCountry:
            if previous in enemyEachCountry[at]:
                canhappen = False
                #if not canhappen:print(2)
            if after in enemyEachCountry[at]:
                canhappen = False
                #if not canhappen:print(3)
        if after in enemyEachCountry:
            if at in enemyEachCountry[after]:
                canhapen = False
                #if not canhappen:print(4)
        if not canhappen:break
            #print(previous,at,after,canhappen)
        #print(countries,canhappen)   
    if canhappen :
        out.append('Okay')
    else:
        out.append('No')

#print(allyEachCountry)
print()
print(enemyEachCountry)
print()
print('\n'.join(out))

# 1681699, 2022-11-12 11:30:36, ------ (0%)

#อันนี้ได้ 66
out = []
allyEachCountry = {}
enemyEachCountry = {}
while True:
    x = input().strip()
    if x == 'End': break
    x = x.split()
    groupType = x[0]
    countries = x[1:]
    if groupType == 'Ally':
        for c in countries:
            if c not in allyEachCountry:
                allyEachCountry[c] = set()
            allyEachCountry[c] |= set(countries)
            allyEachCountry[c].remove(c)
    if groupType == 'Enemy':
        for c in countries:
            if c not in enemyEachCountry:
                enemyEachCountry[c] = set()
            enemyEachCountry[c] |= set(countries)
            enemyEachCountry[c].remove(c)
        for country,enemies in enemyEachCountry.items():
            addition = set()
            for enemy in enemies:
                if enemy in allyEachCountry:
                    addition |= allyEachCountry[enemy]
            enemyEachCountry[country] |= addition
    if groupType == 'Table':
        canhappen = True
        for i in range(len(countries)):
            if countries[i-1] in enemyEachCountry:
                if countries[i] in enemyEachCountry[countries[i-1]]:
                    canhappen = False
                    break
            if countries[i] in enemyEachCountry:
                if countries[i-1] in enemyEachCountry[countries[i]]:
                    canhappen = False
                    break 
        if canhappen :
            out.append('Okay')
        else:
            out.append('No')
print(allyEachCountry)
print()
print(enemyEachCountry)
print()
print('\n'.join(out))


6530056821
# 1681414, 2022-11-12 11:26:10, compilation error (0%)

def mli(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        return [l.strip().split() for l in f]

n = input().split()
a = []
e = []
A = []
c = 0
d = 0
if n[0] == 'Ally':
    for i in range(1,len(n)):
        if len(a) == 0:
            a.append([n[i]])
            A.append(n[i])
        else:
            a[c].append(n[i])
            A.append(n[i])
    c += 1    
if n[0] == 'Enemy':
    for i in range(1,len(n)):
        if len(e) == 0:
            e.append([n[i]])
        else:
            e[d].append(n[i])
    d += 1    
while n!=['End']:
    n = input().split()
    if n!=['End']:
        if n[0] == 'Ally':
            for i in range(1,len(n)):
                if i == 1:
                    a.append([n[i]])
                    A.append(n[i])
                else:
                    a[c].append(n[i])
                    A.append(n[i])
            c += 1    
        if n[0] == 'Enemy':
            for i in range(1,len(n)):
                if i == 1:
                    e.append([n[i]])
                else:
                    e[d].append(n[i])
            d += 1    
        elif n[0] == 'Table':
            o = []
            for l in e:
                if l[0] in A:
                    for x in a:
                        if l[0] in x:
                            l[0] = x
                if l[1] in A:
                    for x in a:
                        if l[1] in x:
                            l[1] = x
            for i in range(1,len(n)):
     
                if i == 1:
                    o.append(n[i])
                else:
                    cc = 0
                    for j in e:
   
                        if n[i] in j[0] and n[i-1] in j[1]:
                            cc +=1
                        elif n[i] in j[1] and n[i-1] in j[0]:
                            cc +=1
                    if cc != 0:
                        print('No')
                        break
            if cc == 0:
            print('Okay')
            
                        






























# 1681429, 2022-11-12 11:26:21, P-PPP- (67%)

def mli(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        return [l.strip().split() for l in f]

n = input().split()
a = []
e = []
A = []
c = 0
d = 0
if n[0] == 'Ally':
    for i in range(1,len(n)):
        if len(a) == 0:
            a.append([n[i]])
            A.append(n[i])
        else:
            a[c].append(n[i])
            A.append(n[i])
    c += 1    
if n[0] == 'Enemy':
    for i in range(1,len(n)):
        if len(e) == 0:
            e.append([n[i]])
        else:
            e[d].append(n[i])
    d += 1    
while n!=['End']:
    n = input().split()
    if n!=['End']:
        if n[0] == 'Ally':
            for i in range(1,len(n)):
                if i == 1:
                    a.append([n[i]])
                    A.append(n[i])
                else:
                    a[c].append(n[i])
                    A.append(n[i])
            c += 1    
        if n[0] == 'Enemy':
            for i in range(1,len(n)):
                if i == 1:
                    e.append([n[i]])
                else:
                    e[d].append(n[i])
            d += 1    
        elif n[0] == 'Table':
            o = []
            for l in e:
                if l[0] in A:
                    for x in a:
                        if l[0] in x:
                            l[0] = x
                if l[1] in A:
                    for x in a:
                        if l[1] in x:
                            l[1] = x
            for i in range(1,len(n)):
     
                if i == 1:
                    o.append(n[i])
                else:
                    cc = 0
                    for j in e:
   
                        if n[i] in j[0] and n[i-1] in j[1]:
                            cc +=1
                        elif n[i] in j[1] and n[i-1] in j[0]:
                            cc +=1
                    if cc != 0:
                        print('No')
                        break
            if cc == 0:
                print('Okay')
            
                        






























# 1681531, 2022-11-12 11:28:28, P-PPP- (67%)

def mli(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        return [l.strip().split() for l in f]

n = input().split()
a = []
e = []
A = []
c = 0
d = 0
if n[0] == 'Ally':
    for i in range(1,len(n)):
        if len(a) == 0:
            a.append([n[i]])
            A.append(n[i])
        else:
            a[c].append(n[i])
            A.append(n[i])
    c += 1    
if n[0] == 'Enemy':
    for i in range(1,len(n)):
        if len(e) == 0:
            e.append([n[i]])
        else:
            e[d].append(n[i])
    d += 1    
while n!=['End']:
    n = input().split()
    if n!=['End']:
        if n[0] == 'Ally':
            for i in range(1,len(n)):
                if i == 1:
                    a.append([n[i]])
                    A.append(n[i])
                else:
                    a[c].append(n[i])
                    A.append(n[i])
            c += 1    
        if n[0] == 'Enemy':
            for i in range(1,len(n)):
                if i == 1:
                    e.append([n[i]])
                else:
                    e[d].append(n[i])
            d += 1    
        elif n[0] == 'Table':
            o = []
            for l in e:
                if l[0] in A:
                    for x in a:
                        if l[0] in x:
                            l[0] = x
                if l[1] in A:
                    for x in a:
                        if l[1] in x:
                            l[1] = x
            for i in range(1,len(n)):
                    cc = 0
                    for j in e:
                        if n[i] in j[0] and n[i-1] in j[1]:
                            cc +=1
                        elif n[i] in j[1] and n[i-1] in j[0]:
                            cc +=1
                    if cc != 0:
                        print('No')
                        break
            if cc == 0:
                print('Okay')
            
                        






























# 1681675, 2022-11-12 11:30:15, x-PPP- (50%)

def mli(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        return [l.strip().split() for l in f]

n = input().split()
a = []
e = []
A = []
c = 0
d = 0
if n[0] == 'Ally':
    for i in range(1,len(n)):
        if len(a) == 0:
            a.append([n[i]])
            A.append(n[i])
        else:
            a[c].append(n[i])
            A.append(n[i])
    c += 1    
if n[0] == 'Enemy':
    for i in range(1,len(n)):
        if len(e) == 0:
            e.append([n[i]])
        else:
            e[d].append(n[i])
    d += 1    
while n!=['End']:
    n = input().split()
    if n!=['End']:
        if n[0] == 'Ally':
            for i in range(1,len(n)):
                if i == 1:
                    a.append([n[i]])
                    A.append(n[i])
                else:
                    a[c].append(n[i])
                    A.append(n[i])
            c += 1    
        if n[0] == 'Enemy':
            for i in range(1,len(n)):
                if i == 1:
                    e.append([n[i]])
                else:
                    e[d].append(n[i])
            d += 1    
        elif n[0] == 'Table':
            for l in e:
                if l[0] in A:
                    for x in a:
                        if l[0] in x:
                            l[0] = x
                if l[1] in A:
                    for x in a:
                        if l[1] in x:
                            l[1] = x
            for i in range(1,len(n)):
                    cc = 0
                    for j in e:
                        if n[i] in j[0] and n[i-1] in j[1]:
                            cc +=1
                        elif n[i] in j[1] and n[i-1] in j[0]:
                            cc +=1
                    if cc != 0:
                        print('No')
                        break
                    if n[0] in j[0] and n[len(n)-1] in j[1]:
                        cc +=1
                    elif n[0] in j[1] and n[len(n)-1] in j[0]:
                        cc +=1
            if cc == 0:
                print('Okay')
            
                        






























# 1681703, 2022-11-12 11:30:43, x-PPP- (50%)

def mli(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        return [l.strip().split() for l in f]

n = input().split()
a = []
e = []
A = []
c = 0
d = 0
if n[0] == 'Ally':
    for i in range(1,len(n)):
        if len(a) == 0:
            a.append([n[i]])
            A.append(n[i])
        else:
            a[c].append(n[i])
            A.append(n[i])
    c += 1    
if n[0] == 'Enemy':
    for i in range(1,len(n)):
        if len(e) == 0:
            e.append([n[i]])
        else:
            e[d].append(n[i])
    d += 1    
while n!=['End']:
    n = input().split()
    if n!=['End']:
        if n[0] == 'Ally':
            for i in range(1,len(n)):
                if i == 1:
                    a.append([n[i]])
                    A.append(n[i])
                else:
                    a[c].append(n[i])
                    A.append(n[i])
            c += 1    
        if n[0] == 'Enemy':
            for i in range(1,len(n)):
                if i == 1:
                    e.append([n[i]])
                else:
                    e[d].append(n[i])
            d += 1    
        elif n[0] == 'Table':
            for l in e:
                if l[0] in A:
                    for x in a:
                        if l[0] in x:
                            l[0] = x
                if l[1] in A:
                    for x in a:
                        if l[1] in x:
                            l[1] = x
            for i in range(1,len(n)):
                    cc = 0
                    for j in e:
                        if n[i] in j[0] and n[i-1] in j[1]:
                            cc +=1
                        elif n[i] in j[1] and n[i-1] in j[0]:
                            cc +=1
                    
                    if n[0] in j[0] and n[len(n)-1] in j[1]:
                        cc +=1
                    elif n[0] in j[1] and n[len(n)-1] in j[0]:
                        cc +=1
                    if cc != 0:
                        print('No')
                        break
            if cc == 0:
                print('Okay')
            
                        































6530105921
# 1680546, 2022-11-12 11:00:52, x----- (0%)

x = input().strip().split()
ally = {}
while x[0] != "Enemy":
    a = []
    for i in range(1,len(x)):
        a.append(x[i])
    for e in a:
        ally[e] = []
        for k in a:
            if k != e:
                ally[e].append(k)
    x = input().strip().split()
enemy ={}
while x[0] != "Table":
    enemy[x[1]] = [x[2]]
    enemy[x[2]] = [x[1]]
    if x[1] in ally:
        for e in ally[x[1]]:
            enemy[e] = [x[2]]
    if x[2] in ally:
        for e in ally[x[2]]:
            enemy[e] = [x[1]]
    if x[2] in ally:
        for e in ally[x[2]]:
            enemy[x[1]].append(e)
            if x[1] in ally:
                for k in ally[x[1]]:
                    enemy[k].append(e)
    if x[1] in ally:
        for e in ally[x[1]]:
            enemy[x[2]].append(e)
            if x[2] in ally:
                for k in ally[x[2]]:
                    enemy[k].append(e)
    x = input().strip().split()
while x[0] != "End":
    b = [x[-1]]
    for i in range(1,len(x)):
        b.append(x[i])
    ok = True
    for i in range(len(b)-1):
        if b[i] in enemy:
            if b[i+1] in enemy[b[i]]:
                ok = False
                break
    if ok:
        print("Okay")
    else:
        print("NO")
    x = input().strip().split()
# 1680558, 2022-11-12 11:01:36, xP-PP- (50%)

x = input().strip().split()
ally = {}
while x[0] != "Enemy":
    a = []
    for i in range(1,len(x)):
        a.append(x[i])
    for e in a:
        ally[e] = []
        for k in a:
            if k != e:
                ally[e].append(k)
    x = input().strip().split()
enemy ={}
while x[0] != "Table":
    enemy[x[1]] = [x[2]]
    enemy[x[2]] = [x[1]]
    if x[1] in ally:
        for e in ally[x[1]]:
            enemy[e] = [x[2]]
    if x[2] in ally:
        for e in ally[x[2]]:
            enemy[e] = [x[1]]
    if x[2] in ally:
        for e in ally[x[2]]:
            enemy[x[1]].append(e)
            if x[1] in ally:
                for k in ally[x[1]]:
                    enemy[k].append(e)
    if x[1] in ally:
        for e in ally[x[1]]:
            enemy[x[2]].append(e)
            if x[2] in ally:
                for k in ally[x[2]]:
                    enemy[k].append(e)
    x = input().strip().split()
while x[0] != "End":
    b = [x[-1]]
    for i in range(1,len(x)):
        b.append(x[i])
    ok = True
    for i in range(len(b)-1):
        if b[i] in enemy:
            if b[i+1] in enemy[b[i]]:
                ok = False
                break
    if ok:
        print("Okay")
    else:
        print("No")
    x = input().strip().split()
# 1680782, 2022-11-12 11:09:05, PP-PP- (67%)

x = input().strip().split()
ally = {}
while (x[0] != "Enemy") and (x[0] != "Table") and (x[0] != "End"):
    a = []
    for i in range(1,len(x)):
        a.append(x[i])
    for e in a:
        ally[e] = []
        for k in a:
            if k != e:
                ally[e].append(k)
    x = input().strip().split()
enemy ={}
while (x[0] != "Table") and (x[0] != "End"):
    enemy[x[1]] = [x[2]]
    enemy[x[2]] = [x[1]]
    if x[1] in ally:
        for e in ally[x[1]]:
            enemy[e] = [x[2]]
    if x[2] in ally:
        for e in ally[x[2]]:
            enemy[e] = [x[1]]
    if x[2] in ally:
        for e in ally[x[2]]:
            enemy[x[1]].append(e)
            if x[1] in ally:
                for k in ally[x[1]]:
                    enemy[k].append(e)
    if x[1] in ally:
        for e in ally[x[1]]:
            enemy[x[2]].append(e)
            if x[2] in ally:
                for k in ally[x[2]]:
                    enemy[k].append(e)
    x = input().strip().split()
while x[0] != "End":
    b = [x[-1]]
    for i in range(1,len(x)):
        b.append(x[i])
    ok = True
    for i in range(len(b)-1):
        if b[i] in enemy:
            if b[i+1] in enemy[b[i]]:
                ok = False
                break
    if ok:
        print("Okay")
    else:
        print("No")
    x = input().strip().split()
# 1681494, 2022-11-12 11:27:39, PPxPxx (50%)

x = input().strip().split()
ally = {}
while (x[0] != "Enemy") and (x[0] != "Table") and (x[0] != "End"):
    a = []
    for i in range(1,len(x)):
        a.append(x[i])
    for e in a:
        ally[e] = []
        for k in a:
            if k != e:
                ally[e].append(k)
    x = input().strip().split()
enemy ={}
while (x[0] != "Table") and (x[0] != "End"):
    if (x[1] not in enemy) and (x[2] not in enemy):
        enemy[x[1]] = [x[2]]
        enemy[x[2]] = [x[1]]
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[e] = [x[2]]
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[e] = [x[1]]
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[x[1]].append(e)
                if x[1] in ally:
                    for k in ally[x[1]]:
                        enemy[k].append(e)
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[x[2]].append(e)
                if x[2] in ally:
                    for k in ally[x[2]]:
                        enemy[k].append(e)
    elif x[1] in enemy:
        enemy[x[1]].append(x[2])
        enemy[x[2]] = [x[1]]
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[e].append[x[2]]
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[e] = [x[1]]
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[x[1]].append(e)
                if x[1] in ally:
                    for k in ally[x[1]]:
                        enemy[k].append(e)
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[x[2]].append(e)
                if x[2] in ally:
                    for k in ally[x[2]]:
                        enemy[k].append(e)
    elif x[2] in enemy:
        enemy[x[2]].append(x[1])
        enemy[x[1]] = [x[2]]
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[e].append[x[1]]
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[e] = [x[2]]
        if x[1] in ally:
            for e in ally[x[1]]:
                enemy[x[2]].append(e)
                if x[2] in ally:
                    for k in ally[x[2]]:
                        enemy[k].append(e)
        if x[2] in ally:
            for e in ally[x[2]]:
                enemy[x[1]].append(e)
                if x[1] in ally:
                    for k in ally[x[1]]:
                        enemy[k].append(e)

    x = input().strip().split()
while x[0] != "End":
    b = [x[-1]]
    for i in range(1,len(x)):
        b.append(x[i])
    ok = True
    for i in range(len(b)-1):
        if b[i] in enemy:
            if b[i+1] in enemy[b[i]]:
                ok = False
                break
    if ok:
        print("Okay")
    else:
        print("No")
    x = input().strip().split()
# 1681535, 2022-11-12 11:28:31, PP-PP- (67%)

x = input().strip().split()
ally = {}
while (x[0] != "Enemy") and (x[0] != "Table") and (x[0] != "End"):
    a = []
    for i in range(1,len(x)):
        a.append(x[i])
    for e in a:
        ally[e] = []
        for k in a:
            if k != e:
                ally[e].append(k)
    x = input().strip().split()
enemy ={}
while (x[0] != "Table") and (x[0] != "End"):
    enemy[x[1]] = [x[2]]
    enemy[x[2]] = [x[1]]
    if x[1] in ally:
        for e in ally[x[1]]:
            enemy[e] = [x[2]]
    if x[2] in ally:
        for e in ally[x[2]]:
            enemy[e] = [x[1]]
    if x[2] in ally:
        for e in ally[x[2]]:
            enemy[x[1]].append(e)
            if x[1] in ally:
                for k in ally[x[1]]:
                    enemy[k].append(e)
    if x[1] in ally:
        for e in ally[x[1]]:
            enemy[x[2]].append(e)
            if x[2] in ally:
                for k in ally[x[2]]:
                    enemy[k].append(e)
    x = input().strip().split()
while x[0] != "End":
    b = [x[-1]]
    for i in range(1,len(x)):
        b.append(x[i])
    ok = True
    for i in range(len(b)-1):
        if b[i] in enemy:
            if b[i+1] in enemy[b[i]]:
                ok = False
                break
    if ok:
        print("Okay")
    else:
        print("No")
    x = input().strip().split()

6531317821
# 1680696, 2022-11-12 11:06:05, PPPP-- (67%)

country,answer = {},[]
t = input().strip().split()
while t[0] != "Table":
    ss = set(t[1:])
    if t[0] == "Ally":
        for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Ally": " ".join(list(ss-set(list(t[i+1]))))+" ","Enemy": ""}
            elif t[i+1] in country and "Ally" in country[t[i+1]]:
                country[t[i+1]]["Ally"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Ally" not in country[t[i+1]]:
                country[t[i+1]]["Ally"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    elif t[0] == "Enemy":
       for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Enemy": " ".join(list(ss-set(list(t[i+1]))))+" ","Ally": ""}
            elif t[i+1] in country and "Enemy" in country[t[i+1]]:
                country[t[i+1]]["Enemy"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Enemy" not in country[t[i+1]]:
                country[t[i+1]]["Enemy"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    t = input().strip().split()

for coun,alll in country.items():
    for e in alll:
        country[coun][e] = country[coun][e].split()
for coun,alll in country.items():
    for e in alll:
        for x in country[coun][e]:
            if x == coun:
                country[coun][e].remove(x)
for coun,alll in country.items():
    for e in country[coun]["Ally"]:
        country[coun]["Enemy"] += country[e]["Enemy"]
while t[0] != "End":
    check = True
    tab = t[1:]
    for i in range(len(tab)-1):
        if tab[i] in country:
            if tab[i-1] in country[tab[i]]["Enemy"] or tab[i+1] in country[tab[i]]["Enemy"]:
                answer.append("No")
                check = False
                break
    if check:
        answer.append("Okay")
    t = input().strip().split()
for e in answer:
    print(e)
# 1680800, 2022-11-12 11:09:43, PPTTTT (33%)

country,answer = {},[]
t = input().strip().split()
while t[0] != "Table":
    ss = set(t[1:])
    if t[0] == "Ally":
        for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Ally": " ".join(list(ss-set(list(t[i+1]))))+" ","Enemy": ""}
            elif t[i+1] in country and "Ally" in country[t[i+1]]:
                country[t[i+1]]["Ally"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Ally" not in country[t[i+1]]:
                country[t[i+1]]["Ally"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    elif t[0] == "Enemy":
       for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Enemy": " ".join(list(ss-set(list(t[i+1]))))+" ","Ally": ""}
            elif t[i+1] in country and "Enemy" in country[t[i+1]]:
                country[t[i+1]]["Enemy"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Enemy" not in country[t[i+1]]:
                country[t[i+1]]["Enemy"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    t = input().strip().split()

for coun,alll in country.items():
    for e in alll:
        country[coun][e] = country[coun][e].split()
for coun,alll in country.items():
    for e in alll:
        for x in country[coun][e]:
            if x == coun:
                country[coun][e].remove(x)
for coun,alll in country.items():
    for e in country[coun]["Ally"]:
        country[coun]["Enemy"] += country[e]["Enemy"]
    for e in country[coun]["Enemy"]: 
        country[coun]["Enemy"] += country[e]["Ally"] 
while t[0] != "End":
    check = True
    tab = t[1:]
    for i in range(len(tab)-1):
        if tab[i] in country:
            if tab[i-1] in country[tab[i]]["Enemy"] or tab[i+1] in country[tab[i]]["Enemy"]:
                answer.append("No")
                check = False
                break
    if check:
        answer.append("Okay")
    t = input().strip().split()
for e in answer:
    print(e)
# 1680815, 2022-11-12 11:10:13, PPPP-- (67%)

country,answer = {},[]
t = input().strip().split()
while t[0] != "Table":
    ss = set(t[1:])
    if t[0] == "Ally":
        for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Ally": " ".join(list(ss-set(list(t[i+1]))))+" ","Enemy": ""}
            elif t[i+1] in country and "Ally" in country[t[i+1]]:
                country[t[i+1]]["Ally"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Ally" not in country[t[i+1]]:
                country[t[i+1]]["Ally"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    elif t[0] == "Enemy":
       for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Enemy": " ".join(list(ss-set(list(t[i+1]))))+" ","Ally": ""}
            elif t[i+1] in country and "Enemy" in country[t[i+1]]:
                country[t[i+1]]["Enemy"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Enemy" not in country[t[i+1]]:
                country[t[i+1]]["Enemy"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    t = input().strip().split()

for coun,alll in country.items():
    for e in alll:
        country[coun][e] = country[coun][e].split()
for coun,alll in country.items():
    for e in alll:
        for x in country[coun][e]:
            if x == coun:
                country[coun][e].remove(x)
for coun,alll in country.items():
    for e in country[coun]["Ally"]:
        country[coun]["Enemy"] += country[e]["Enemy"]
while t[0] != "End":
    check = True
    tab = t[1:]
    for i in range(len(tab)-1):
        if tab[i] in country:
            if tab[i-1] in country[tab[i]]["Enemy"] or tab[i+1] in country[tab[i]]["Enemy"]:
                answer.append("No")
                check = False
                break
    if check:
        answer.append("Okay")
    t = input().strip().split()
for e in answer:
    print(e)
# 1681516, 2022-11-12 11:28:08, PPPP-- (67%)

country,answer = {},[]
t = input().strip().split()
while t[0] != "Table":
    ss = set(t[1:])
    if t[0] == "Ally":
        for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Ally": " ".join(list(ss-set(list(t[i+1]))))+" ","Enemy": ""}
            elif t[i+1] in country and "Ally" in country[t[i+1]]:
                country[t[i+1]]["Ally"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Ally" not in country[t[i+1]]:
                country[t[i+1]]["Ally"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    elif t[0] == "Enemy":
       for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Enemy": " ".join(list(ss-set(list(t[i+1]))))+" ","Ally": ""}
            elif t[i+1] in country and "Enemy" in country[t[i+1]]:
                country[t[i+1]]["Enemy"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Enemy" not in country[t[i+1]]:
                country[t[i+1]]["Enemy"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    t = input().strip().split()

for coun,alll in country.items():
    for e in alll:
        country[coun][e] = country[coun][e].split()
for coun,alll in country.items():
    for e in alll:
        for x in country[coun][e]:
            if x == coun:
                country[coun][e].remove(x)
for coun,alll in country.items():
    for e in country[coun]["Ally"]:
        country[coun]["Enemy"] += country[e]["Enemy"]
while t[0] != "End":
    check = True
    tab = t[1:]
    for i in range(len(tab)-1):
        if tab[i] in country:
            if tab[i-1] in country and tab[i+1] in country:
                if tab[i-1] in country[tab[i]]["Enemy"] or tab[i+1] in country[tab[i]]["Enemy"] or tab[i] in country[tab[i-1]]["Enemy"] or tab[i] in country[tab[i+1]]["Enemy"]:
                    answer.append("No")
                    check = False
                    break
            elif tab[i-1] in country and tab[i+1] not in country:
                if tab[i-1] in country[tab[i]]["Enemy"] or tab[i+1] in country[tab[i]]["Enemy"] or tab[i] in country[tab[i-1]]["Enemy"]:
                    answer.append("No")
                    check = False
                    break
            elif tab[i-1] not in country and tab[i+1] in country:
                if tab[i-1] in country[tab[i]]["Enemy"] or tab[i+1] in country[tab[i]]["Enemy"] or tab[i] in country[tab[i+1]]["Enemy"]:
                    answer.append("No")
                    check = False
                    break
    if check:
        answer.append("Okay")
    t = input().strip().split()
for e in answer:
    print(e)
# 1681577, 2022-11-12 11:29:13, PPPP-- (67%)

country,answer = {},[]
t = input().strip().split()
while t[0] != "Table":
    ss = set(t[1:])
    if t[0] == "Ally":
        for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Ally": " ".join(list(ss-set(list(t[i+1]))))+" ","Enemy": ""}
            elif t[i+1] in country and "Ally" in country[t[i+1]]:
                country[t[i+1]]["Ally"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Ally" not in country[t[i+1]]:
                country[t[i+1]]["Ally"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    elif t[0] == "Enemy":
       for i in range(len(t[1:])):
            if t[i+1] not in country:
                country[t[i+1]] = {"Enemy": " ".join(list(ss-set(list(t[i+1]))))+" ","Ally": ""}
            elif t[i+1] in country and "Enemy" in country[t[i+1]]:
                country[t[i+1]]["Enemy"] += " ".join(list(ss-set(list(t[i+1]))))+" "
            elif t[i+1] in country and "Enemy" not in country[t[i+1]]:
                country[t[i+1]]["Enemy"] = " ".join(list(ss-set(list(t[i+1]))))+" "
    t = input().strip().split()

for coun,alll in country.items():
    for e in alll:
        country[coun][e] = country[coun][e].split()
for coun,alll in country.items():
    for e in alll:
        for x in country[coun][e]:
            if x == coun:
                country[coun][e].remove(x)
for coun,alll in country.items():
    for e in country[coun]["Ally"]:
        country[coun]["Enemy"] += country[e]["Enemy"]
while t[0] != "End":
    check = True
    tab = t[1:]
    for i in range(len(tab)-1):
        if tab[i] in country:
            if tab[i-1] in country and tab[i+1] in country:
                if tab[i-1] in country[tab[i]]["Enemy"] or tab[i+1] in country[tab[i]]["Enemy"] or tab[i] in country[tab[i-1]]["Enemy"] or tab[i] in country[tab[i+1]]["Enemy"]:
                    answer.append("No")
                    check = False
                    break
            elif tab[i-1] in country and tab[i+1] not in country:
                if tab[i-1] in country[tab[i]]["Enemy"] or tab[i+1] in country[tab[i]]["Enemy"] or tab[i] in country[tab[i-1]]["Enemy"]:
                    answer.append("No")
                    check = False
                    break
            elif tab[i-1] not in country and tab[i+1] in country:
                if tab[i-1] in country[tab[i]]["Enemy"] or tab[i+1] in country[tab[i]]["Enemy"] or tab[i] in country[tab[i+1]]["Enemy"]:
                    answer.append("No")
                    check = False
                    break
    if check:
        answer.append("Okay")
    t = input().strip().split()
for e in answer:
    print(e)

6531326421
# 1679777, 2022-11-12 10:27:21, ------ (0%)

x = input().split()
Ally = {}
Enemy = []
while x[0] == 'Ally' :
    Ally[len(Ally)] = set(x[1:])
    x = input().split()
while x[0] == 'Enemy' :
    a = set()
    b = set()
    for e in Ally :
        if x[1] in Ally[e] :
            a = Ally[e]
        if x[2] in Ally[e] :
            b = Ally[e]
    if a == set() and b != set() :
        c = set([x[1]])
        Enemy.append([c,b])
    elif b == set() and a != set() :
        c = set([x[2]])
        Enemy.append([a,c])
    elif a == set() and b == set() :
        Enemy.append([set([x[1]]),set([x[2]])])
    else :
        Enemy.append([a,b])
    a = set()
    b = set()
    x = input().split()
while x[0] == 'Table' :
    y = x[1:]
    check = True
    for i in range(len(y)-1) :
        for e in Enemy :
            if y[i] in e[0] and y[i+1] in e[1] :
                check = False
                break
            if y[i] in e[1] and y[i+1] in e[0] :
                check = False
                break
        if not check :
            print('No')
            break
    if check :
        print('OK')
    x = input().split()
# 1679884, 2022-11-12 10:31:18, P-PPP- (67%)

x = input().split()
Ally = {}
Enemy = []
while x[0] == 'Ally' :
    Ally[len(Ally)] = set(x[1:])
    x = input().split()
while x[0] == 'Enemy' :
    a = set()
    b = set()
    for e in Ally :
        if x[1] in Ally[e] :
            a = Ally[e]
        if x[2] in Ally[e] :
            b = Ally[e]
    if a == set() and b != set() :
        c = set([x[1]])
        Enemy.append([c,b])
    elif b == set() and a != set() :
        c = set([x[2]])
        Enemy.append([a,c])
    elif a == set() and b == set() :
        Enemy.append([set([x[1]]),set([x[2]])])
    else :
        Enemy.append([a,b])
    a = set()
    b = set()
    x = input().split()
while x[0] == 'Table' and x[0] != 'END' :
    y = x[1:]
    check = True
    for i in range(len(y)-1) :
        for e in Enemy :
            if y[i] in e[0] and y[i+1] in e[1] :
                check = False
                break
            if y[i] in e[1] and y[i+1] in e[0] :
                check = False
                break
        if not check :
            print('No')
            break
    if check :
        print('Okay')
    x = input().split()
# 1681409, 2022-11-12 11:26:05, xxxxxx (0%)

x = input().split()
Ally = {}
Enemy = []
while x[0] != 'END' :
    if x[0] == 'Ally' :
        y = x[1:]
        if len(Ally) != 0 :
            for i in range(len(Ally)) :
                for e in y :
                    if e in Ally[i] :
                        Ally[i].update(y)
                        break
                    else :
                        Ally[len(Ally)] = set(y)
                        break
        else :
            Ally[len(Ally)] = set(y) 
    if x[0] == 'Enemy' :
        a = set()
        b = set()
        for e in Ally :
            if x[1] in Ally[e] :
                a = Ally[e]
            if x[2] in Ally[e] :
                b = Ally[e]
        if a == set() and b != set() :
            c = set([x[1]])
            Enemy.append([c,b])
        elif b == set() and a != set() :
            c = set([x[2]])
            Enemy.append([a,c])
        elif a == set() and b == set() :
            Enemy.append([set([x[1]]),set([x[2]])])
        else :
            Enemy.append([a,b])
        a = set()
        b = set()  
    if x[0] == 'Table' :
        y = x[1:]
        check = True
        for i in range(len(y)-1) :
            for e in Enemy :
                if y[i] in e[0] and y[i+1] in e[1] :
                    check = False
                    break
                if y[i] in e[1] and y[i+1] in e[0] :
                    check = False
                    break
            if not check :
                print('No')
                break
        if check :
            print('Okay')
    x = input().split()
# 1681483, 2022-11-12 11:27:27, xxxxxx (0%)

x = input().split()
Ally = {}
Enemy = []
while x[0] != 'END' :
    if x[0] == 'Ally' :
        y = x[1:]
        if len(Ally) != 0 :
            for i in range(len(Ally)) :
                for e in y :
                    if e in Ally[i] :
                        Ally[i].update(y)
                        break
                    else :
                        Ally[len(Ally)] = set(y)
                        break
        else :
            Ally[len(Ally)] = set(y) 
    if x[0] == 'Enemy' :
        a = set()
        b = set()
        for e in Ally :
            if x[1] in Ally[e] :
                a = Ally[e]
            if x[2] in Ally[e] :
                b = Ally[e]
        if a == set() and b != set() :
            c = set([x[1]])
            Enemy.append([c,b])
        elif b == set() and a != set() :
            c = set([x[2]])
            Enemy.append([a,c])
        elif a == set() and b == set() :
            Enemy.append([set([x[1]]),set([x[2]])])
        else :
            Enemy.append([a,b])
        a = set()
        b = set()  
    if x[0] == 'Table' :
        y = x[1:]
        check = True
        for i in range(len(y)-1) :
            for e in Enemy :
                if y[i] in e[0] and y[i+1] in e[1] :
                    check = False
                    break
                if y[i] in e[1] and y[i+1] in e[0] :
                    check = False
                    break
            if not check :
                print('No')
                break
        if check :
            print('Okay')
    x = input().split()
# 1681501, 2022-11-12 11:27:50, P-PPP- (67%)

x = input().split()
Ally = {}
Enemy = []
while x[0] == 'Ally' :
    Ally[len(Ally)] = set(x[1:])
    x = input().split()
while x[0] == 'Enemy' :
    a = set()
    b = set()
    for e in Ally :
        if x[1] in Ally[e] :
            a = Ally[e]
        if x[2] in Ally[e] :
            b = Ally[e]
    if a == set() and b != set() :
        c = set([x[1]])
        Enemy.append([c,b])
    elif b == set() and a != set() :
        c = set([x[2]])
        Enemy.append([a,c])
    elif a == set() and b == set() :
        Enemy.append([set([x[1]]),set([x[2]])])
    else :
        Enemy.append([a,b])
    a = set()
    b = set()
    x = input().split()
while x[0] == 'Table' and x[0] != 'END' :
    y = x[1:]
    check = True
    for i in range(len(y)-1) :
        for e in Enemy :
            if y[i] in e[0] and y[i+1] in e[1] :
                check = False
                break
            if y[i] in e[1] and y[i+1] in e[0] :
                check = False
                break
        if not check :
            print('No')
            break
    if check :
        print('Okay')
    x = input().split()

6530022421
# 1680094, 2022-11-12 10:41:31, xxTTTT (0%)

Ally = {}
Enemy = {}
x = input()
while x != 'End':
    y = x.split()
    if y[0] == 'Ally':
        for e in y[1:]:
            if e not in Ally:
                Ally[e] = [c for c in y[1:] if c != e]
            else:
                Ally[e] += [c for c in y[1:] if c != e]
    if y[0] == 'Enemy':
        for e in y[1:]:
            Enemy[e] = [c for c in y[1:] if c != e]
        for c in Enemy[e]:
            if c in Ally:
                Enemy[e] += [ch for ch in Ally[c]]
    if y[0] == 'Table':
        y = y[1:] + y[1]
        for i in range(len(y) - 1):
            if y[i] in Enemy:
                if y[i+1] in Enemy[y[i]]:
                    print('No')
        else:
            print('Okay')
    x = input()
# 1680186, 2022-11-12 10:45:36, xxxxxx (0%)

Ally = {}
Enemy = {}
x = input()
while x != 'End':
    y = x.split()
    if y[0] == 'Ally':
        for e in y[1:]:
            if e not in Ally:
                Ally[e] = set([c for c in y[1:] if c != e])
            else:
                Ally[e] = Ally[e] | set([c for c in y[1:] if c != e])
    if y[0] == 'Enemy':
        for e in y[1:]:
            if e not in Enemy:
                Enemy[e] = set([c for c in y[1:] if c != e])
            else:
                Enemy[e] = Enemy[e] | set([c for c in y[1:] if c != e])
        for c in Enemy[e]:
            if c in Ally:
                Enemy[e] = Enemy[e] | set([ch for ch in Ally[c]])
    if y[0] == 'Table':
        y = y[1:] + y[1]
        for i in range(len(y) - 1):
            if y[i] in Enemy:
                if y[i+1] in Enemy[y[i]]:
                    print('No')
        else:
            print('Okay')
    x = input()
# 1680215, 2022-11-12 10:47:14, xxxxxx (0%)

Ally = {}
Enemy = {}
x = input()
while x != 'End':
    y = x.split()
    if y[0] == 'Ally':
        for e in y[1:]:
            if e not in Ally:
                Ally[e] = set([c for c in y[1:] if c != e])
            else:
                Ally[e] = Ally[e] | set([c for c in y[1:] if c != e])
    if y[0] == 'Enemy':
        for e in y[1:]:
            if e not in Enemy:
                Enemy[e] = set([c for c in y[1:] if c != e])
            else:
                Enemy[e] = Enemy[e] | set([c for c in y[1:] if c != e])
        for c in Enemy[e]:
            if c in Ally:
                Enemy[e] = Enemy[e] | set([ch for ch in Ally[c]])
    if y[0] == 'Table':
        y = y[1:].append(y[1])
        for i in range(len(y) - 1):
            if y[i] in Enemy:
                if y[i+1] in Enemy[y[i]]:
                    print('No')
        else:
            print('Okay')
    x = input()
# 1680593, 2022-11-12 11:02:49, PPPP-- (67%)

Ally = {}
Enemy = {}
x = input()
while x != 'End':
    y = x.split()
    if y[0] == 'Ally':
        for e in y[1:]:
            if e not in Ally:
                Ally[e] = set([c for c in y[1:] if c != e])
            else:
                Ally[e] = Ally[e] | set([c for c in y[1:] if c != e])
    if y[0] == 'Enemy':
        for e in y[1:]:
            if e not in Enemy:
                Enemy[e] = set([c for c in y[1:] if c != e])
            else:
                Enemy[e] = Enemy[e] | set([c for c in y[1:] if c != e])
        for c in Enemy[e]:
            if c in Ally:
                Enemy[e] = Enemy[e] | Ally[c]
    if y[0] == 'Table':
        L = y[1:] + [y[1]]
        ANS = set()
        for i in range(len(L)-1):
            if L[i] in Enemy:
                if L[i+1] in Enemy[L[i]]:
                    ANS.add('No')
            else:
                ANS.add('Okay')
        if 'No' in ANS:
            print('No')
        else:
            print('Okay')
    x = input()

6231129921
# 1680591, 2022-11-12 11:02:47, P-P--- (33%)

x = input().split()
not_sit = {}
t = []
while x[0] == 'Ally':
    Ally = set(x[1:])
    t.append(Ally)
    for e in Ally:
        not_sit[e] = set()
    x = input().split()
    
    
 #{ประเทศ:{ศัตรู}}
while x[0] == 'Enemy':
    if x[1] not in not_sit:
        not_sit[x[1]] = set()
    not_sit[x[1]].add(x[2])
    if x[2] not in not_sit:
        not_sit[x[2]] = set()
    not_sit[x[2]].add(x[1])
    x = input().split()

for k,v in not_sit.items():
    for s in t:
        if len(v&s) >0:
            not_sit[k].update(v | s)
 
#print(not_sit)
ans = ''
while x[0] != 'End':
    for e in x[1:]:
        if e not in not_sit:
            not_sit[e] = set()
    

    if x[1] in not_sit[x[-1]]:
        ans+='1'
    if x[-1] in not_sit[x[1]]:
        ans += '1'
    for i in range(1,len(x)-2,1):
        if x[i] in not_sit[x[i+1]]:
            ans+='1'
        if x[i+1] in not_sit[x[i]]:
            ans += '1'
    if '1' in ans:
        print('No')
    else:
        print('Okay')

    x = input().split()
    
    
    
    
    
    
    
    

# 1680721, 2022-11-12 11:07:01, PPPP-- (67%)

x = input().split()
not_sit = {}
t = []
while x[0] == 'Ally':
    Ally = set(x[1:])
    t.append(Ally)
    for e in Ally:
        not_sit[e] = set()
    x = input().split()
    
    
 #{ประเทศ:{ศัตรู}}
while x[0] == 'Enemy':
    if x[1] not in not_sit:
        not_sit[x[1]] = set()
    not_sit[x[1]].add(x[2])
    if x[2] not in not_sit:
        not_sit[x[2]] = set()
    not_sit[x[2]].add(x[1])
    x = input().split()

for k,v in not_sit.items():
    for s in t:
        if len(v&s) >0:
            not_sit[k].update(v | s)
 
#print(not_sit)
while x[0] != 'End':
    ans = ''
    for e in x[1:]:
        if e not in not_sit:
            not_sit[e] = set()

    if x[1] in not_sit[x[-1]]:
        ans+='1'
    if x[-1] in not_sit[x[1]]:
        ans += '1'
    for i in range(1,len(x)-2,1):
        if x[i] in not_sit[x[i+1]]:
            ans+='1'
        if x[i+1] in not_sit[x[i]]:
            ans += '1'
    if '1' in ans:
        print('No')
    else:
        print('Okay')

    x = input().split()
    
    
    
# 1680892, 2022-11-12 11:12:57, PPPP-- (67%)

x = input().split()
not_sit = {}
t = []
while x[0] == 'Ally':
    Ally = set(x[1:])
    t.append(Ally)
    for e in Ally:
        not_sit[e] = set()
    x = input().split()
    
    
 #{ประเทศ:{ศัตรู}}
while x[0] == 'Enemy':
    if x[1] not in not_sit:
        not_sit[x[1]] = set()
    not_sit[x[1]].add(x[2])
    if x[2] not in not_sit:
        not_sit[x[2]] = set()
    not_sit[x[2]].add(x[1])
    x = input().split()

for k,v in not_sit.items():
    for s in t:
        if len(v&s) >0:
            not_sit[k].update(v | s)
 
#print(not_sit)
while x[0] != 'End':
    ans = ''
    for e in x[1:]:
        if e not in not_sit:
            not_sit[e] = set()

    if x[1] in not_sit[x[-1]]:
        ans+='1'
    if x[-1] in not_sit[x[1]]:
        ans += '1'
    for i in range(1,len(x)-1,1):
        if x[i] in not_sit[x[i+1]]:
            ans+='1'
        if x[i+1] in not_sit[x[i]]:
            ans += '1'
    if '1' in ans:
        print('No')
    else:
        print('Okay')

    x = input().split()
    

6530087221
# 1680138, 2022-11-12 10:43:17, ------ (0%)

k = 0
country_ally = {}
country_enemy = {} 
while k == 0 :
    x = input().split()
    if x == ['End'] :
        k += 1
    elif x[0] == 'Ally':
        temp_ally = []
        for i in range(1,len(x)) :
            temp_ally += [x[i]]
            country_ally[x[i]] = temp_ally
#         print(country_ally)
    elif x[0] == 'Enemy' :
        pass
    elif x[0] == 'Table' :
        print('No')
# 1680152, 2022-11-12 10:43:43, P----- (17%)

k = 0
country_ally = {}
country_enemy = {} 
while k == 0 :
    x = input().split()
    if x == ['End'] :
        k += 1
    elif x[0] == 'Ally':
        temp_ally = []
        for i in range(1,len(x)) :
            temp_ally += [x[i]]
            country_ally[x[i]] = temp_ally
#         print(country_ally)
    elif x[0] == 'Enemy' :
        pass
    elif x[0] == 'Table' :
        print('Okay')
# 1681436, 2022-11-12 11:26:29, PPPP-x (67%)

k = 0
country_ally = {}
country_enemy = {} 
while k == 0 :
    x = input().split()
    if x == ['End'] :
        k += 1
    elif x[0] == 'Ally':
        temp_ally = []
        for i in range(1,len(x)) :
            temp_ally += [x[i]]
            country_ally[x[i]] = temp_ally
    elif x[0] == 'Enemy' :
        if x[1] in country_ally :
            temp_enemy1 = country_ally[x[1]]
        if x[2] in country_ally :
            temp_enemy2 = country_ally[x[2]]
        if x[1] in country_ally and x[2] in country_ally :
            for i in temp_enemy1 :
                if i not in country_enemy :
                    country_enemy[i] = temp_enemy2
                else :
                    country_enemy[i] += temp_enemy2
            for i in temp_enemy2 :
                if i not in country_enemy :
                    country_enemy[i] = temp_enemy1
                else :
                    country_enemy[i] += temp_enemy1
        elif x[1] in country_ally and x[2] not in country_ally :
            for i in temp_enemy1 :
                if i not in country_enemy :
                    country_enemy[i] = [x[2]]
                else :
                    country_enemy[i] += [x[2]]
            if x[2] not in country_enemy :
                country_enemy[x[2]] = temp_enemy1
            else :
                country_enemy[x[2]] += temp_enemy1
        elif x[1] not in country_ally and x[2] in country_ally :
            for i in temp_enemy2 :
                if i not in country_enemy :
                    country_enemy[i] = [x[1]]
                else :
                    country_enemy[i] += [x[1]]
            if x[2] not in country_enemy :
                country_enemy[x[1]] = temp_enemy2
            else :
                country_enemy[x[1]] += temp_enemy2
        else :
            if x[1] not in country_enemy :
                country_enemy[x[1]] = [x[2]]
            else :
                country_enemy[x[1]] += [x[2]]
            if x[2] not in country_enemy :
                country_enemy[x[2]] = [x[1]]
            else :
                country_enemy[x[2]] += [x[1]]                   
    elif x[0] == 'Table' :
        check = 0
        for i in range(2,len(x)-1) :
            if x[i] in country_enemy:
                if x[i-1] in country_enemy[x[i]] or x[i+1] in country_enemy[x[i]] :
                    check += 1
        if x[1] in country_enemy :    
            if x[2] in country_enemy[x[1]] or x[len(x)-1] in country_enemy[x[1]]:
                check += 1
        if check == 0 :
            print('Okay')
        if check != 0 :
            print('No')
                
        

6431105021
# 1680109, 2022-11-12 10:42:05, PPPP-- (67%)

def checking(don ,dink,dic_ally , dic_enem) :
    if dink in dic_enem and don in dic_enem[dink] :
        return False
    elif don in dic_enem and dink in dic_enem[don] :
        return False
    return True

doss = input().split()
dic_ally = {}
dic_enem = {}
while doss[0] != "End" :
    if doss[0] == "Ally" :
        for don in doss[1:] :
            ally = doss[1:]
            ally.remove(don)
            dic_ally[don] = ally
    if doss[0] == "Enemy" :
        if doss[1] not in dic_enem :
            dic_enem[doss[1]] = []
        dic_enem[doss[1]].append(doss[2])
        if (doss[2] in dic_ally) :
            dic_enem[doss[1]] += dic_ally[doss[2]]
        
        if doss[2] not in dic_enem :
            dic_enem[doss[2]] = []
        dic_enem[doss[2]].append(doss[1])
        if (doss[1] in dic_ally) :
            dic_enem[doss[2]] += dic_ally[doss[1]]
    if doss[0] == "Table" :
        table = doss[1:]
        flag = True
        for i in range(len(table)) :
            check1 = table[i-1] if i-1 >= 0 else table[-1]
            check2 = table[i+1] if i+1 < len(table) else table[0]
            if not (checking(table[i] , check1 ,dic_ally , dic_enem) and checking(table[i] ,check2,dic_ally , dic_enem)) :
                flag = False
                break
        if (flag) :
            print("Okay")
        else :
            print("No")
    doss = input().split()
            
        


6432036521
# 1680981, 2022-11-12 11:15:58, P-PPP- (67%)

ans = list()
ally = list()
enemy = dict()
x = input()
while x!="End":
    x=x.split()
    s=set(x[1:])
    if x[0]=="Ally":
        if len(ally)!=0:
            exist=False
            for i in range(len(ally)):
                if ally[i].intersection(s)!=set():
                    ally[i].union(s)
                    exist=True
                    break
            if exist == False: ally.append(s)
        else:
            ally.append(s)

    elif x[0]=="Enemy":
        for c in s:
            exist=False
            for d in ally:
                if c in d:
                    exist=True
            if exist==False:
                a=set()
                a.add(c)
                ally.append(a)

        a = x[1]
        b = x[2]
        e = set()
        f = set()
        for c in ally:
            if a in c:
                e = c
            elif b in c:
                f = c
        for c in e:
            if c in enemy:
                enemy[c] = enemy[c].union(f)
            else:
                enemy[c]=f
        for c in f:
            if c in enemy:
                enemy[c] = enemy[c].union(e)
            else:
                enemy[c]=e

    elif x[0]=="Table":
        tf = True
        for i in range(1,len(x)-1):
            if x[i] in enemy:
                if x[i+1] in enemy[x[i]]:
                    ans.append("No")
                    tf = False
                    break
        if tf == True:ans.append("Okay")

    x=input()

for c in ans:
    print(c)

6531805721
# 1680671, 2022-11-12 11:05:06, P-PPP- (67%)

ally = [] ; enemy = [] ; war = {} ; table = []
s = input().split(' ')
while len(s) != 1:
    if s[0] == 'Ally':
        ally.append(tuple(s[1:]))
    elif s[0] == 'Enemy':
        enemy.append(tuple(s[1:]))
    elif s[0] == 'Table':
        table.append(s[1:])
    s = input().split()

def find(l,c):
    for i in l:
        if c in i:
            return i
    return (c,)

for i in enemy:
    i0_ally = find(ally,i[0]) ; i1_ally = find(ally,i[1])
    
    if i0_ally not in war:
        war[i0_ally] = i1_ally
    else:
        war[i0_ally] = war[i0_ally] + i1_ally
    if i1_ally not in war:
        war[i1_ally] = i0_ally
    else:
        war[i1_ally] = war[i1_ally] + i1_ally

def find_key_war(war,c):
    for i in war:
        if c in i:
            return i
    return None

out = []
for i in table:
    for k in range(len(i)-1):
        if find_key_war(war,i[k]) != None:
            if i[k+1] in war[find_key_war(war,i[k])]:
                out.append('No')
                break
    out.append('Okay')
    
i = 0
while i < len(out):
    if out[i] == 'No':
        print('No')
        i += 2
    else:
        print('Okay')
        i += 1

Max Score = 50


6530012121
# 1680612, 2022-11-12 11:03:22, P----- (17%)

blue=[];n=1
red={};vs ={};love= {}


wn = input().strip().split()
while wn!=['End']:
    if wn[0]=='Ally':
        blue.append(wn[1:])
        kk =wn[1:]
        for i in kk:
            kkc = kk.copy()
            love[i] = kkc
    elif wn[0]=='Enemy':
        red[wn[1]]=wn[2]
    elif wn[0] == 'Table':
        if n ==1 :
            for i in list(red.keys()):
                if red[i] in love.keys():
                    vs[i] =love[red[i]]
                else:
                    vs[i] = [red[i]]
            for v,k in red.items():
                if v in love.keys():
                    vs[k] = love[v]
                elif v not in love.keys() and k not in love.keys():
                    vs[k] = [v]
                
        n+=1
        people = wn[1:];valid = True
        for i in range(len(people)-1):
            if i == 0:
                if people[0] in vs.keys():
                    if people[-1] in vs[people[0]]:
                        valid = False
                        break
                elif people[-1] in vs.keys():
                    if people[0] in vs[people[-1]]:
                        valid = False
                        break
            
        if valid == True:print('Okay')
        elif valid == False:print('No')
    wn = input().strip().split()


# 1680719, 2022-11-12 11:07:00, PP-P-- (50%)

blue=[];n=1
red={};vs ={};love= {}


wn = input().strip().split()
while wn!=['End']:
    if wn[0]=='Ally':
        blue.append(wn[1:])
        kk =wn[1:]
        for i in kk:
            kkc = kk.copy()
            love[i] = kkc
    elif wn[0]=='Enemy':
        red[wn[1]]=wn[2]
    elif wn[0] == 'Table':
        if n ==1 :
            for i in list(red.keys()):
                if red[i] in love.keys():
                    vs[i] =love[red[i]]
                else:
                    vs[i] = [red[i]]
            for v,k in red.items():
                if v in love.keys():
                    vs[k] = love[v]
                elif v not in love.keys() and k not in love.keys():
                    vs[k] = [v]
                
        n+=1
        people = wn[1:];valid = True
        for i in range(len(people)-1):
            if i == 0:
                if people[0] in vs.keys():
                    if people[-1] in vs[people[0]]:
                        valid = False
                        break
                elif people[-1] in vs.keys():
                    if people[0] in vs[people[-1]]:
                        valid = False
                        break
            else:
                if people[i-1] in vs.keys():
                    if people[i] in vs[people[i-1]]:
                        valid = False
                        break
                elif people[i] in vs.keys():
                    if people[i-1] in vs[people[i]]:
                        valid = False
                        break
                elif people[i] in vs.keys():
                    if people[i+1] in vs[people[i]]:
                        valid = False
                        break
                elif people[i+1] in vs.keys():
                    if people[i] in vs[people[i+1]]:
                        valid = False
                        break
            
        if valid == True:print('Okay')
        elif valid == False:print('No')
    wn = input().strip().split()


# 1681031, 2022-11-12 11:17:03, PP-P-- (50%)

blue=[];n=1
red={};vs ={};love= {}


wn = input().strip().split()
while wn!=['End']:
    if wn[0]=='Ally':
        blue.append(wn[1:])
        kk =wn[1:]
        for i in kk:
            kkc = kk.copy()
            love[i] = kkc
    elif wn[0]=='Enemy':
        red[wn[1]]=wn[2]
    elif wn[0] == 'Table':
        if n ==1 :
            for i in list(red.keys()):
                if red[i] in love.keys():
                    if i not in vs.keys():
                        vs[i] =love[red[i]]
                    else:
                        vs[i] +=love[red[i]]
                else:
                    if i not in vs.keys():
                        vs[i] = [red[i]]
                    else:
                        vs[i] += [red[i]]
            for v,k in red.items():
                if v in love.keys():
                    if k not in vs.keys():
                        vs[k] = love[v]
                    else:
                        vs[k] += love[v]
                elif v not in love.keys() and k not in love.keys():
                    if k not in vs.keys():   
                        vs[k] = [v]
                    else:
                        vs[k]+=[v]
                
        n+=1
        people = wn[1:];valid = True
        for i in range(len(people)-1):
            if i == 0:
                if people[0] in vs.keys():
                    if people[-1] in vs[people[0]]:
                        valid = False
                        break
                elif people[-1] in vs.keys():
                    if people[0] in vs[people[-1]]:
                        valid = False
                        break
            else:
                if people[i-1] in vs.keys():
                    if people[i] in vs[people[i-1]]:
                        valid = False
                        break
                elif people[i] in vs.keys():
                    if people[i-1] in vs[people[i]]:
                        valid = False
                        break
                elif people[i] in vs.keys():
                    if people[i+1] in vs[people[i]]:
                        valid = False
                        break
                elif people[i+1] in vs.keys():
                    if people[i] in vs[people[i+1]]:
                        valid = False
                        break
            
        if valid == True:print('Okay')
        elif valid == False:print('No')
    wn = input().strip().split()



# 1681044, 2022-11-12 11:17:24, PP-P-- (50%)

blue=[];n=1
red={};vs ={};love= {}


wn = input().strip().split()
while wn!=['End']:
    if wn[0]=='Ally':
        blue.append(wn[1:])
        kk =wn[1:]
        for i in kk:
            kkc = kk.copy()
            love[i] = kkc
    elif wn[0]=='Enemy':
        red[wn[1]]=wn[2]
    elif wn[0] == 'Table':
        if n ==1 :
            for i in list(red.keys()):
                if red[i] in love.keys():
                    if i not in vs.keys():
                        vs[i] =love[red[i]]
                    else:
                        vs[i] +=love[red[i]]
                else:
                    if i not in vs.keys():
                        vs[i] = [red[i]]
                    else:
                        vs[i] += [red[i]]
            for v,k in red.items():
                if v in love.keys():
                    if k not in vs.keys():
                        vs[k] = love[v]
                    else:
                        vs[k] += love[v]
                elif v not in love.keys() and k not in love.keys():
                    if k not in vs.keys():   
                        vs[k] = [v]
                    else:
                        vs[k]+=[v]
                
        n+=1
        people = wn[1:];valid = True
        for i in range(len(people)-1):
            if i == 0:
                if people[0] in vs.keys():
                    if people[-1] in vs[people[0]]:
                        valid = False
                        break
                elif people[-1] in vs.keys():
                    if people[0] in vs[people[-1]]:
                        valid = False
                        break
            else:
                if people[i-1] in vs.keys():
                    if people[i] in vs[people[i-1]]:
                        valid = False
                        break
                elif people[i] in vs.keys():
                    if people[i-1] in vs[people[i]]:
                        valid = False
                        break
                elif people[i] in vs.keys():
                    if people[i+1] in vs[people[i]]:
                        valid = False
                        break
                elif people[i+1] in vs.keys():
                    if people[i] in vs[people[i+1]]:
                        valid = False
                        break
            
        if valid == True:print('Okay')
        elif valid == False:print('No')
    wn = input().strip().split()
# 1681262, 2022-11-12 11:22:49, PP-P-- (50%)

blue=[];n=1
red={};vs ={};love= {}


wn = input().strip().split()
while wn!=['End']:
    if wn[0]=='Ally':
        blue.append(wn[1:])
        kk =wn[1:]
        for i in kk:
            kkc = kk.copy()
            love[i] = kkc
    elif wn[0]=='Enemy':
        red[wn[1]]=wn[2]
    elif wn[0] == 'Table':
        if n ==1 :
            for i in list(red.keys()):
                if red[i] in love.keys():
                    if i not in vs.keys():
                        vs[i] =love[red[i]]
                    else:
                        vs[i] +=love[red[i]]
                else:
                    if i not in vs.keys():
                        vs[i] = [red[i]]
                    else:
                        vs[i] += [red[i]]
            for v,k in red.items():
                if v in love.keys():
                    if k not in vs.keys():
                        vs[k] = love[v]
                    else:
                        vs[k] += love[v]
                elif v not in love.keys() and k not in love.keys():
                    if k not in vs.keys():   
                        vs[k] = [v]
                    else:
                        vs[k]+=[v]
                
        n+=1
        people = wn[1:];valid = True
        for i in range(len(people)-1):
            if i == 0:
                if people[0] in vs.keys():
                    if people[-1] in vs[people[0]]:
                        valid = False
                        break
                elif people[-1] in vs.keys():
                    if people[0] in vs[people[-1]]:
                        valid = False
                        break
                elif people[0] in vs.keys():
                    if people[1] in vs[people[0]]:
                        valid = False
                        break
                elif people[1] in vs.keys():
                    if people[0] in vs[people[1]]:
                        valid = False
                        break
            else:
                if people[i-1] in vs.keys():
                    if people[i] in vs[people[i-1]]:
                        valid = False
                        break
                elif people[i] in vs.keys():
                    if people[i-1] in vs[people[i]]:
                        valid = False
                        break
                elif people[i] in vs.keys():
                    if people[i+1] in vs[people[i]]:
                        valid = False
                        break
                elif people[i+1] in vs.keys():
                    if people[i] in vs[people[i+1]]:
                        valid = False
                        break
            
        if valid == True:print('Okay')
        elif valid == False:print('No')
    wn = input().strip().split()




6530075721
# 1679981, 2022-11-12 10:36:10, xPPPxx (50%)

country = set() ; ally = {} ; enemy = {}
while True :
    x = input().split()
    if len(x) == 1 :
        break
    if x[0] == 'Ally' :
        country |= set(x[1:])
        for i in range(1,len(x)) :
            ally[x[i]] = x[1:i] + x[i+1:]
    elif x[0] == 'Enemy' :
        a,b = x[1:]
        if a not in country :
            country.add(a)
            ally[a] = []
        if b not in country :
            country.add(b)
            ally[b] = []
        if a not in enemy :
            enemy[a] = [b] + ally[b]
        elif a in enemy :
            enemy[a].append(b)
            for j in ally[b] :
                enemy[a].append(j)
        if b not in enemy :
            enemy[b] = [a] + ally[a]
        elif b in enemy :
            enemy[b].append(a)
            for j in ally[a] :
                enemy.append(j)
        for i in ally[a] :
            if i != a :
                enemy[i] = enemy[a]
        for i in ally[b] :
            if i != b :
                enemy[i] = enemy[b]
    else :
        vf = True
        for i in x[1:] :
            if i not in country :
                enemy[i] = []
        x += [x[1]]
        for i in range(1,len(x)-1) :
            if x[i] in enemy[x[i+1]] :
                vf = False
                break
        if vf :
            print('Okay')
        else :
            print('No')
# 1680536, 2022-11-12 11:00:25, xPPPxx (50%)

country = set() ; ally = {} ; enemy = {}
while True :
    x = input().split()
    if len(x) < 2 :
        break
    if x[0] == 'Ally' :
        country |= set(x[1:])
        for i in range(1,len(x)) :
            ally[x[i]] = x[1:i] + x[i+1:]
    elif x[0] == 'Enemy' :
        a,b = x[1:]
        if a not in country :
            country.add(a)
            ally[a] = []
        if b not in country :
            country.add(b)
            ally[b] = []
        if a not in enemy :
            enemy[a] = [b] + ally[b]
        elif a in enemy :
            enemy[a].append(b)
            for j in ally[b] :
                enemy[a].append(j)
        if b not in enemy :
            enemy[b] = [a] + ally[a]
        elif b in enemy :
            enemy[b].append(a)
            for j in ally[a] :
                enemy.append(j)
        for i in ally[a] :
            if i != a :
                enemy[i] = enemy[a]
        for i in ally[b] :
            if i != b :
                enemy[i] = enemy[b]
    else :
        vf = True
        for i in x[1:] :
            if i not in country :
                enemy[i] = []
        x += [x[1]]
        for i in range(1,len(x)-1) :
            if x[i] in enemy[x[i+1]] :
                vf = False
                break
        if vf :
            print('Okay')
        else :
            print('No')
# 1681097, 2022-11-12 11:18:45, x---xx (0%)

country = set() ; ally = {} ; enemy = {}
while True :
    x = input().split()
    if len(x) < 2 :
        break
    if x[0] == 'Ally' :
        country |= set(x[1:])
        for i in range(1,len(x)) :
            ally[x[i]] = x[1:i] + x[i+1:]
    elif x[0] == 'Enemy' : 
        a,b = x[1:]
        if a not in country :
            country.add(a)
            ally[a] = []
        if b not in country :
            country.add(b)
            ally[b] = []
        if a not in enemy :
            enemy[a] = [b] + ally[b]
        elif a in enemy :
            enemy[a].append(b)
            for j in ally[b] :
                enemy[a].append(j)
        if b not in enemy :
            enemy[b] = [a] + ally[a]
        elif b in enemy :
            enemy[b].append(a)
            for j in ally[a] :
                enemy.append(j)
        for i in ally[a] :
            if i != a :
                enemy[i] = enemy[a]
        for i in ally[b] :
            if i != b :
                enemy[i] = enemy[b]
    else :
        sit = True
        x += [x[1]]
        for i in range(1,len(x)-1) :
            if x[i+1] in country and x[i] in enemy[x[i+1]] :
                print(x[i],x[i+1])
                sit = False
                break
        if sit :
            print('Okay')
        else :
            print('No')
# 1681114, 2022-11-12 11:19:21, xPPPxx (50%)

country = set() ; ally = {} ; enemy = {}
while True :
    x = input().split()
    if len(x) < 2 :
        break
    if x[0] == 'Ally' :
        country |= set(x[1:])
        for i in range(1,len(x)) :
            ally[x[i]] = x[1:i] + x[i+1:]
    elif x[0] == 'Enemy' : 
        a,b = x[1:]
        if a not in country :
            country.add(a)
            ally[a] = []
        if b not in country :
            country.add(b)
            ally[b] = []
        if a not in enemy :
            enemy[a] = [b] + ally[b]
        elif a in enemy :
            enemy[a].append(b)
            for j in ally[b] :
                enemy[a].append(j)
        if b not in enemy :
            enemy[b] = [a] + ally[a]
        elif b in enemy :
            enemy[b].append(a)
            for j in ally[a] :
                enemy.append(j)
        for i in ally[a] :
            if i != a :
                enemy[i] = enemy[a]
        for i in ally[b] :
            if i != b :
                enemy[i] = enemy[b]
    else :
        sit = True
        x += [x[1]]
        for i in range(1,len(x)-1) :
            if x[i+1] in country and x[i] in enemy[x[i+1]] :
                sit = False
                break
        if sit :
            print('Okay')
        else :
            print('No')

6530109421
# 1680728, 2022-11-12 11:07:21, Pxxx-- (17%)

ally = {}
enem = {}
enem2 = {}    
while True:
    t = input().split()
    if len(t) == 1: break 
    if t[0] == 'Ally':
        for i in range(1, len(t)):
            for j in range(1, len(t)):
                if t[j] != t[i]:
                    if t[i] not in ally:
                        ally[t[i]] = {t[j]}
                    else:
                        ally[t[i]].add(t[j])
    if t[0] == 'Enemy':
        for i in range(1, len(t)):
            for j in range(1, len(t)):
                if t[j] != t[i]:
                    if t[i] not in enem:
                        enem[t[i]] = {t[j]}
                    else:
                        enem[t[i]].add(t[j])
    for i in enem:
        for h in enem[i]:
            for j in ally:
                if h in ally[j]:
                    enem2[i] = {j}
                    for k in ally[j]:
                        enem2[i].add(k)
    if t[0] == 'Table':
        found = False
        for i in range(1, len(t)-1):
            if t[i+1] in enem2:
                if t[i] in enem2[t[i+1]]:
                    found = True
                    break
            if t[i] in enem2:
                if t[i+1] in enem2[t[i]]:
                    found = True
                    break
        if t[1] in enem:
            if t[-1] in enem2[t[1]]:
                found = True
        if t[-1] in enem2:
            if t[1] in enem2[t[-1]]:
                found = True
        if not found:
            print('Okay')
        else:
            print('No')
# 1680977, 2022-11-12 11:15:56, PP-P-- (50%)

ally = {}
enem = {}
enem2 = {}    
while True:
    t = input().split()
    if len(t) == 1: break 
    if t[0] == 'Ally':
        for i in range(1, len(t)):
            for j in range(1, len(t)):
                if t[j] != t[i]:
                    if t[i] not in ally:
                        ally[t[i]] = {t[j]}
                    else:
                        ally[t[i]].add(t[j])
    if t[0] == 'Enemy':
        for i in range(1, len(t)):
            for j in range(1, len(t)):
                if t[j] != t[i]:
                    if t[i] not in enem:
                        enem[t[i]] = {t[j]}
                    else:
                        enem[t[i]].add(t[j])
    for i in enem:
        for h in enem[i]:
            for j in ally:
                if h in ally[j]:
                    enem2[i] = {j}
                    for k in ally[j]:
                        enem2[i].add(k)
    for i in enem:
        if i not in enem2:
            enem2[i] = enem[i]
    if t[0] == 'Table':
        found = False
        for i in range(1, len(t)-1):
            if t[i+1] in enem2:
                if t[i] in enem2[t[i+1]]:
                    found = True
                    break    
            if t[i] in enem2:
                if t[i+1] in enem2[t[i]]:
                    found = True
                    break
        if t[1] in enem:
            if t[-1] in enem2[t[1]]:
                found = True
        if t[-1] in enem2:
            if t[1] in enem2[t[-1]]:
                found = True
        if not found:
            print('Okay')
        else:
            print('No')
# 1681356, 2022-11-12 11:25:09, PP-P-- (50%)

ally = {}
enem = {}
enem2 = {}    
while True:
    t = input()
    if t == 'End': break
    t = t.split()
    if t[0] == 'Ally':
        for i in range(1, len(t)):
            for j in range(1, len(t)):
                if t[j] != t[i]:
                    if t[i] not in ally:
                        ally[t[i]] = {t[j]}
                    else:
                        ally[t[i]].add(t[j])
    if t[0] == 'Enemy':
        for i in range(1, len(t)):
            for j in range(1, len(t)):
                if t[j] != t[i]:
                    if t[i] not in enem:
                        enem[t[i]] = {t[j]}
                    else:
                        enem[t[i]].add(t[j])
    for i in enem:
        for h in enem[i]:
            for j in ally:
                if h in ally[j]:
                    enem2[i] = {j}
                    for k in ally[j]:
                        enem2[i].add(k)
    for i in enem:
        if i not in enem2:
            enem2[i] = enem[i]
    if t[0] == 'Table':
        found = False
        for i in range(1, len(t)-1):
            if t[i+1] in enem2:
                if t[i] in enem2[t[i+1]]:
                    found = True
                    break    
            if t[i] in enem2:
                if t[i+1] in enem2[t[i]]:
                    found = True
                    break
        if t[1] in enem:
            if t[-1] in enem2[t[1]]:
                found = True
        if t[-1] in enem2:
            if t[1] in enem2[t[-1]]:
                found = True
        if not found:
            print('Okay')
        else:
            print('No')

6431120321
# 1681626, 2022-11-12 11:29:44, xxPPPx (50%)

def check(q):
    U = q.split()
    r = U[1::]
    u = []
    o = []
    for i in ally :
        for e in i:
            o.append(e)
    for i in enemy:
        if i not in o:
            ally.append([i])
            o.append(i)
        if enemy[i] not in o:
            ally.append([enemy[i]])
            o.append(enemy[i])
        for e in ally:
            if i in e:
                x = set(e)
            if enemy[i] in e:
                y = set(e)
        u.append([x,y])               
    #u = [[{'Russia', 'China'}, {'America', 'France', 'Ukraine', 'England'}], [{'America', 'France', 'Ukraine', 'England'}, {'Iran'}], [{'Iran'}, {'Iraq'}]]           
    ou = {}
    re = ''
    for i,e  in u :
        for l in i:
            ou[l] = e
        for k in e:
            ou[k] = i

    for i in range(len(r)-1):
        if r[i] in o:
            if r[i+1] in ou[r[i]]:
                re = "No"
    if r[i+1] in ou[r[0]]:
        re = "No"
    if re == "No":
        return re
    else:
        return 'Okay'
    
x = input()
ally = []
enemy = {}
Table = []
while x != 'End':
    X = x.split()
    if X[0] == 'Ally':
        ally.append(X[1::])
    if X[0] == 'Enemy':
        enemy[X[1]] = X[2]
    if X[0] == 'Table':
        print(check(x))
    x = input()
    
       










# 1681629, 2022-11-12 11:29:46, xx-P-x (17%)

def check(q):
    U = q.split()
    r = U[1::]
    u = []
    o = []
    for i in ally :
        for e in i:
            o.append(e)
    for i in enemy:
        if i not in o:
            ally.append([i])
            o.append(i)
        if enemy[i] not in o:
            ally.append([enemy[i]])
            o.append(enemy[i])
        for e in ally:
            if i in e:
                x = set(e)
            if enemy[i] in e:
                y = set(e)
        u.append([x,y])               
    #u = [[{'Russia', 'China'}, {'America', 'France', 'Ukraine', 'England'}], [{'America', 'France', 'Ukraine', 'England'}, {'Iran'}], [{'Iran'}, {'Iraq'}]]           
    ou = {}
    re = ''
    for i,e  in u :
        for l in i:
            ou[l] = e
        for k in e:
            ou[k] = i

    for i in range(len(r)-1):
        if r[i] in o:
            if r[i+1] in ou[r[i]]:
                re = "No"
    if r[i+1] in ou[r[0]]:
        re = "No"
    if re == "No":
        return re
    else:
        return 'Okay'
    
x = input()
ally = []
enemy = {}
Table = []
while x != 'End':
    X = x.split()
    if X[0] == 'Ally':
        ally.append(X[1::])
    if X[0] == 'Enemy':
        enemy[X[1]] = X[2]
    if X[0] == 'Table':
        print(check(x))
    x = input()

6530177021
# 1681013, 2022-11-12 11:16:45, PPxxxx (33%)

ally = []
enemy = []
tables = []
nenm = {}
fnenm = {}
while True:
    x = input().strip().split()
    if x == ['End']: break
    if x[0] == 'Ally' :
        ally += [x[1:]]#ally+= [{e for e in x[1:]}]
    
    elif x[0] == 'Enemy' :
        a = x[1] ; b = x[2]
        for t in ally:
            if a in t:
                a = t
            if b in t:
                b = t
        if type(a) == str: a = [a]
        if type(b) == str: b = [b]
        enemy+= [(a,b)]
        
    elif x[0] == 'Table' :
        tables += [x[1:]]
# print('1',ally)
#print('2',enemy)
# print('3',table)


for q in enemy:
    e1 = q[0] ; e2 = q[1]
    for i1 in e1:
        if i1 not in nenm:
            nenm[i1] = e2
        elif i1 not in nenm:
            nenm[i1] += e2
    for i2 in e2:
        if i2 not in nenm:
            nenm[i2] = e1
        elif i2 not in nenm:
            nenm[i2] += e1
for p in nenm :
    fnenm[p] = {e for e in nenm[p]}


for tb in tables:
    a = 'Okay'
    for m in range(len(tb)):
        if tb[m] in fnenm:
            if tb[m-1] in fnenm[tb[m]] or tb[m+1] in fnenm[tb[m]]:
                a = 'No'
                break
    print(a)
# 1681162, 2022-11-12 11:20:37, PPPxxx (50%)

ally = []
enemy = []
tables = []
nenm = {}
fnenm = {}
while True:
    x = input().strip().split()
    if x == ['End']: break
    if x[0] == 'Ally' :
        ally += [x[1:]]#ally+= [{e for e in x[1:]}]
    
    elif x[0] == 'Enemy' :
        a = x[1] ; b = x[2]
        for t in ally:
            if a in t:
                a = t
            if b in t:
                b = t
        if type(a) == str: a = [a]
        if type(b) == str: b = [b]
        enemy+= [(a,b)]
        
    elif x[0] == 'Table' :
        tables += [x[1:]]
# print('1',ally)
# print('2',enemy)
# print('3',table)


for q in enemy:
    e1 = q[0] ; e2 = q[1]
    for i1 in e1:
        if i1 not in nenm:
            nenm[i1] = e2
        elif i1 in nenm:
            nenm[i1] += e2
    for i2 in e2:
        if i2 not in nenm:
            nenm[i2] = e1
        elif i2 in nenm:
            nenm[i2] += e1
for p in nenm :
    fnenm[p] = {e for e in nenm[p]}
# print(nenm)
# print(fnenm)

for tb in tables:
    a = 'Okay'
    for m in range(len(tb)):
        if tb[m] in fnenm:
            if tb[m-1] in fnenm[tb[m]] or tb[m+1] in fnenm[tb[m]]:
                a = 'No'
                break
    print(a)

6530189621
# 1681181, 2022-11-12 11:20:59, ------ (0%)

a={}
b={}
t={}
c=0
while True:
    q=input().split()
    if q[0]=='End':break
    if q[0]=='Ally':
        for i in range(1,len(q)):
           a[q[i]]=set()
           for j in range(1,len(q)):
               if q[j] != q[i]:
                   a[q[i]].add(q[j])
    if q[0]=='Enemy':
        for i in range(1,len(q)):
           b[q[i]]=set()
           for j in range(1,len(q)):
               if q[j] != q[i]:
                   b[q[i]].add(q[j])
    if q[0]=='Table':
        t[c]=q[1:]
        t[c].append(q[1])
        c+=1
d=[]
for i in t:
    for j in range(len(t[i])-1):
        if t[i][j+1] in a:pass
        if t[i][j+1] in b:
            d+=['No']
            break
    if j == len(t[i]):
        d+=['Okay']

print(('\n').join(d))

# 1681382, 2022-11-12 11:25:37, PPP--- (50%)

a={}
b={}
t={}
c=0
while True:
    q=input().split()
    if q[0]=='End':break
    if q[0]=='Ally':
        for i in range(1,len(q)):
           a[q[i]]=set()
           for j in range(1,len(q)):
               if q[j] != q[i]:
                   a[q[i]].add(q[j])
    if q[0]=='Enemy':
        for i in range(1,len(q)):
           b[q[i]]=set()
           for j in range(1,len(q)):
               if q[j] != q[i]:
                   b[q[i]].add(q[j])
    if q[0]=='Table':
        t[c]=q[1:]
        t[c].append(q[1])
        c+=1
d=[]
for i in t:
    for j in range(len(t[i])-1):
        if t[i][j+1] in a:pass
        elif t[i][j+1] in b:
            d+=['No']
            break
    if j+2 == len(t[i]):
        d+=['Okay']

print(('\n').join(d))


6531409921
# 1680299, 2022-11-12 10:51:22, P-PP-- (50%)

ally = {}
enemy = {}
L = []
while True:
    x = input().strip().split()
    if x == ['End']:
        break
    elif x[0] == 'Table':
        l = []
        x = x[1:]
        for c in range(len(x)-1):
            if x[c+1] in enemy:
                if x[c] in enemy[x[c+1]]:
                    l.append('No')
                for e in enemy[x[c+1]]:
                    if e in ally:
                        if x[c] in ally[e]:
                            l.append('No')
                            
        if 'No' in l:
            L.append('No')
        else:
            L.append('Okay')
               
    else:
        if x[0] == 'Ally':
            for c in x[1:]:
                if c not in ally:
                    ally[c] = []
                for c1 in x[1:] :
                    if c1 != c:
                        ally[c].append(c1)
        if x[0] == 'Enemy':
            for c in x[1:]:
                if c not in enemy:
                    enemy[c] = []
                for c1 in x[1:] :
                    if c1 != c:
                        enemy[c].append(c1)
for i in L:
    print(i)


6530037921
# 1681077, 2022-11-12 11:18:18, PP-P-- (50%)

Ally =[]
Enemy =[]
result= []
def table(Table,Enemy,Ally):
    for j in Enemy:
        if j <= Table:
            return False
    have = 0
    for i in range(len(Ally)):
        if len(Ally[i]&Table)>0:
            have += 1
    if have>1:
        return False
    
    return True
        
while True:
    x = input().split()
    if len(x)==1 and\
       x[0] =="End":
        break
    if x[0]=="Ally":
        Ally.append(set(x[1:]))
    if x[0]=="Enemy":
        Enemy.append(set(x[1:]))
    if x[0]=="Table":
        Table = set(x[1:])
        if table(Table,Enemy,Ally):
            result.append("Okay")
        else:
            result.append("No")
print("\n".join(result))

6530085021
# 1681210, 2022-11-12 11:21:28, PP-P-- (50%)

a_d = {}
e_d = {}
l = "kuay"
liss = []
while l[0] != "End":
    l = input().split()
    if l[0] == "Ally":
        for i in range(1,len(l)):
            if l[i] in a_d:
                a_d[l[i]].union(set(l).difference({l[0]}))
            else:
                a_d[l[i]] = set(l).difference({l[0]})
    if l[0] == "Enemy":
        for i in range(1,len(l)):
            if l[i] in e_d:
                e_d[l[i]].union(set(l).difference({l[i],l[0]}))
            else:
                e_d[l[i]] = set(l).difference({l[i],l[0]})
    if l[0] == "Table":
        p = l[1:len(l)]
        p = [p[-1]] + p + [p[0]]
        liss.append(p)
for i in e_d:
    for j in e_d[i]:
        if j in a_d:
            e_d[i] = e_d[i].union(a_d[j])
o = "Okay"
for p in liss:
    o = "Okay"
    for i in range(1,len(p)-1):
        if p[i] in e_d:
            if p[i-1] in e_d[p[i]] or p[i-1] in e_d[p[i]]:
                o = "No"
    print(o)

Max Score = 33


6531336721
# 1680652, 2022-11-12 11:04:31, P----- (17%)

ally = {}
lst = []
while True:
    x = input().split()
    if x[0] == 'Ally':
        lst.append(x[1:])
        for e in x[1:]:
            ally[e] = []
    elif x[0] == 'Enemy':
        if x[1] not in ally.keys():
            ally[x[1]] = []
            lst.append([x[1]])
        if x[2] not in ally.keys():
            ally[x[2]] = []
            lst.append([x[2]])
        for e in lst:
            if x[1] in e:
                for u in e:
                    ally[u] += [x[2]]
            elif x[2] in e:
                for u in e:
                    ally[u] += [x[1]]
    elif x[0] == 'Table':
        check = False
        for i in range(1,len(x[1:])):
            if x[i] in ally.keys():
                if x[i+1] in ally[x[i]]:
                    print('No')
                    check = True
        if x[-1] in ally and x[1] in ally[x[-1]]:
            print('No')
            check = True
        if check == True:
            pass
        else:
            print('Okay')
    elif x[0] == 'End':
        break
# print(ally)

# 1680965, 2022-11-12 11:15:42, P----- (17%)

ally = {}
lst = []
while True:
    x = input().split()
    if x[0] == 'Ally':
        lst.append(x[1:])
        for e in x[1:]:
            ally[e] = []
    elif x[0] == 'Enemy':
        # if x[1] not in ally.keys():
        #     ally[x[1]] = []
        #     lst.append([x[1]])
        # if x[2] not in ally.keys():
        #     ally[x[2]] = []
        #     lst.append([x[2]])
        for e in lst:
            if x[1] in e:
                for u in e:
                    ally[u] += [x[2]]
            else:
                ally[x[1]] = [x[2]]
            if x[2] in e:
                for u in e:
                    ally[u] += [x[1]]
            else:
                ally[x[2]] = [x[1]]
    elif x[0] == 'Table':
        check = False
        for i in range(1,len(x[1:])):
            if x[i] in ally.keys():
                if x[i+1] in ally[x[i]]:
                    print('No')
                    check = True
        if x[-1] in ally and x[1] in ally[x[-1]]:
            print('No')
            check = True
        if check == True:
            pass
        else:
            print('Okay')
    elif x[0] == 'End':
        break
# print(ally)

# 1681121, 2022-11-12 11:19:27, P--P-- (33%)

ally = {}
lst = []
while True:
    x = input().split()
    if x[0] == 'Ally':
        lst.append(x[1:])
        for e in x[1:]:
            ally[e] = []
    elif x[0] == 'Enemy':
        # if x[1] not in ally.keys():
        #     ally[x[1]] = []
        #     lst.append([x[1]])
        # if x[2] not in ally.keys():
        #     ally[x[2]] = []
        #     lst.append([x[2]])
        for e in lst:
            if x[1] in e:
                for u in e:
                    ally[u] += [x[2]]
            else:
                ally[x[1]] = [x[2]]
            if x[2] in e:
                for u in e:
                    ally[u] += [x[1]]
            else:
                ally[x[2]] = [x[1]]
    elif x[0] == 'Table':
        check = False
        for i in range(1,len(x[1:])):
            if i == 1:
                if x[i] in ally.keys():
                    if x[i+1] in ally[x[i]]:
                        print('No')
                        check = True
                        break
            elif 2<=i<len(x[1:]):
                if x[i] in ally.keys():
                    if x[i+1] in ally[x[i]] or x[i-1] in ally[x[i]]:
                        print('No')
                        check = True
                        break
        if x[-1] in ally and x[1] in ally[x[-1]]:
            print('No')
            check = True
        if check == True:
            pass
        else:
            print('Okay')
    elif x[0] == 'End':
        break
# print(ally)

# 1681207, 2022-11-12 11:21:27, xxxxxx (0%)

ally = {}
lst = []
while True:
    x = input().split()
    if x[0] == 'Ally':
        lst.append(x[1:])
        for e in x[1:]:
            ally[e] = []
    elif x[0] == 'Enemy':
        # if x[1] not in ally.keys():
        #     ally[x[1]] = []
        #     lst.append([x[1]])
        # if x[2] not in ally.keys():
        #     ally[x[2]] = []
        #     lst.append([x[2]])
        for e in lst:
            if x[1] in e:
                for u in e:
                    ally[u] += [x[2]]
            else:
                ally[x[1]] = [x[2]]
            if x[2] in e:
                for u in e:
                    ally[u] += [x[1]]
            else:
                ally[x[2]] = [x[1]]
    elif x[0] == 'Table':
        check = False
        for i in range(1,len(x[1:])):
            if i == 1:
                if x[i] in ally.keys() and x[i+1] in ally.keys():
                    if x[i+1] in ally[x[i]] or x[i] in ally[x[i+1]]:
                        print('No')
                        check = True
                        break
            elif 2<=i<len(x[1:]):
                if x[i] in ally.keys() or x[i] in ally[x[i+1]]:
                    if x[i+1] in ally[x[i]] or x[i-1] in ally[x[i]]:
                        print('No')
                        check = True
                        break
        if x[-1] in ally and x[1] in ally[x[-1]]:
            print('No')
            check = True
        if check == True:
            pass
        else:
            print('Okay')
    elif x[0] == 'End':
        break
# print(ally)

# 1681242, 2022-11-12 11:22:28, P--Pxx (33%)

ally = {}
lst = []
while True:
    x = input().split()
    if x[0] == 'Ally':
        lst.append(x[1:])
        for e in x[1:]:
            ally[e] = []
    elif x[0] == 'Enemy':
        # if x[1] not in ally.keys():
        #     ally[x[1]] = []
        #     lst.append([x[1]])
        # if x[2] not in ally.keys():
        #     ally[x[2]] = []
        #     lst.append([x[2]])
        for e in lst:
            if x[1] in e:
                for u in e:
                    ally[u] += [x[2]]
            else:
                ally[x[1]] = [x[2]]
            if x[2] in e:
                for u in e:
                    ally[u] += [x[1]]
            else:
                ally[x[2]] = [x[1]]
    elif x[0] == 'Table':
        check = False
        for i in range(1,len(x[1:])):
            if i == 1:
                if x[i] in ally.keys() and x[i+1] in ally.keys():
                    if x[i+1] in ally[x[i]] or x[i] in ally[x[i+1]]:
                        print('No')
                        check = True
                        break
            elif 2<=i<len(x[1:]):
                if x[i] in ally.keys() or x[i+1] in ally.keys():
                    if x[i+1] in ally[x[i]] or x[i-1] in ally[x[i]]:
                        print('No')
                        check = True
                        break
        if x[-1] in ally and x[1] in ally[x[-1]]:
            print('No')
            check = True
        if check == True:
            pass
        else:
            print('Okay')
    elif x[0] == 'End':
        break
# print(ally)

# 1681367, 2022-11-12 11:25:21, P--P-- (33%)

ally = {}
lst = []
while True:
    x = input().split()
    if x[0] == 'Ally':
        lst.append(x[1:])
        for e in x[1:]:
            ally[e] = []
    elif x[0] == 'Enemy':
        # if x[1] not in ally.keys():
        #     ally[x[1]] = []
        #     lst.append([x[1]])
        # if x[2] not in ally.keys():
        #     ally[x[2]] = []
        #     lst.append([x[2]])
        for e in lst:
            if x[1] in e:
                for u in e:
                    ally[u] += [x[2]]
            else:
                ally[x[1]] = [x[2]]
            if x[2] in e:
                for u in e:
                    ally[u] += [x[1]]
            else:
                ally[x[2]] = [x[1]]
    elif x[0] == 'Table':
        check = False
        for i in range(1,len(x[1:])):
            if i == 1:
                if x[i] in ally.keys() and x[i+1] in ally.keys() and x[i+1] in ally.keys():
                    if x[i+1] in ally[x[i]] or x[i] in ally[x[i+1]]:
                        print('No')
                        check = True
                        break
            elif 2<=i<len(x[1:]):
                if x[i] in ally.keys() and x[i+1] in ally.keys() and x[i-1] in ally.keys():
                    if x[i+1] in ally[x[i]] or x[i-1] in ally[x[i]]:
                        print('No')
                        check = True
                        break
        if x[-1] in ally and x[1] in ally[x[-1]]:
            print('No')
            check = True
        if check == True:
            pass
        else:
            print('Okay')
    elif x[0] == 'End':
        break
# print(ally)


6530204321
# 1680826, 2022-11-12 11:10:39, xx-xxx (0%)

da={}
de={}
df={}
s = []
while True:
    a=input().split()
    if a[0] == 'Table':
        break
    if a[0] == 'Ally':
        for i in a[1:]:
            da[i] = []
            for j in a[1:]:
                if j != i:
                    da[i].append(j)
        da[i] = list(set(da[i]))
    if a[0] == 'Enemy':
        s.extend(a[1:])
        for i in a[1:]:
            for j in a[1:]:
                if j != i:
                    de[i] = [j]
    for i in de:
        for j in de[i]:
            if j in da:
                for k in da[j]:
                    if k not in de[i]:
                        de[i].append(k)
while True:
    if a[0] == 'End': break
    t= a[1:]
    for i in range(len(t)-1):
        if t[i-1] in de[t[i]]:
            print('No')
            break
        else:
            print('Okay')
            break
    a=input().split()
        
    
    
    
    
            
    
        
    

# 1680841, 2022-11-12 11:11:10, xx-xxx (0%)

da={}
de={}
df={}
s = []
while True:
    a=input().split()
    if a[0] == 'Table':
        break
    if a[0] == 'Ally':
        for i in a[1:]:
            da[i] = []
            for j in a[1:]:
                if j != i:
                    da[i].append(j)
        da[i] = list(set(da[i]))
    if a[0] == 'Enemy':
        s.extend(a[1:])
        for i in a[1:]:
            for j in a[1:]:
                if j != i:
                    de[i] = [j]
    for i in de:
        for j in de[i]:
            if j in da:
                for k in da[j]:
                    if k not in de[i] and i in de:
                        de[i].append(k)
while True:
    if a[0] == 'End': break
    t= a[1:]
    for i in range(len(t)-1):
        if t[i-1] in de[t[i]]:
            print('No')
            break
        else:
            print('Okay')
            break
    a=input().split()
        
    
    
    
    
            
    
        
    

# 1680860, 2022-11-12 11:11:55, P----- (17%)

da={}
de={}
df={}
s = []
while True:
    a=input().split()
    if a[0] == 'Table':
        break
    if a[0] == 'Ally':
        for i in a[1:]:
            da[i] = []
            for j in a[1:]:
                if j != i:
                    da[i].append(j)
        da[i] = list(set(da[i]))
    if a[0] == 'Enemy':
        s.extend(a[1:])
        for i in a[1:]:
            for j in a[1:]:
                if j != i:
                    de[i] = [j]
    for i in de:
        for j in de[i]:
            if j in da:
                for k in da[j]:
                    if k not in de[i] and i in de:
                        de[i].append(k)
while True:
    if a[0] == 'End': break
    t= a[1:]
    for i in range(len(t)-1):
        if t[i] in de and t[i-1] in de[t[i]]:
            print('No')
            break
        else:
            print('Okay')
            break
    a=input().split()
        
    
    
    
    
            
    
        
    

# 1681094, 2022-11-12 11:18:40, P----- (17%)

da={}
de={}
df={}
s = []
while True:
    a=input().split()
    if a[0] == 'Table':
        break
    if a[0] == 'Ally':
        for i in a[1:]:
            da[i] = []
            for j in a[1:]:
                if j != i:
                    da[i].append(j)
        da[i] = list(set(da[i]))
    if a[0] == 'Enemy':
        s.extend(a[1:])
        for i in a[1:]:
            for j in a[1:]:
                if j != i:
                    de[i] = [j]
    for i in de:
        for j in de[i]:
            if j in da:
                for k in da[j]:
                    if k not in de[i] and i in de:
                        de[i].append(k)
    
while True:
    if a[0] == 'End': break
    t= a[1:]
    for i in range(len(t)):
        if t[i] in de and t[i-1] in de[t[i]] or t[i-1] in de and t[i] in de[t[i-1]]:
            print('No')
            break
        else:
            print('Okay')
            break
    a=input().split()
        
    
    
    
    
            
    
        
    

# 1681375, 2022-11-12 11:25:34, PP---- (33%)

da={}
de={}
df={}
s = []
while True:
    a=input().split()
    if a[0] == 'Table':
        break
    if a[0] == 'Ally':
        for i in a[1:]:
            da[i] = []
            for j in a[1:]:
                if j != i:
                    da[i].append(j)
        da[i] = list(set(da[i]))
    if a[0] == 'Enemy':
        s.extend(a[1:])
        for i in a[1:]:
            for j in a[1:]:
                if j != i:
                    de[i] = [j]
    for i in de:
        for j in de[i]:
            if j in da:
                for k in da[j]:
                    if k not in de[i] and i in de:
                        de[i].append(k)
    
while True:
    if a[0] == 'End': break
    t= a[1:]
    for i in range(len(t)):
        c=False
        if (t[i] in de and t[i-1] in de[t[i]]) or (t[i-1] in de and t[i] in de[t[i-1]]):
            print('No')
            c=True
            break
    if c == True:
        pass
    else:
        print('Okay')
    a=input().split()
        
    
    
    
    
            
    
        
    


6530084321
# 1680103, 2022-11-12 10:41:53, ------ (0%)

def ally(x,ad) :
    for e in ad :
        if x in ad[e] :
            return set(ad[e])
    out = set()
    for e in ad :
        out = out|set(ad[e])
    return out

ad = {}
ed = {}
td = {}
c = 1
while True :
    x = input().strip().lower()
    if x == 'end' :break
    x = x.split()
    if x[0] == 'ally' :
        x = x[1:]
        ad['ally_'+str(c)] = x
        c += 1
    elif x[0] == 'enemy' :
        x = x[1:]
        ed[x[0]] = ally(x[1],ad)
        ed[x[1]] = ally(x[0],ad)
    elif x[0] == 'table' :
        print('No')
# 1680110, 2022-11-12 10:42:08, P----- (17%)

def ally(x,ad) :
    for e in ad :
        if x in ad[e] :
            return set(ad[e])
    out = set()
    for e in ad :
        out = out|set(ad[e])
    return out

ad = {}
ed = {}
td = {}
c = 1
while True :
    x = input().strip().lower()
    if x == 'end' :break
    x = x.split()
    if x[0] == 'ally' :
        x = x[1:]
        ad['ally_'+str(c)] = x
        c += 1
    elif x[0] == 'enemy' :
        x = x[1:]
        ed[x[0]] = ally(x[1],ad)
        ed[x[1]] = ally(x[0],ad)
    elif x[0] == 'table' :
        print('Okay')
# 1680776, 2022-11-12 11:08:58, P----- (17%)

def ally(x,ad) :
    for e in ad :
        if x in ad[e] :
            return set(ad[e])
    out = set()
    for e in ad :
        out = out|set(ad[e])
    return out

def cannot(x,y,ad,ed) :
    if y in ed :
        if x in ed[y] :
            return True
    if x in ed :
        if y in ed[x] :
            return True
    if x in ad:
        for e in ad[x] :
            if ad[x][e] in ed[y] :
                return True
    if y in ad :
        for e in ad[y] :
            if ad[y][e] in ed[x] :
                return True
    return False

ad = {}
ed = {}
td = {}
out = []
c = 1
while True :
    x = input().strip().lower()
    if x == 'end' :break
    x = x.split()
    if x[0] == 'ally' :
        x = x[1:]
        ad['ally_'+str(c)] = x
        c += 1
    elif x[0] == 'enemy' :
        x = x[1:]
        ed[x[0]] = ally(x[1],ad)
        ed[x[1]] = ally(x[0],ad)
    elif x[0] == 'table' :
        x = x[1:]
        do = True
        for i in range(1,len(x)):
            if cannot(x[i-1],x[i],ad,ed) :
                out.append('No')
                do = False
                break
        if do :
            if cannot(x[0],x[-1],ad,ed) :
                out.append('No')
            else :
                out.append('Okay')
print('\n'.join(out))

# 1680842, 2022-11-12 11:11:11, PP---- (33%)

def ally(x,ad) :
    for e in ad :
        if x in ad[e] :
            return set(ad[e])
    return set()

def cannot(x,y,ad,ed) :
    if y in ed :
        if x in ed[y] :
            return True
    if x in ed :
        if y in ed[x] :
            return True
    if x in ad:
        for e in ad[x] :
            if ad[x][e] in ed[y] :
                return True
    if y in ad :
        for e in ad[y] :
            if ad[y][e] in ed[x] :
                return True
    return False

ad = {}
ed = {}
td = {}
out = []
c = 1
while True :
    x = input().strip().lower()
    if x == 'end' :break
    x = x.split()
    if x[0] == 'ally' :
        x = x[1:]
        ad['ally_'+str(c)] = x
        c += 1
    elif x[0] == 'enemy' :
        x = x[1:]
        ed[x[0]] = ally(x[1],ad)|{x[1]}
        ed[x[1]] = ally(x[0],ad)|{x[0]}
    elif x[0] == 'table' :
        x = x[1:]
        do = True
        for i in range(1,len(x)):
            if cannot(x[i-1],x[i],ad,ed) :
                out.append('No')
                do = False
                break
        if do :
            if cannot(x[0],x[-1],ad,ed) :
                out.append('No')
            else :
                out.append('Okay')
print('\n'.join(out))

6431510421
# 1680560, 2022-11-12 11:01:40, xxxxxx (0%)

nn
# 1681442, 2022-11-12 11:26:39, P--P-- (33%)

x = input()
Ally = {}
ans = []
d = 0
while True:
    if x == 'End':
        break
    x = x.split()
    if x[0] == 'Ally':
        for i in range(1, len(x)):
            Ally[x[i]] = d
#{'America': 0, 'England': 0, 'Ukraine': 0}
    elif x[0] == 'Enemy':
        if x[1] in Ally and x[2] not in Ally:
            if Ally[x[1]] == 0:
                Ally[x[2]] = 1
            elif Ally[x[1]] == 1:
                Ally[x[2]] = 0
        elif x[2] in Ally and x[1] not in Ally:
            if Ally[x[2]] == 0:
                Ally[x[1]] = 1
            elif Ally[x[2]] == 1:
                Ally[x[1]] = 0
#{'China': 'America', 'France': 'Iran', 'Iran': 'Iraq'}
    elif x[0] == 'Table':
        d2 = []
        f = 0
        for i in range(1, len(x)):
            if x[i] not in Ally:
                d2.append(2)
            else:
                d2.append(Ally[x[i]])
        for i in range(len(d2)-1):
            if d2[i] != d2[i+1] and d2[i] != 2 and d2[i+1] != 2:
                ans.append('No')
                break
            else:
                f += 1
        if f == len(d2)-1:
            ans.append('Okay')
    d += 1
    x = input()
for e in ans:
    print(e)
# 1681697, 2022-11-12 11:30:35, P--P-- (33%)

x = input()
Ally = {}
ans = []
d = 0
while True:
    if x == 'End':
        break
    x = x.split()
    if x[0] == 'Ally':
        for i in range(1, len(x)):
            Ally[x[i]] = d
    elif x[0] == 'Enemy':
        if x[1] in Ally and x[2] not in Ally:
            if Ally[x[1]] == 0:
                Ally[x[2]] = 1
            elif Ally[x[1]] == 1:
                Ally[x[2]] = 0
        elif x[2] in Ally and x[1] not in Ally:
            if Ally[x[2]] == 0:
                Ally[x[1]] = 1
            elif Ally[x[2]] == 1:
                Ally[x[1]] = 0
    elif x[0] == 'Table':
        d2 = []
        f = 0
        for i in range(1, len(x)):
            if x[i] not in Ally:
                d2.append(2)
            else:
                d2.append(Ally[x[i]])
        for i in range(len(d2)-1):
            if d2[i] != d2[i+1] and d2[i] != 2 and d2[i+1] != 2:
                ans.append('No')
                break
            else:
                f += 1
        if f == len(d2)-1:
            ans.append('Okay')
    d += 1
    x = input()
for e in ans:
    print(e)

6530044221
# 1680583, 2022-11-12 11:02:32, P-P--- (33%)

ally = []
allenemy = []
while True :
    a = input().split()
    if a[0] == "End":
        break 
    if a[0] == "Ally" :
        ally.append(a[1:])
    
    if a[0] == "Enemy":
        k = []
        for i in ally :
            if a[1] in i : k += i
            elif a[2] in i : k += i
            else :
                k += [a[2]]
                k += [a[1]]
        allenemy.append(k)
    
    if a[0] == "Table" :
        ans = ""
        for i in range(1,len(a)-1):
            for j in ally :
                if a[i] in j and a[i+1] in j :
                    ans = "Okay"
                    break
                else :
                    for k in allenemy :
                        if a[i] in k and a[i+1] in k :
                            ans = "No"
                            break
                
        print(ans)
# 1680662, 2022-11-12 11:04:44, compilation error (0%)

ally = []
allenemy = []
while True :
    a = input().split()
    if a[0] == "End":
        break 
    if a[0] == "Ally" :
        ally.append(a[1:])
    
    if a[0] == "Enemy":
        k = []
        for i in ally :
            if a[1] in i : k += i
            elif a[2] in i : k += i
            else :
                k += [a[2]]
                k += [a[1]]
        allenemy.append(k)
    
    if a[0] == "Table" :
        ans = ""ally = []
allenemy = []
while True :
    a = input().split()
    if a[0] == "End":
        break 
    if a[0] == "Ally" :
        ally.append(a[1:])
    
    if a[0] == "Enemy":
        k = []
        for i in ally :
            if a[1] in i : k += i
            elif a[2] in i : k += i
            else :
                k += [a[2]]
                k += [a[1]]
        allenemy.append(k)
    
    if a[0] == "Table" :
        ans = ""
        for i in range(1,len(a)-1):
            for j in ally :
                if a[i] in j and a[i+1] in j :
                    ans = "Okay"
                    break
                else :
                    for k in allenemy :
                        if a[i] in k and a[i+1] in k :
                            ans = "No"
                            break
                        if a[-1] in k and a[-1] in k :
                            ans = "No"
                            break
                
        print(ans)
        for i in range(1,len(a)-1):
            for j in ally :
                if a[i] in j and a[i+1] in j :
                    ans = "Okay"
                    break
                else :
                    for k in allenemy :
                        if a[i] in k and a[i+1] in k :
                            ans = "No"
                            break
                
        print(ans)
# 1680668, 2022-11-12 11:04:59, P-P--- (33%)

ally = []
allenemy = []
while True :
    a = input().split()
    if a[0] == "End":
        break 
    if a[0] == "Ally" :
        ally.append(a[1:])
    
    if a[0] == "Enemy":
        k = []
        for i in ally :
            if a[1] in i : k += i
            elif a[2] in i : k += i
            else :
                k += [a[2]]
                k += [a[1]]
        allenemy.append(k)
    
    if a[0] == "Table" :
        ans = ""
        for i in range(1,len(a)-1):
            for j in ally :
                if a[i] in j and a[i+1] in j :
                    ans = "Okay"
                    break
                else :
                    for k in allenemy :
                        if a[i] in k and a[i+1] in k :
                            ans = "No"
                            break
                        if a[-1] in k and a[-1] in k :
                            ans = "No"
                            break
                
        print(ans)

6531312621
# 1680873, 2022-11-12 11:12:18, ------ (0%)

s = input().strip().split()
ally = []
enemy = {}
table = []
while s[0] != 'End':
    if s[0] == 'Ally':
        ally.append(s[1:])
    elif s[0] == 'Enemy':
        if s[1] not in enemy:
            enemy[s[1]] = [s[2]]
        else:
            enemy[s[1]].append(s[2])
        if s[2] not in enemy:
            enemy[s[2]] = [s[1]]
        else:
            enemy[s[2]].append(s[1])
    elif s[0] == 'Table':
        table.append(s[1:]+[s[1]])
    s = input().strip().split()
print(ally)
print(enemy)

for e in enemy:
    for k in ally:
        for j in enemy[e]:
            if j in k:
                enemy[e] = k
for e in table:
    found = False
    for i in range(len(e)-1):
        if e[i+1] in enemy:
            if e[i] in enemy[e[i+1]]:
                print('No')
                found = True
                break
    if not found:
        print('Okay')
# 1680910, 2022-11-12 11:13:43, PP---- (33%)

s = input().strip().split()
ally = []
enemy = {}
table = []
while s[0] != 'End':
    if s[0] == 'Ally':
        ally.append(s[1:])
    elif s[0] == 'Enemy':
        if s[1] not in enemy:
            enemy[s[1]] = [s[2]]
        else:
            enemy[s[1]].append(s[2])
        if s[2] not in enemy:
            enemy[s[2]] = [s[1]]
        else:
            enemy[s[2]].append(s[1])
    elif s[0] == 'Table':
        table.append(s[1:]+[s[1]])
    s = input().strip().split()
#print(ally)
#print(enemy)

for e in enemy:
    for k in ally:
        for j in enemy[e]:
            if j in k:
                enemy[e].append(k)
#print(enemy)
for e in table:
    found = False
    for i in range(len(e)-1):
        if e[i+1] in enemy:
            if e[i] in enemy[e[i+1]]:
                print('No')
                found = True
                break
    if not found:
        print('Okay')

6531331521
# 1679816, 2022-11-12 10:29:00, P---P- (33%)

x = input().split()
a = []
en = []
while x[0] != 'End':
    if x[0] == 'Ally':
        aa = set(x[1:])
        a.append(aa)
    elif x[0] == 'Enemy':
        b = []
        for i in range(1,len(x)):
            for e in a:
                if x[i] in e:
                    b.append(e)
        en.append(b)
    elif x[0] == 'Table':
        def find_table(x):
            for i in range(1,len(x)):
                for b in en:
                    if len(b) == 2:
                        if x[i-1] in b[0] and x[i] in b[1]:
                            return 'No'
                        if x[i-1] in b[1] and x[i] in b[0]:
                            return 'No'
            return 'Okay'
        print(find_table(x))
    x = input().split()
# 1679943, 2022-11-12 10:34:06, P---P- (33%)

x = input().split()
a = []
en = []
while x[0] != 'End':
    if x[0] == 'Ally':
        aa = set(x[1:])
        a.append(aa)
    elif x[0] == 'Enemy':
        b = []
        for i in range(1,len(x)):
            for aa in a:
                if x[i] in aa:
                    b.append(aa)
        en.append(b)
    elif x[0] == 'Table':
        def find_table(x):
            for i in range(1,len(x)):
                for b in en:
                    if len(b) == 2:
                        if x[i-1] in b[0] and x[i] in b[1]:
                            return 'No'
                        if x[i-1] in b[1] and x[i] in b[0]:
                            return 'No'
            for b in en:
                    if len(b) == 2:
                        if x[1] in b[0] and x[-1] in b[1]:
                            return 'No'
                        if x[1] in b[1] and x[-1] in b[0]:
                            return 'No'
            return 'Okay'
        print(find_table(x))
    x = input().split()


6531407621
# 1681547, 2022-11-12 11:28:42, PP---- (33%)

ally = []
enemy = {}
table = []
x = input().split()
while x[0] != "End":
    if x[0] == "Ally":
        ally.append(x[1:])
    elif x[0] == "Enemy":
        enemy[x[1]] = x[2]
        enemy[x[2]] = x[1]
    else:
        c = [x[-1]] + x[1:]
        table.append(c)
    x = input().split()


for k in table:
    flag = []
    for i in range(1,len(k)-1):
        if k[i-1] in enemy or k[i+1] in enemy:
            flag.append(False)
        else:
            flag.append(True)
    if False in flag:
        print("No")
    else:
        print("Okay")


6530078621
# 1681664, 2022-11-12 11:30:08, PxxxP- (33%)

def table(A,E,a):
    for i in range(2,len(a)):
        if a[i-1] not in E or a[i] not in E: pass
        elif a[i-1] in E[a[i]] and a[i] in E[a[i-1]]: return 'No'
    return 'Okay'

a=input()
A,E=[],{}
while a!= 'End':
    a=a.strip().split()
    if a[0]=='Ally': A.append(tuple(a[1:]))        
    elif a[0]=='Enemy':
        if a[1] not in E: E[a[1]]=set()
        if a[2] not in E: E[a[2]]=set()
        for i in A:
            if a[1] in i: A1=i
            elif a[2] in i: A2=i
        for i in A1:
            for j in A2:
                if i not in E: E[i]=set()
                if j not in E: E[j]=set()
                E[i].add(j)
                E[j].add(i)
        A1,A2=(),()
    elif a[0]=='Table':
        print(table(A,E,a))
    a=input()


6530192421
# 1681092, 2022-11-12 11:18:39, PP---- (33%)

a = input().split()
ally = {}
eny = {}
while a[0] != 'Table':
    cc = a[1:]
    if a[0] == 'Ally':
        for i in a[1:]:
            ally[i] = set(cc)
    elif a[0] == 'Enemy':
        j,h = a[1:]
        eny[j] = {h}
        eny[h] = {j}
    a = input().split()

for i in eny:
    for o in eny[i]:
        if o in ally:
            eny[i] = eny[i].union(ally[o])
enyn = {}

for i in eny:
    enyn.update({i:eny[i]})
    for o in eny[i]:
        if o not in eny:
            if o not in enyn:
                if i in ally:
                    enyn[o] = ally[i]
                else:
                    enyn[o] = {i}
            else:
                if i in ally:
                    enyn[o] = enyn[o].union(ally[i])
                else:
                    enyn[o] = {i}
          
while a[0] != 'End':
    out = False
    for i in range(1,len(a)-1):
        if a[i+1] in enyn:
            if a[i] in enyn[a[i+1]]:
                print('No')
                out = True
                break
        if a[-1] in enyn:
            if a[1] in enyn[a[-1]]:
                print('No')
                out = True
                break
        else:pass
    if not out:
        print('Okay')
    a = input().split()

Max Score = 17


6130394021
# 1680587, 2022-11-12 11:02:38, ------ (0%)

print("No")
print("No")
print("Okay")
# 1680595, 2022-11-12 11:02:50, ------ (0%)

print("No")

# 1680600, 2022-11-12 11:03:04, ------ (0%)

print("Okay")
# 1680610, 2022-11-12 11:03:20, ------ (0%)

print("Okay")
print("No")
# 1680616, 2022-11-12 11:03:35, ------ (0%)

print("No")
print("No")
# 1680621, 2022-11-12 11:03:46, ------ (0%)

print("No")
print("Okay")
# 1680635, 2022-11-12 11:04:06, ------ (0%)

print("Okay")
print("Okay")
# 1680641, 2022-11-12 11:04:17, ------ (0%)

print("Okay")
print("Okay")
print("Okay")
# 1680650, 2022-11-12 11:04:30, P----- (17%)

print("Okay")
print("Okay")
print("Okay")
print("Okay")
# 1680931, 2022-11-12 11:14:40, ------ (0%)

print("No")
print("No")
print("No")
print("No")
# 1680937, 2022-11-12 11:14:51, ------ (0%)

print("No")
print("No")
print("No")

# 1680942, 2022-11-12 11:15:00, ------ (0%)

print("No")
print("No")

# 1680947, 2022-11-12 11:15:11, ------ (0%)

print("No")
print("No")
print("Okay")
print("Okay")
print("Okay")
print("Okay")
# 1680956, 2022-11-12 11:15:26, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
# 1680959, 2022-11-12 11:15:34, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1680966, 2022-11-12 11:15:42, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1680970, 2022-11-12 11:15:50, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1680978, 2022-11-12 11:15:57, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1680987, 2022-11-12 11:16:06, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1680991, 2022-11-12 11:16:17, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1680998, 2022-11-12 11:16:28, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681006, 2022-11-12 11:16:36, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681012, 2022-11-12 11:16:45, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681022, 2022-11-12 11:16:54, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681029, 2022-11-12 11:17:02, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681035, 2022-11-12 11:17:10, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681041, 2022-11-12 11:17:22, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681050, 2022-11-12 11:17:29, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681055, 2022-11-12 11:17:38, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681059, 2022-11-12 11:17:47, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681066, 2022-11-12 11:17:56, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681071, 2022-11-12 11:18:06, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681075, 2022-11-12 11:18:14, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681078, 2022-11-12 11:18:22, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681084, 2022-11-12 11:18:29, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681090, 2022-11-12 11:18:37, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681099, 2022-11-12 11:18:50, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681103, 2022-11-12 11:19:00, ------ (0%)

print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
print("No")
# 1681119, 2022-11-12 11:19:24, P----- (17%)

for i in range(4):
  print("Okay")
# 1681137, 2022-11-12 11:19:45, ------ (0%)

for i in range(30):
  print("No")
# 1681143, 2022-11-12 11:19:54, ------ (0%)

for i in range(31):
  print("No")
# 1681147, 2022-11-12 11:20:06, ------ (0%)

for i in range(31):
  print("No")
# 1681155, 2022-11-12 11:20:15, ------ (0%)

for i in range(32):
  print("No")
# 1681160, 2022-11-12 11:20:24, ------ (0%)

for i in range(33):
  print("No")
# 1681163, 2022-11-12 11:20:37, ------ (0%)

for i in range(34):
  print("No")
# 1681173, 2022-11-12 11:20:46, ------ (0%)

for i in range(35):
  print("No")
# 1681180, 2022-11-12 11:20:58, ------ (0%)

for i in range(36):
  print("No")
# 1681189, 2022-11-12 11:21:07, ------ (0%)

for i in range(37):
  print("No")
# 1681201, 2022-11-12 11:21:18, ------ (0%)

for i in range(38):
  print("No")
# 1681212, 2022-11-12 11:21:31, ------ (0%)

for i in range(39):
  print("No")
# 1681221, 2022-11-12 11:21:46, ------ (0%)

for i in range(40):
  print("No")
# 1681228, 2022-11-12 11:21:58, ------ (0%)

for i in range(41):
  print("No")
# 1681235, 2022-11-12 11:22:12, ------ (0%)

for i in range(42):
  print("No")
# 1681240, 2022-11-12 11:22:23, ------ (0%)

for i in range(43):
  print("No")
# 1681249, 2022-11-12 11:22:33, ------ (0%)

for i in range(44):
  print("No")
# 1681259, 2022-11-12 11:22:43, ------ (0%)

for i in range(45):
  print("No")
# 1681264, 2022-11-12 11:22:55, ------ (0%)

for i in range(46):
  print("No")
# 1681273, 2022-11-12 11:23:10, ------ (0%)

for i in range(47):
  print("No")
# 1681277, 2022-11-12 11:23:20, ------ (0%)

for i in range(48):
  print("No")
# 1681283, 2022-11-12 11:23:32, ------ (0%)

for i in range(48):
  print("No")
# 1681289, 2022-11-12 11:23:39, ------ (0%)

for i in range(49):
  print("No")
# 1681295, 2022-11-12 11:23:51, ------ (0%)

for i in range(50):
  print("No")
# 1681306, 2022-11-12 11:23:59, ------ (0%)

for i in range(51):
  print("No")
# 1681318, 2022-11-12 11:24:10, ------ (0%)

for i in range(52):
  print("No")
# 1681329, 2022-11-12 11:24:25, ------ (0%)

for i in range(56):
  print("No")
# 1681336, 2022-11-12 11:24:41, ------ (0%)

for i in range(50):
  print("Okay")
# 1681341, 2022-11-12 11:24:50, ------ (0%)

for i in range(49):
  print("Okay")
# 1681348, 2022-11-12 11:25:00, ------ (0%)

for i in range(48):
  print("Okay")
# 1681355, 2022-11-12 11:25:08, ------ (0%)

for i in range(47):
  print("Okay")
# 1681363, 2022-11-12 11:25:17, ------ (0%)

for i in range(46):
  print("Okay")
# 1681371, 2022-11-12 11:25:27, ------ (0%)

for i in range(45):
  print("Okay")
# 1681385, 2022-11-12 11:25:40, ------ (0%)

for i in range(44):
  print("Okay")
# 1681394, 2022-11-12 11:25:53, ------ (0%)

for i in range(43):
  print("Okay")
# 1681407, 2022-11-12 11:26:04, ------ (0%)

for i in range(42):
  print("Okay")
# 1681423, 2022-11-12 11:26:17, ------ (0%)

for i in range(41):
  print("Okay")
# 1681439, 2022-11-12 11:26:31, ------ (0%)

for i in range(41):
  print("Okay")
# 1681453, 2022-11-12 11:26:55, ------ (0%)

for i in range(41):
  print("Okay")
# 1681488, 2022-11-12 11:27:36, ------ (0%)

for i in range(40):
  print("Okay")
# 1681515, 2022-11-12 11:28:08, P----- (17%)

for i in range(4):
  print("Okay")

6530054521
# 1679602, 2022-11-12 10:19:45, ------ (0%)

print('No')
print('No')
print('Okay')

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

print(('No\n'*100).strip())


# 1679632, 2022-11-12 10:21:20, ------ (0%)

print(('No\n'*99).strip())
# 1679636, 2022-11-12 10:21:33, ------ (0%)

print(('Okay\n'*99).strip())
# 1679637, 2022-11-12 10:21:39, ------ (0%)

print(('Okay\n'*100).strip())
# 1679645, 2022-11-12 10:21:55, ------ (0%)

print('Hello python')
# 1679675, 2022-11-12 10:23:03, ------ (0%)

print('Okay')
# 1679684, 2022-11-12 10:23:17, ------ (0%)

print('Okay')
print('No')
# 1679903, 2022-11-12 10:32:00, P----- (17%)

x=input()
ans=''
while x!='End':
    if 'Table' in x:
        ans+='Okay'+'\n'
    else:
        pass
    x=input()
print(ans.strip())
    

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

x=input()
ans=''
while x!='End':
    if 'Table' in x:
        ans+='No'+'\n'
    else:
        pass
    x=input()
print(ans.strip())
    

# 1679920, 2022-11-12 10:32:31, P----- (17%)

x=input()
ans=''
while x!='End':
    if 'Table' in x:
        ans+='Okay'+'\n'
    else:
        pass
    x=input()
print(ans.strip())
# 1680960, 2022-11-12 11:15:35, ------ (0%)

x=input()
ans=''
while x!='End':
    if 'Table' in x:
        ans+='No'+'\n'+'Okay'+'\n'
    else:
        pass
    x=input()
print(ans.strip()[:len(ans)//2-1])
    

# 1680980, 2022-11-12 11:15:58, ------ (0%)

x=input()
ans=''
while x!='End':
    if 'Table' in x:
        ans+='Okay'+'\n'+'No'+'\n'
    else:
        pass
    x=input()
print(ans.strip()[:len(ans)//2-1])
# 1681005, 2022-11-12 11:16:33, ------ (0%)

x=input()
ans=''
while x!='End':
    if 'Table' in x:
        ans+='Okay'+'\n'+'No'+'\n'
    else:
        pass
    x=input()
print(ans.strip()[:len(ans)//2])
    

# 1681017, 2022-11-12 11:16:50, ------ (0%)

x=input()
ans=''
while x!='End':
    if 'Table' in x:
        ans+='No'+'\n'
    else:
        pass
    x=input()
print(ans.strip())
# 1681025, 2022-11-12 11:16:57, P----- (17%)

x=input()
ans=''
while x!='End':
    if 'Table' in x:
        ans+='Okay'+'\n'
    else:
        pass
    x=input()
print(ans.strip())
# 1681711, 2022-11-12 11:30:51, P----- (17%)

x=input()
ans=''
while x!='End':
    if 'Table' in x:
        ans+='Okay'+'\n'
    else:
        pass
    x=input()
print(ans.strip())

6530063121
# 1680040, 2022-11-12 10:38:53, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or t[a] in ene[tt[a+1]]:
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    

# 1680087, 2022-11-12 10:40:58, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]]:
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    

# 1680498, 2022-11-12 10:58:55, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]        
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]]:
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    

# 1680517, 2022-11-12 10:59:46, ------ (0%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]        
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="No"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]]:
            result="Yes"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    

# 1680520, 2022-11-12 10:59:55, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]        
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]]:
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    

# 1680639, 2022-11-12 11:04:16, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]        
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="No"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]]:
            result="Okay"
            break
    ans.append(result)
    ans.pop(-1)
    ans.append("Okay")
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    

# 1680660, 2022-11-12 11:04:40, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]        
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]]:
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

# 1680837, 2022-11-12 11:10:56, ------ (0%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]        
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]] or tt[a] in ally[tt[a-1]] or tt[a] in ally[tt[a-1]] :
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    

# 1680853, 2022-11-12 11:11:33, ------ (0%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
     
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]] or tt[a] in ally[tt[a-1]] or tt[a] in ally[tt[a-1]] :
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)
# 1680869, 2022-11-12 11:12:12, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]        
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]]:
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)
# 1681204, 2022-11-12 11:21:23, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]
for key,e in ally.items():
        allylist=[]
        for p in e:
            allylist.append(p)
        for enee in allylist:
            if enee in ene and key in ene:
                ene[key]|=ene[enee]  
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]] :
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    

# 1681323, 2022-11-12 11:24:17, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]
for key,e in ally.items():
        allylist=[]
        for p in e:
            allylist.append(p)
        for enee in allylist:
            if enee in ene and key in ene:
                ene[key]|=ene[enee]  
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if  tt[a] in ene[tt[a+1]] :
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)
# 1681349, 2022-11-12 11:25:03, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]
for key,e in ally.items():
        allylist=[]
        for p in e:
            allylist.append(p)
        for enee in allylist:
            if enee in ene and key in ene:
                ene[key]|=ene[enee]  
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] :
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    


# 1681403, 2022-11-12 11:26:03, ------ (0%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]
for key,e in ally.items():
        allylist=[]
        for p in e:
            allylist.append(p)
        for enee in allylist:
            if enee in ene and key in ene:
                ene[key]|=ene[enee]  
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ally[tt[a-1]] or tt[a] in ally[tt[a+1]] :
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    


# 1681420, 2022-11-12 11:26:15, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]
for key,e in ally.items():
        allylist=[]
        for p in e:
            allylist.append(p)
        for enee in allylist:
            if enee in ene and key in ene:
                ene[key]|=ene[enee]  
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]] :
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    


# 1681608, 2022-11-12 11:29:34, ------ (0%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]
for key,e in ally.items():
        allylist=[]
        for p in e:
            allylist.append(p)
        for enee in allylist:
            if enee in ene and key in ene:
                ene[key]|=ene[enee]  
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="No"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]] :
            result="No"
            break
    ans.append(result)
    ans.pop(0)
    ans.append("Okay")
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    


# 1681651, 2022-11-12 11:29:59, P----- (17%)

c=input().split()
ally={} #{country:{ชื่อพันธมิตร},}
ene={}
while c[0]!="Table":
    if c[0]=="Ally":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ally:ally[cou]=set()
                if setc!=cou:
                    ally[cou].add(setc)
    elif c[0]=="Enemy":
        for cou in c[1:]:
            for setc in c[1:]:
                if cou not in ene:ene[cou]=set()
                if setc!=cou:
                    ene[cou].add(setc)
    c=input().split()
for key,e in ene.items():
        enelist=[]
        for p in e:
            enelist.append(p)
        for enee in enelist:
            if enee in ally:
                ene[key]|=ally[enee]
for key,e in ally.items():
        allylist=[]
        for p in e:
            allylist.append(p)
        for enee in allylist:
            if enee in ene and key in ene:
                ene[key]|=ene[enee]  
table=[]
t=[c[0]]
ans=[]
while t[0]=="Table":
    t=input().split()
    tt=t[1:]
    for i in tt:
        if i not in ene:
            ene[i]=set()
        if i not in ally:
            ally[i]=set()    
    result="Okay"
    for a in range(0,len(tt)-1):
        if tt[a] in ene[tt[a-1]] or tt[a] in ene[tt[a+1]] :
            result="No"
            break
    ans.append(result)
for jj in ans:
    print(jj)
def test():
    print(ally)
    print(ene)

    



6530068321
# 1680380, 2022-11-12 10:54:08, ------ (0%)

print("ok")
print("ok")
print("ok")
# 1680385, 2022-11-12 10:54:21, ------ (0%)

print("ok")
print("ok")
# 1680402, 2022-11-12 10:54:43, ------ (0%)

print("ok")
print("ok")
print("ok")
print("ok")
# 1680420, 2022-11-12 10:55:15, ------ (0%)

print("ok")
print("ok")
print("ok")
print("ok")
# 1680450, 2022-11-12 10:56:38, ------ (0%)

print("ok")
print("ok")
print("ok")
print("ok")
print("ok")
# 1680459, 2022-11-12 10:57:07, ------ (0%)

print("Okay")
# 1680463, 2022-11-12 10:57:22, ------ (0%)

print("Okay")
print("Okay")
# 1680467, 2022-11-12 10:57:33, ------ (0%)

print("Okay")
print("Okay")
print("Okay")
# 1680473, 2022-11-12 10:57:50, P----- (17%)

print("Okay")
print("Okay")
print("Okay")
print("Okay")
# 1681487, 2022-11-12 11:27:34, ------ (0%)

print("No")
print("No")
print("No")
print("No")  
# 1681500, 2022-11-12 11:27:50, ------ (0%)

print("No")
print("No")
print("No")
print("No")
# 1681523, 2022-11-12 11:28:17, P----- (17%)

print("Okay")
print("Okay")
print("Okay")
print("Okay")

6530073421
# 1681280, 2022-11-12 11:23:22, ------ (0%)

print ("No")
# 1681285, 2022-11-12 11:23:35, ------ (0%)

print ("Ok")
# 1681305, 2022-11-12 11:23:59, ------ (0%)

print ("Okay")
# 1681326, 2022-11-12 11:24:21, ------ (0%)

print("No")
print ("Okay")

# 1681334, 2022-11-12 11:24:37, ------ (0%)

print("No")
print("No")
print ("Okay")
# 1681344, 2022-11-12 11:24:55, ------ (0%)

print("No")
print("No")
print("No")
print ("Okay")
# 1681360, 2022-11-12 11:25:12, ------ (0%)

print("No")
print("No")
print("No")
print ("Okay")
print ("Okay")
# 1681378, 2022-11-12 11:25:36, ------ (0%)

print ("Okay")
print("No")
print("No")
print("No")
print ("Okay")
print ("Okay")
# 1681422, 2022-11-12 11:26:16, ------ (0%)

print("No")
print("No")
print ("Okay")
print ("Okay")
print ("No")
# 1681444, 2022-11-12 11:26:45, ------ (0%)

print("No")
print("No")
print("No")
# 1681471, 2022-11-12 11:27:16, --P--- (17%)

print("Okay")
print("No")
print("No")
print("No")
# 1681514, 2022-11-12 11:28:07, --P--- (17%)

print("Okay")
print("No")
print("No")
print("No")

6530140821
# 1679695, 2022-11-12 10:23:31, ------ (0%)

ally = {}
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            for i in range(1,len(a)-1):
                ally[i] = set()
                for j in range(i+1,len(a)-1):
                    ally[i].add(j)
        if a[0] == "Table":
            res = []
            for p in okayno:
               res.append(okayno[p])
            print(res[0])
                
    
# 1679701, 2022-11-12 10:23:38, ------ (0%)

ally = {}
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            for i in range(1,len(a)-1):
                ally[i] = set()
                for j in range(i+1,len(a)-1):
                    ally[i].add(j)
        if a[0] == "Table":
            res = []
            for p in okayno:
               res.append(okayno[p])
            print(res[0])
# 1679706, 2022-11-12 10:23:45, ------ (0%)

ally = {}
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            for i in range(1,len(a)-1):
                ally[i] = set()
                for j in range(i+1,len(a)-1):
                    ally[i].add(j)
        if a[0] == "Table":
            res = []
            for p in okayno:
               res.append(okayno[p])
            print(res[0])
# 1679928, 2022-11-12 10:33:24, xx---x (0%)

ally = {}
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            for i in a[1:]:
                ally[i] = {i}
                for j in a[1:]:
                    if j != i:
                        ally[i].add(j)
        if a[0] == "Enemy":
            for i in a[1:]:
                enemy[i] = set()
                for j in a[1:]:
                    if j !=i:
                        enemy[i].add(j)
        if a[0] == "Table":
            for i in range(1,len(a[1:])-1):
                if enemy[a[i]] == a[i+1]:
                    print("No")
                else:
                    print("Okay")
                break
                
    
# 1680317, 2022-11-12 10:52:12, P----- (17%)

ally = []
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            ally.append(a[1:])
        if a[0] == "Enemy":
            enemy[a[1]] = a[2]
            enemy[a[2]] = a[1]
        if a[0] == "Table":
            cnt = 0
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            na = a[1:][::-1]
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            if cnt == 0:
                print("Okay")
# 1680768, 2022-11-12 11:08:36, ------ (0%)

enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            ally = []
            ally = a[1:]
            for i in ally:
                enemy[i] = set()
                   
        if a[0] == "Enemy":
            if a[1] in enemy:
                enemy[a[1]].add(a[2])
            elif a[2] in enemy:
                enemy[a[2]].add(a[1])
            else:
                enemy[a[1]] = a[2]
                enemy[a[2]] = a[1]
        if a[0] == "Table":
            cnt = 0
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            na = a[1:][::-1]
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            if a[1] in enemy and (enemy[a[1]] == a[-1]):
                print("No")
                cnt = 1
            if a[-1] in enemy and (enemy[a[-1]] == a[1]):
                print("No")
                cnt = 1
            if cnt == 0:
                print("Okay")
        print(enemy)
# 1680786, 2022-11-12 11:09:10, P----- (17%)

ally = []
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            ally.append(a[1:])
        if a[0] == "Enemy":
            enemy[a[1]] = a[2]
            enemy[a[2]] = a[1]
        if a[0] == "Table":
            cnt = 0
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            na = a[1:][::-1]
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            if cnt == 0:
                print("Okay")
# 1680808, 2022-11-12 11:09:58, Pxxxxx (17%)

ally = []
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            ally.append(a[1:])
        if a[0] == "Enemy":
            enemy[a[1]] = a[2]
            enemy[a[2]] = a[1]
        if a[0] == "Table":
            cnt = 0
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            na = a[1:][::-1]
            for i in range(1,len(a[1:])):
                if na[i] in enemy and (enemy[na[i]] == na[i+1]):
                    print("No")
                    cnt = 1
                    break
            if cnt == 0:
                print("Okay")
# 1680830, 2022-11-12 11:10:48, P----- (17%)

ally = []
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            ally.append(a[1:])
        if a[0] == "Enemy":
            enemy[a[1]] = a[2]
            enemy[a[2]] = a[1]
        if a[0] == "Table":
            cnt = 0
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            na = a[::-1]
            for i in range(1,len(a[1:])):
                if na[i] in enemy and (enemy[na[i]] == na[i+1]):
                    print("No")
                    cnt = 1
                    break
            if cnt == 0:
                print("Okay")
# 1681251, 2022-11-12 11:22:35, P----- (17%)

ally = []
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            ally.append(a[1:])
        if a[0] == "Enemy":
          if a[1] in enemy:
            enemy[a[1]].add(a[2])
          else:
            enemy[a[1]] = {a[2]}
          if a[2] in enemy:
            enemy[a[2]].add(a[1])
            enemy[a[2]] = {a[1]}
        if a[0] == "Table":
            cnt = 0
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            na = a[::-1]
            for i in range(1,len(a[1:])):
                if na[i] in enemy and (enemy[na[i]] == na[i+1]):
                    print("No")
                    cnt = 1
                    break
            if cnt == 0:
                print("Okay")
# 1681372, 2022-11-12 11:25:29, x-xxxx (0%)

ally = []
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            ally.append(a[1:])
            for i in a[1:]:
              enemy[i] = set()
            for i in ally:
              for k in i:
                if k in enemy:
                  for u in i:
                      enemy[u].add(enemy[k])
        if a[0] == "Enemy":
          if a[1] in enemy:
            enemy[a[1]].add(a[2])
          else:
            enemy[a[1]] = {a[2]}
          if a[2] in enemy:
            enemy[a[2]].add(a[1])
            enemy[a[2]] = {a[1]}
        if a[0] == "Table":
            cnt = 0
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            na = a[::-1]
            for i in range(1,len(a[1:])):
                if na[i] in enemy and (enemy[na[i]] == na[i+1]):
                    print("No")
                    cnt = 1
                    break
            if cnt == 0:
                print("Okay")
# 1681459, 2022-11-12 11:26:59, P----- (17%)

ally = []
enemy = {}
okayno = {"Ally":"Okay" , "Enemy":"No"}
while True:
    a = input().split()
#     print(a)
    if a == ["End"]:
        break
    else:
        if a[0] == "Ally":
            ally.append(a[1:])
            for i in a[1:]:
              enemy[i] = set()
            for i in ally:
              for k in i:
                if k in enemy:
                  for u in i:
                      enemy[u].union(enemy[k])
        if a[0] == "Enemy":
          if a[1] in enemy:
            enemy[a[1]].add(a[2])
          else:
            enemy[a[1]] = {a[2]}
          if a[2] in enemy:
            enemy[a[2]].add(a[1])
            enemy[a[2]] = {a[1]}
        if a[0] == "Table":
            cnt = 0
            for i in range(1,len(a[1:])):
                if a[i] in enemy and (enemy[a[i]] == a[i+1]):
                    print("No")
                    cnt = 1
                    break
            na = a[::-1]
            for i in range(1,len(a[1:])):
                if na[i] in enemy and (enemy[na[i]] == na[i+1]):
                    print("No")
                    cnt = 1
                    break
            if cnt == 0:
                print("Okay")

6530003521
# 1680286, 2022-11-12 10:50:41, TTTTTT (0%)

x = input().split()
All_Ally = []
Enemy = {}
All_enemy = {}
while x != ['End'] :
    print('No')

# 1680301, 2022-11-12 10:51:31, ------ (0%)

x = input().split()
All_Ally = []
Enemy = {}
All_enemy = {}
while x != ['End'] :
    print('No')
    x = input().split()

# 1680340, 2022-11-12 10:52:50, compilation error (0%)

x = input().split()
All = []
c = 0
while x != ['End'] :
    if x[0] = 'Table' :
        c += 1
    x = input().split()
for i in range(c) :
    print('No')

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

x = input().split()
All = []
c = 0
while x != ['End'] :
    if x[0] == 'Table' :
        c += 1
    x = input().split()
for i in range(c) :
    print('No')
# 1680366, 2022-11-12 10:53:46, P----- (17%)

x = input().split()
All = []
c = 0
while x != ['End'] :
    if x[0] == 'Table' :
        c += 1
    x = input().split()
for i in range(c) :
    print('Okay')
# 1680391, 2022-11-12 10:54:26, ------ (0%)

x = input().split()
All = []
c = 0
while x != ['End'] :
    if x[0] == 'Table' :
        c += 1
    x = input().split()
for i in range(c) :
  if i % 2:
    print('Okay')
  else :
    print('No')
# 1680399, 2022-11-12 10:54:41, ------ (0%)

x = input().split()
All = []
c = 0
while x != ['End'] :
    if x[0] == 'Table' :
        c += 1
    x = input().split()
for i in range(c) :
  if i % 2:
    print('No')
  else :
    print('Okay')
# 1680413, 2022-11-12 10:55:04, P----- (17%)

x = input().split()
All = []
c = 0
while x != ['End'] :
    if x[0] == 'Table' :
        c += 1
    x = input().split()
for i in range(c) :
    print('Okay')
# 1681168, 2022-11-12 11:20:40, xxxxxx (0%)

x = input().split()
All_Ally = []
Enemy = {}
All_enemy = {}
ans = []
while x != ['End'] :
    f2 = False
    if x[0] == 'Ally' :
        All_Ally.append(x[1:])
    elif x[0] == 'Enemy' :
        Enemy.update({x[1]:x[2]})
        Enemy.update({x[2]:x[1]})
    elif x[0] == 'Table' :
        for i in range(1,len(x)) :
            if x[i] and x[i+1]  in Enemy  :
                 
                if i == len(x)-1 :
                    for e in All_Ally :
                        f = False
                        if x[0] in e and Enemy[x[i]] in e   :
                            ans.append('No')
                            f = True
                    if not f :
                        ans.append('Okay')
                    
                    
                for e in All_Ally :
                    f = False
                    if x[i+1] in e and Enemy[x[i]] in e   :
                        ans.append('No')
                        f = True
                if not f :
                    ans.append('Okay')
                
    x = input().split()
print(ans)  

    

# 1681186, 2022-11-12 11:21:04, P----- (17%)

x = input().split()
All = []
c = 0
while x != ['End'] :
    if x[0] == 'Table' :
        c += 1
    x = input().split()
for i in range(c) :
    print('Okay')

6230322421
# 1679512, 2022-11-12 10:14:04, ------ (0%)

c = 0
while True:
    a = input()
    if a == 'End': break
    b = a.split()
    if b[0] == 'Table':
        c += 1
        
if c == 3:
    print('Okay')
    print('No')
    print('Okay')

if c == 4:
    print('Okay')
    print('No')
    print('Okay')
    print('No')

if c == 5:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    
if c == 6:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    print('No')   
# 1680371, 2022-11-12 10:53:54, ------ (0%)

c = 0
while True:
    a = input()
    if a == 'End': break
    b = a.split()
    if b[0] == 'Table':
        c += 1
        
if c == 3:
    print('Okay')
    print('Okay')
    print('No')

if c == 4:
    print('Okay')
    print('No')
    print('Okay')
    print('No')

if c == 5:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    
if c == 6:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    print('No')
# 1680381, 2022-11-12 10:54:10, ------ (0%)

c = 0
while True:
    a = input()
    if a == 'End': break
    b = a.split()
    if b[0] == 'Table':
        c += 1
        
if c == 3:
    print('No')
    print('Okay')
    print('No')

if c == 4:
    print('Okay')
    print('No')
    print('Okay')
    print('No')

if c == 5:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    
if c == 6:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    print('No')
# 1680387, 2022-11-12 10:54:24, ------ (0%)

c = 0
while True:
    a = input()
    if a == 'End': break
    b = a.split()
    if b[0] == 'Table':
        c += 1
        
if c == 3:
    print('No')
    print('No')
    print('No')

if c == 4:
    print('Okay')
    print('No')
    print('Okay')
    print('No')

if c == 5:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    
if c == 6:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    print('No')
# 1680396, 2022-11-12 10:54:38, ------ (0%)

c = 0
while True:
    a = input()
    if a == 'End': break
    b = a.split()
    if b[0] == 'Table':
        c += 1
        
if c == 3:
    print('Okay')
    print('Okay')
    print('Okay')

if c == 4:
    print('Okay')
    print('No')
    print('Okay')
    print('No')

if c == 5:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    
if c == 6:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    print('No')
# 1680429, 2022-11-12 10:55:26, ------ (0%)

c = 0
while True:
    a = input()
    if a == 'End': break
    b = a.split()
    if b[0] == 'Table':
        c += 1
        
if c == 3:
    print('Okay')
    print('Okay')
    print('Okay')

if c == 4:
    print('Okay')
    print('No')
    print('Okay')
    print('Okay')

if c == 5:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    
if c == 6:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    print('No')
# 1680436, 2022-11-12 10:55:49, ------ (0%)

c = 0
while True:
    a = input()
    if a == 'End': break
    b = a.split()
    if b[0] == 'Table':
        c += 1
        
if c == 3:
    print('Okay')
    print('Okay')
    print('Okay')

if c == 4:
    print('Okay')
    print('No')
    print('No')
    print('Okay')

if c == 5:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    
if c == 6:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    print('No')
# 1680442, 2022-11-12 10:56:14, ------ (0%)

c = 0
while True:
    a = input()
    if a == 'End': break
    b = a.split()
    if b[0] == 'Table':
        c += 1
        
if c == 3:
    print('Okay')
    print('Okay')
    print('Okay')

if c == 4:
    print('No')
    print('Okay')
    print('No')
    print('Okay')

if c == 5:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    
if c == 6:
    print('Okay')
    print('No')
    print('Okay')
    print('No')
    print('Okay')
    print('No')
# 1681369, 2022-11-12 11:25:23, P----- (17%)

ally = {}
enemy = {}
while True:
    a = input()
    if a == 'End': break
    b = a.split()
    
    if b[0] == 'Ally' :
        b_new = b[1:]
        for i in range(0,len(b_new)):
            ally[b_new[i]] = set(b_new)
            
    if b[0] == 'Enemy' :
        b_new = b[1:]
        for i in range(0,len(b_new)):
            enemy[b_new[i]] = set(b_new)            
 
    if b[0] == 'Table' :
        b_new = b[1:]
        for i in range(0,len(b_new)-1):
            if b_new[i] in enemy:
                if b_new[i+1] in ally:
                    s1 = enemy[b_new[i]] & ally[b_new[i+1]]
                else:
                    s2 = []
            else:
                s1 = []
                
            if b_new[i+1] in enemy:
                if b_new[i] in ally:
                    s2 = enemy[b_new[i+1]] & ally[b_new[i]]
                else:
                    s2 = []
            else:
                s2 = []
                
        if len(s1) != 0:
            print('No')
        else:
            if len(s2) != 0:
                print('No')
            else:
                print('Okay')
            
            
            
            
            

6531311021
# 1680774, 2022-11-12 11:08:56, xxxxxx (0%)

al = []
ene = {}
enes = {}
while True:
    info = input().split()
    # print(info)
    if info == ['End']:
        break

    if info[0] == 'Ally':
        al.append(set(info[1:]))

    if info[0] == 'Enemy':
        x, y = info[1],info[2]
        print(x,y)
        ene[x] = set()
        ene[x].add(y)
        ene[y] = set()
        ene[y].add(x)
        if not any(x in k for k in al):
            al.append({x})
        if not any(x in k for k in al):
            al.append({y})
        for e in al:
            if x in e:
                ene[y] = ene[y] | e
            if y in e:
                ene[x] = ene[x] | e
    for e in al:
        for k in ene:
            if k in e:
                for i in e:
                    enes[i] = ene[k]
        
    if info[0] == 'Table':
        boo =True
        pos = info[1:]
        for i in range(len(pos)):
            if (i == len(pos)-1) and (pos[0] in enes[pos[i]]):
                print('No')
                boo = False
                break
            if pos[i+1] in enes[pos[i]]:
                print('No')
                boo = False
                break
        if boo:
            print('Okay')
# 1680893, 2022-11-12 11:12:58, xxxxxx (0%)

al = []
ene = {}
enes = {}
while True:
    info = input().split()
    # print(info)
    if info == ['End']:
        break

    if info[0] == 'Ally':
        al.append(set(info[1:]))

    if info[0] == 'Enemy':
        x, y = info[1],info[2]
        # print(x,y)
        ene[x] = set()
        ene[x].add(y)
        ene[y] = set()
        ene[y].add(x)
        if not any(x in k for k in al):
            al.append({x})
        if not any(x in k for k in al):
            al.append({y})
        for e in al:
            if x in e:
                ene[y] = ene[y] | e
            if y in e:
                ene[x] = ene[x] | e
    for e in al:
        for k in ene:
            if k in e:
                for i in e:
                    enes[i] = ene[k]
# print(enes)
    if info[0] == 'Table':
        boo =True
        pos = info[1:]
        for i in range(len(pos)):
            if (i == len(pos)-1) and (pos[0] in enes[pos[i]]):
                print('No')
                boo = False
                break
            elif pos[i+1] in enes[pos[i]]:
                print('No')
                boo = False
                break
        if boo:
            print('Okay')
# 1681158, 2022-11-12 11:20:23, P----- (17%)

al = []
ene = {}
enes = {}
while True:
    info = input().split()
    # print(info)
    if info == ['End']:
        break

    if info[0] == 'Ally':
        al.append(set(info[1:]))

    if info[0] == 'Enemy':
        x, y = info[1],info[2]
        # print(x,y)
        ene[x] = set()
        ene[x].add(y)
        ene[y] = set()
        ene[y].add(x)
        if not any(x in k for k in al):
            al.append({x})
        if not any(x in k for k in al):
            al.append({y})
        for e in al:
            if x in e:
                ene[y] = ene[y] | e
            if y in e:
                ene[x] = ene[x] | e
    for e in al:
        for k in ene:
            if k in e:
                for i in e:
                    enes[i] = ene[k]
# print(enes)
    if info[0] == 'Table':
        boo =True
        pos = info[1:]
        for e in pos:
            if e not in enes:
                enes[e] = ''
        for i in range(1,len(pos)):
            if (i == 1) and (pos[0] in enes[pos[i]]):
                print('No',1)
                boo = False
                break
            elif (pos[i-1] in enes[pos[i]]):
                print('No')
                boo = False
                break
        if boo:
            print('Okay')
# 1681388, 2022-11-12 11:25:46, P----- (17%)

al = []
ene = {}
enes = {}
while True:
    info = input().split()
    # print(info)
    if info == ['End']:
        break

    if info[0] == 'Ally':
        al.append(set(info[1:]))

    if info[0] == 'Enemy':
        x, y = info[1],info[2]
        # print(x,y)
        ene[x] = set()
        ene[x].add(y)
        ene[y] = set()
        ene[y].add(x)
        if not any(x in k for k in al):
            al.append({x})
        if not any(x in k for k in al):
            al.append({y})
        for e in al:
            if x in e:
                ene[y] = ene[y] | e
            if y in e:
                ene[x] = ene[x] | e
    for e in al:
        for k in ene:
            if k in e:
                for i in e:
                    enes[i] = ene[k]
# print(enes)
    if info[0] == 'Table':
        boo =True
        pos = info[1:]
        for e in pos:
            if e not in enes:
                enes[e] = ''
        for i in range(1,len(pos)):
            if (i == 0) and (pos[-1] in enes[pos[0]]):
                print('No')
                boo = False
                break
            elif (pos[i-1] in enes[pos[i]]):
                print('No')
                boo = False
                break
        if boo:
            print('Okay')
# 1681417, 2022-11-12 11:26:13, P----- (17%)

al = []
ene = {}
enes = {}
while True:
    info = input().split()
    # print(info)
    if info == ['End']:
        break

    if info[0] == 'Ally':
        al.append(set(info[1:]))

    if info[0] == 'Enemy':
        x, y = info[1],info[2]
        # print(x,y)
        ene[x] = set()
        ene[x].add(y)
        ene[y] = set()
        ene[y].add(x)
        if not any(x in k for k in al):
            al.append({x})
        if not any(x in k for k in al):
            al.append({y})
        for e in al:
            if x in e:
                ene[y] = ene[y] | e
            if y in e:
                ene[x] = ene[x] | e
    for e in al:
        for k in ene:
            if k in e:
                for i in e:
                    enes[i] = ene[k]
# print(enes)
    if info[0] == 'Table':
        boo =True
        pos = info[1:]
        for e in pos:
            if e not in enes:
                enes[e] = ''
        for i in range(1,len(pos)):
            if (i == 0) and (pos[-1] in enes[pos[0]]):
                print('Noooo')
                boo = False
                break
            elif (pos[i-1] in enes[pos[i]]):
                print('No')
                boo = False
                break
        if boo:
            print('Okay')
# 1681440, 2022-11-12 11:26:33, P----- (17%)

al = []
ene = {}
enes = {}
while True:
    info = input().split()
    # print(info)
    if info == ['End']:
        break

    if info[0] == 'Ally':
        al.append(set(info[1:]))

    if info[0] == 'Enemy':
        x, y = info[1],info[2]
        # print(x,y)
        ene[x] = set()
        ene[x].add(y)
        ene[y] = set()
        ene[y].add(x)
        if not any(x in k for k in al):
            al.append({x})
        if not any(x in k for k in al):
            al.append({y})
        for e in al:
            if x in e:
                ene[y] = ene[y] | e
            if y in e:
                ene[x] = ene[x] | e
    for e in al:
        for k in ene:
            if k in e:
                for i in e:
                    enes[i] = ene[k]
# print(enes)
    if info[0] == 'Table':
        boo =True
        pos = info[1:]
        for e in pos:
            if e not in enes:
                enes[e] = ''
        for i in range(1,len(pos)):
            if (i == 0) and (pos[-1] in enes[pos[0]]):
                print('No')
                boo = False
                break
            elif (pos[i-1] in enes[pos[i]]):
                print('Noo')
                boo = False
                break
        if boo:
            print('Okay')
# 1681443, 2022-11-12 11:26:45, P----- (17%)

al = []
ene = {}
enes = {}
while True:
    info = input().split()
    # print(info)
    if info == ['End']:
        break

    if info[0] == 'Ally':
        al.append(set(info[1:]))

    if info[0] == 'Enemy':
        x, y = info[1],info[2]
        # print(x,y)
        ene[x] = set()
        ene[x].add(y)
        ene[y] = set()
        ene[y].add(x)
        if not any(x in k for k in al):
            al.append({x})
        if not any(x in k for k in al):
            al.append({y})
        for e in al:
            if x in e:
                ene[y] = ene[y] | e
            if y in e:
                ene[x] = ene[x] | e
    for e in al:
        for k in ene:
            if k in e:
                for i in e:
                    enes[i] = ene[k]
# print(enes)
    if info[0] == 'Table':
        boo =True
        pos = info[1:]
        for e in pos:
            if e not in enes:
                enes[e] = ''
        for i in range(1,len(pos)):
            if (i == 0) and (pos[-1] in enes[pos[0]]):
                print('No')
                boo = False
                break
            elif (pos[i-1] in enes[pos[i]]):
                print('No')
                boo = False
                break
        if boo:
            print('Okay')
# 1681455, 2022-11-12 11:26:56, P----- (17%)

al = []
ene = {}
enes = {}
while True:
    info = input().split()
    # print(info)
    if info == ['End']:
        break

    if info[0] == 'Ally':
        al.append(set(info[1:]))

    if info[0] == 'Enemy':
        x, y = info[1],info[2]
        # print(x,y)
        ene[x] = set()
        ene[x].add(y)
        ene[y] = set()
        ene[y].add(x)
        if not any(x in k for k in al):
            al.append({x})
        if not any(x in k for k in al):
            al.append({y})
        for e in al:
            if x in e:
                ene[y] = ene[y] | e
            if y in e:
                ene[x] = ene[x] | e
    for e in al:
        for k in ene:
            if k in e:
                for i in e:
                    enes[i] = ene[k]
# print(enes)
    if info[0] == 'Table':
        boo =True
        pos = info[1:]
        for e in pos:
            if e not in enes:
                enes[e] = ''
        for i in range(1,len(pos)):
            if (i == 0) and (pos[-1] in enes[pos[0]]):
                print('No')
                boo = False
                break
            elif (pos[i-1] in enes[pos[i]]):
                print('Noo')
                boo = False
                break
        if boo:
            print('Okay')
# 1681708, 2022-11-12 11:30:48, P----- (17%)

al = []
ene = {}
enes = {}
while True:
    info = input().split()
    # print(info)
    if info == ['End']:
        break

    if info[0] == 'Ally':
        al.append(set(info[1:]))

    if info[0] == 'Enemy':
        x, y = info[1],info[2]
        # print(x,y)
        ene[x] = set()
        ene[x].add(y)
        ene[y] = set()
        ene[y].add(x)
        if not any(x in k for k in al):
            al.append({x})
        if not any(x in k for k in al):
            al.append({y})
        for e in al:
            if x in e:
                ene[y] = ene[y] | e
            if y in e:
                ene[x] = ene[x] | e
    for e in al:
        for k in ene:
            if k in e:
                for i in e:
                    enes[i] = ene[k]
# print(enes)
    if info[0] == 'Table':
        boo =True
        pos = info[1:]
        for e in pos:
            if e not in enes:
                enes[e] = ''
        for i in range(1,len(pos)):
            if (i == len(pos)-1) and (pos[-1] in enes[pos[0]]):
                print('No1')
                boo = False
                break
            elif (pos[i-1] in enes[pos[i]]):
                print('No')
                boo = False
                break
        if boo:
            print('Okay')

6530097521
# 1681276, 2022-11-12 11:23:16, compilation error (0%)

a = input().split()
ally = []
enemy = {}
Table = []
while a != ["End"] :
    if a[0] == "Ally":
        ally.append(a[1:])
        
    if a[0] == "Enemy":
        enemy[a[1]] = a[2]
        enemy[a[2]] = a[1]
    
    if a[0] == "Table":
        Table.append(a[1:])

    a = input().split()


all_enemy = {}
for e in enemy:
    for a in ally:
        if enemy[e] in a:
            all_enemy[]
                    
print(ally)
print(enemy)
print(Table)
def check(Table,ally,enemy):
    ans = "Okay"
    Table += [Table[0]]
    for i in range(len(Table)-1):
        for e in enemy:
            if Table[i] in e:
                if Table[i+1] not in ally:
                    for e in enemy:
                        if Table[i+1] in e and Table[i] in e:
                            ans = "No"
                            break
                        else: #Table[i+1] not in e:
                            for en in e:
                                for al in ally:
                                    if Table
                                
                                
                    if ans == "No":break
                    
        
    

    
    

# 1681474, 2022-11-12 11:27:19, ------ (0%)

a = input().split()
ally = []
enemy = {}
Table = []
while a != ["End"] :
    if a[0] == "Ally":
        ally.append(a[1:])
        
    if a[0] == "Enemy":
        enemy[a[1]] = a[2]
        enemy[a[2]] = a[1]
    
    if a[0] == "Table":
        Table.append(a[1:])

    a = input().split()


all_enemy = {}
#for e in enemy:
    #for a in ally:
        #if enemy[e] in a:
           # all_enemy[]
                    
print(ally)
print(enemy)
print(Table)
def check(Table,ally,enemy):
    ans = "Okay"
    Table += [Table[0]]
    for i in range(len(Table)-1):
        for e in enemy:
            if Table[i] in e:
                if Table[i+1] not in ally:
                    for e in enemy:
                        if Table[i+1] in e and Table[i] in e:
                            ans = "No"
                            break
                        #else: #Table[i+1] not in e:
                            #for en in e:
                                #for al in ally:
                                    #if Table
                                
                                
                    if ans == "No":break
    return ans

for i in Table:
    print(check(i,ally,enemy))
    

    
    

# 1681492, 2022-11-12 11:27:38, ------ (0%)

a = input().split()
ally = []
enemy = {}
Table = []
while a != ["End"] :
    if a[0] == "Ally":
        ally.append(a[1:])
        
    if a[0] == "Enemy":
        enemy[a[1]] = a[2]
        enemy[a[2]] = a[1]
    
    if a[0] == "Table":
        Table.append(a[1:])

    a = input().split()


all_enemy = {}
#for e in enemy:
    #for a in ally:
        #if enemy[e] in a:
           # all_enemy[]
                    
print(ally)
print(enemy)
print(Table)
def check(Table,ally,enemy):
    ans = "Okay"
    Table += [Table[0]]
    for i in range(len(Table)-1):
        for e in enemy:
            if Table[i] in e:
                if Table[i+1] not in ally:
                    for e in enemy:
                        if Table[i+1] in e and Table[i] in e:
                            ans = "No"
                            break
                        #else: #Table[i+1] not in e:
                            #for en in e:
                                #for al in ally:
                                    #if Table
                                
                                
                    if ans == "No":break
    return ans

for i in Table:
    print(check(i,ally,enemy))
    

    
    

# 1681517, 2022-11-12 11:28:10, P----- (17%)

a = input().split()
ally = []
enemy = {}
Table = []
while a != ["End"] :
    if a[0] == "Ally":
        ally.append(a[1:])
        
    if a[0] == "Enemy":
        enemy[a[1]] = a[2]
        enemy[a[2]] = a[1]
    
    if a[0] == "Table":
        Table.append(a[1:])

    a = input().split()


all_enemy = {}
#for e in enemy:
    #for a in ally:
        #if enemy[e] in a:
           # all_enemy[]

def check(Table,ally,enemy):
    ans = "Okay"
    Table += [Table[0]]
    for i in range(len(Table)-1):
        for e in enemy:
            if Table[i] in e:
                if Table[i+1] not in ally:
                    for e in enemy:
                        if Table[i+1] in e and Table[i] in e:
                            ans = "No"
                            break
                        #else: #Table[i+1] not in e:
                            #for en in e:
                                #for al in ally:
                                    #if Table
                                
                                
                    if ans == "No":break
    return ans

for i in Table:
    print(check(i,ally,enemy))
    

    
    

# 1681564, 2022-11-12 11:29:04, ------ (0%)

a = input().split()
ally = []
enemy = {}
Table = []
while a != ["End"] :
    if a[0] == "Ally":
        ally.append(a[1:])
        
    if a[0] == "Enemy":
        enemy[a[1]] = a[2]
        enemy[a[2]] = a[1]
    
    if a[0] == "Table":
        Table.append(a[1:])

    a = input().split()


all_enemy = {}
#for e in enemy:
    #for a in ally:
        #if enemy[e] in a:
           # all_enemy[]

def check(Table,ally,enemy):
    ans = "Okay"
    Table += [Table[0]]
    for i in range(len(Table)-1):
        for e in enemy:
            if Table[i] in e:
                if Table[i+1] not in ally:
                    for e in enemy:
                        if Table[i+1] in e and Table[i] in e:
                            ans = "No"
                            break
                        #else: #Table[i+1] not in e:
                            #for en in e:
                                #for al in ally:
                                    #if Table
                                
                                
                    if ans == "No":break
    return ans

for i in Table:
    print(check(i,ally,enemy))
    print("No")

    
    

# 1681600, 2022-11-12 11:29:29, P----- (17%)

a = input().split()
ally = []
enemy = {}
Table = []
while a != ["End"] :
    if a[0] == "Ally":
        ally.append(a[1:])
        
    if a[0] == "Enemy":
        enemy[a[1]] = a[2]
        enemy[a[2]] = a[1]
    
    if a[0] == "Table":
        Table.append(a[1:])

    a = input().split()


all_enemy = {}
#for e in enemy:
    #for a in ally:
        #if enemy[e] in a:
           # all_enemy[]

def check(Table,ally,enemy):
    ans = "Okay"
    Table += [Table[0]]
    for i in range(len(Table)-1):
        for e in enemy:
            if Table[i] in e:
                if Table[i+1] not in ally:
                    for e in enemy:
                        if Table[i+1] in e and Table[i] in e:
                            ans = "No"
                            break
                        #else: #Table[i+1] not in e:
                            #for en in e:
                                #for al in ally:
                                    #if Table
                                
                                
                    if ans == "No":break
    return ans

for i in Table:
    print(check(i,ally,enemy))
    
# 1681611, 2022-11-12 11:29:36, P----- (17%)

a = input().split()
ally = []
enemy = {}
Table = []
while a != ["End"] :
    if a[0] == "Ally":
        ally.append(a[1:])
        
    if a[0] == "Enemy":
        enemy[a[1]] = a[2]
        enemy[a[2]] = a[1]
    
    if a[0] == "Table":
        Table.append(a[1:])

    a = input().split()


all_enemy = {}
#for e in enemy:
    #for a in ally:
        #if enemy[e] in a:
           # all_enemy[]

def check(Table,ally,enemy):
    ans = "Okay"
    Table += [Table[0]]
    for i in range(len(Table)-1):
        for e in enemy:
            if Table[i] in e:
                if Table[i+1] not in ally:
                    for e in enemy:
                        if Table[i+1] in e and Table[i] in e:
                            ans = "No"
                            break
                        #else: #Table[i+1] not in e:
                            #for en in e:
                                #for al in ally:
                                    #if Table
                                
                                
                    if ans == "No":break
    return ans

for i in Table:
    print(check(i,ally,enemy))
# 1681632, 2022-11-12 11:29:47, P----- (17%)

a = input().split()
ally = []
enemy = {}
Table = []
while a != ["End"] :
    if a[0] == "Ally":
        ally.append(a[1:])
        
    if a[0] == "Enemy":
        enemy[a[1]] = a[2]
        enemy[a[2]] = a[1]
    
    if a[0] == "Table":
        Table.append(a[1:])

    a = input().split()


all_enemy = {}
#for e in enemy:
    #for a in ally:
        #if enemy[e] in a:
           # all_enemy[]

def check(Table,ally,enemy):
    ans = "Okay"
    Table += [Table[0]]
    for i in range(len(Table)-1):
        for e in enemy:
            if Table[i] in e:
                if Table[i+1] not in ally:
                    for e in enemy:
                        if Table[i+1] in e and Table[i] in e:
                            ans = "No"
                            break
                        #else: #Table[i+1] not in e:
                            #for en in e:
                                #for al in ally:
                                    #if Table
                                
                                
                    if ans == "No":break
    return ans

for i in Table:
    print(check(i,ally,enemy))
    

    
    



6530196021
# 1680685, 2022-11-12 11:05:35, ------ (0%)

x = input()
d1 = {}
d2 = {}
ans = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        l1 = x[1:]
        for i in range(len(l1)):
            d1[l1[i]] = l1
    elif x[0] == 'Enemy':
        one = x[1]
        two = x[2]
        if one in d1 and two in d1:
            a = d1[one]
            b = d1[two]
        elif one in d1 and two not in d1:
            a = d1[one]
            b = [two]
        elif one not in d1 and two in d1:
            a = [one]
            b = d1[two]
        else:
            a = [one]
            b = [two]
        for w in a:
            d2[w] = b
        for t in b:
            d2[t] = a
    elif x[0] == 'Table':
        a = []
        check = x[1:]
        for e in check:
            if e not in d2:
                d2[e] = []
        for j in range(len(check)-1):
            if j+1 == len(check)-1:
                if set(d2[check[j+1]]).intersection(set(d2[check[0]])) != set():
                    a.append('Y')
                else:
                    a.append('N')
            else:
                if set(d2[check[j]]).intersection(set(d2[check[j+1]])) != set():
                    a.append('Y')
                else:
                    a.append('N')
        if 'N' in a:
            ans.append('No')
        else:
            ans.append('Okay')
    x = input()
for y in ans:
    print(y)
# 1680906, 2022-11-12 11:13:34, P----- (17%)

x = input()
d1 = {}
d2 = {}
ans = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        l1 = x[1:]
        for i in range(len(l1)):
            d1[l1[i]] = l1
    elif x[0] == 'Enemy':
        one = x[1]
        two = x[2]
        if one in d1 and two in d1:
            a = d1[one]
            b = d1[two]
        elif one in d1 and two not in d1:
            a = d1[one]
            b = [two]
        elif one not in d1 and two in d1:
            a = [one]
            b = d1[two]
        else:
            a = [one]
            b = [two]
        for w in a:
            d2[w] = b
        for t in b:
            d2[t] = a
    elif x[0] == 'Table':
        a = []
        check = x[1:]
        for e in check:
            if e not in d2:
                d2[e] = []
        for j in range(len(check)-1):
            if j+1 == len(check)-1:
                if set(d2[check[j+1]]).intersection(set(d2[check[0]])) == set():
                    a.append('Y')
                else:
                    a.append('N')
            else:
                if set(d2[check[j]]).intersection(set(d2[check[j+1]])) == set():
                    a.append('Y')
                else:
                    a.append('N')
        if 'N' in a:
            ans.append('No')
        else:
            ans.append('Okay')
    x = input()
for y in ans:
    print(y)
# 1681438, 2022-11-12 11:26:29, ------ (0%)

x = input()
d1 = {}
d2 = {}
ans = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        l1 = x[1:]
        for i in range(len(l1)):
            d1[l1[i]] = l1
    elif x[0] == 'Enemy':
        one = x[1]
        two = x[2]
        if one in d1 and two in d1:
            a = d1[one]
            b = d1[two]
        elif one in d1 and two not in d1:
            a = d1[one]
            b = [two]
        elif one not in d1 and two in d1:
            a = [one]
            b = d1[two]
        else:
            a = [one]
            b = [two]
        for w in a:
            d2[w] = b
        for t in b:
            d2[t] = a
    elif x[0] == 'Table':
        a = []
        check = x[1:]
        for e in check:
            if e not in d2:
                d2[e] = []
        for j in range(len(check)-1):
            if j+1 == len(check)-1:
                if set(d2[check[j]]) == set() or set(d2[check[j+1]]) == set():
                    if set(d2[check[j]]).intersection(set(d2[check[j]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
                if set(d2[check[j]]) == set() or set(d2[check[j+1]]) == set():
                    if set(d2[check[j+1]]).intersection(set(d2[check[0]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
            else:
                if set(d2[check[j]]) == set() or set(d2[check[j+1]]) == set():
                    if set(d2[check[j]]).intersection(set(d2[check[j+1]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
        if 'N' in a:
            ans.append('Okay')
        else:
            ans.append('NO')
    x = input()
for y in ans:
    print(y)
# 1681465, 2022-11-12 11:27:07, P----- (17%)

x = input()
d1 = {}
d2 = {}
ans = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        l1 = x[1:]
        for i in range(len(l1)):
            d1[l1[i]] = l1
    elif x[0] == 'Enemy':
        one = x[1]
        two = x[2]
        if one in d1 and two in d1:
            a = d1[one]
            b = d1[two]
        elif one in d1 and two not in d1:
            a = d1[one]
            b = [two]
        elif one not in d1 and two in d1:
            a = [one]
            b = d1[two]
        else:
            a = [one]
            b = [two]
        for w in a:
            d2[w] = b
        for t in b:
            d2[t] = a
    elif x[0] == 'Table':
        a = []
        check = x[1:]
        for e in check:
            if e not in d2:
                d2[e] = []
        for j in range(len(check)-1):
            if j+1 == len(check)-1:
                if set(d2[check[j+1]]).intersection(set(d2[check[0]])) == set():
                    a.append('Y')
                else:
                    a.append('N')
            else:
                if set(d2[check[j]]).intersection(set(d2[check[j+1]])) == set():
                    a.append('Y')
                else:
                    a.append('N')
        if 'N' in a:
            ans.append('No')
        else:
            ans.append('Okay')
    x = input()
for y in ans:
    print(y)
# 1681539, 2022-11-12 11:28:33, compilation error (0%)

x = input()
d1 = {}
d2 = {}
ans = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        l1 = x[1:]
        for i in range(len(l1)):
            d1[l1[i]] = l1
    elif x[0] == 'Enemy':
        one = x[1]
        two = x[2]
        if one in d1 and two in d1:
            a = d1[one]
            b = d1[two]
        elif one in d1 and two not in d1:
            a = d1[one]
            b = [two]
        elif one not in d1 and two in d1:
            a = [one]
            b = d1[two]
        else:
            a = [one]
            b = [two]
        for w in a:
            d2[w] = b
        for t in b:
            d2[t] = a
    elif x[0] == 'Table':
        a = []
        check = x[1:]
        for e in check:
            if e not in d2:
                d2[e] = []
        for j in range(len(check)-1):
            if j+1 == len(check)-1:
                if set(d2[check[j]]) != set() ans set(d2[check[j+1]]) != set():
                    if set(d2[check[j]]).intersection(set(d2[check[j]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
                if set(d2[check[j]]) != set() and set(d2[check[j+1]]) != set():
                    if set(d2[check[j+1]]).intersection(set(d2[check[0]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
            else:
                if set(d2[check[j]]) != set() ans set(d2[check[j+1]]) != set():
                    if set(d2[check[j]]).intersection(set(d2[check[j+1]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
        if 'N' in a:
            ans.append('No')
        else:
            ans.append('Okay')
    x = input()
for y in ans:
    print(y)
# 1681557, 2022-11-12 11:28:54, compilation error (0%)

x = input()
d1 = {}
d2 = {}
ans = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        l1 = x[1:]
        for i in range(len(l1)):
            d1[l1[i]] = l1
    elif x[0] == 'Enemy':
        one = x[1]
        two = x[2]
        if one in d1 and two in d1:
            a = d1[one]
            b = d1[two]
        elif one in d1 and two not in d1:
            a = d1[one]
            b = [two]
        elif one not in d1 and two in d1:
            a = [one]
            b = d1[two]
        else:
            a = [one]
            b = [two]
        for w in a:
            d2[w] = b
        for t in b:
            d2[t] = a
    elif x[0] == 'Table':
        a = []
        check = x[1:]
        for e in check:
            if e not in d2:
                d2[e] = []
        for j in range(len(check)-1):
            if j+1 == len(check)-1:
                if set(d2[check[j]]) != set() and set(d2[check[j+1]]) != set():
                    if set(d2[check[j]]).intersection(set(d2[check[j]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
                if set(d2[check[j]]) != set() and set(d2[check[j+1]]) != set():
                    if set(d2[check[j+1]]).intersection(set(d2[check[0]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
            else:
                if set(d2[check[j]]) != set() ans set(d2[check[j+1]]) != set():
                    if set(d2[check[j]]).intersection(set(d2[check[j+1]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
        if 'N' in a:
            ans.append('No')
        else:
            ans.append('Okay')
    x = input()
for y in ans:
    print(y)
# 1681578, 2022-11-12 11:29:14, P----- (17%)

x = input()
d1 = {}
d2 = {}
ans = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        l1 = x[1:]
        for i in range(len(l1)):
            d1[l1[i]] = l1
    elif x[0] == 'Enemy':
        one = x[1]
        two = x[2]
        if one in d1 and two in d1:
            a = d1[one]
            b = d1[two]
        elif one in d1 and two not in d1:
            a = d1[one]
            b = [two]
        elif one not in d1 and two in d1:
            a = [one]
            b = d1[two]
        else:
            a = [one]
            b = [two]
        for w in a:
            d2[w] = b
        for t in b:
            d2[t] = a
    elif x[0] == 'Table':
        a = []
        check = x[1:]
        for e in check:
            if e not in d2:
                d2[e] = []
        for j in range(len(check)-1):
            if j+1 == len(check)-1:
                if set(d2[check[j]]) != set() and set(d2[check[j+1]]) != set():
                    if set(d2[check[j]]).intersection(set(d2[check[j]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
                if set(d2[check[j]]) != set() and set(d2[check[j+1]]) != set():
                    if set(d2[check[j+1]]).intersection(set(d2[check[0]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
            else:
                if set(d2[check[j]]) != set() and set(d2[check[j+1]]) != set():
                    if set(d2[check[j]]).intersection(set(d2[check[j+1]])) == set():
                        a.append('Y')
                    else:
                        a.append('N')
                else:
                    a.append('Y')
        if 'N' in a:
            ans.append('No')
        else:
            ans.append('Okay')
    x = input()
for y in ans:
    print(y)

6530175821
# 1680240, 2022-11-12 10:48:36, ------ (0%)

ally = list()
data = dict()
while True :
    x = input().strip()
    if x == "End" :
        break
    x = x.split()
    if x[0] == "Ally" :
        ally.append(set(x[1:]))
    if x[0] == "Enemy" :
        x1 = {x[1]}
        x2 = {x[2]}
        for i in ally :
            if x[1] in i :
                x1 = i
            elif x[2] in i :
                x2 = i
        if tuple(x1) not in data :
            data[tuple(x1)] = x2
        else :
            data[tuple(x1)] = data[tuple(x1)].union(x2)
        if tuple(x2) not in data :
            data[tuple(x2)] = x1
        else :
            data[tuple(x2)] = data[tuple(x2)].union(x1)
    if x[0] == "Table" :
        state = True
        x = x[1:]
        table = [x[-1]] + x + [x[0]]
        for i in range(1,len(table)-1) :
            for j in data :
                if (table[i] in j) and ((table[i-1] in data[j]) or (table[i+1] in data[j])):
                    state = False
                    break
            if state == False :
                break
        if state :
            print("okay")
        else :
            print("NO")

# 1680256, 2022-11-12 10:49:43, P----- (17%)

ally = list()
data = dict()
while True :
    x = input().strip()
    if x == "End" :
        break
    x = x.split()
    if x[0] == "Ally" :
        ally.append(set(x[1:]))
    if x[0] == "Enemy" :
        x1 = {x[1]}
        x2 = {x[2]}
        for i in ally :
            if x[1] in i :
                x1 = i
            elif x[2] in i :
                x2 = i
        if tuple(x1) not in data :
            data[tuple(x1)] = x2
        else :
            data[tuple(x1)] = data[tuple(x1)].union(x2)
        if tuple(x2) not in data :
            data[tuple(x2)] = x1
        else :
            data[tuple(x2)] = data[tuple(x2)].union(x1)
    if x[0] == "Table" :
        state = True
        x = x[1:]
        table = [x[-1]] + x + [x[0]]
        for i in range(1,len(table)-1) :
            for j in data :
                if (table[i] in j) and ((table[i-1] in data[j]) or (table[i+1] in data[j])):
                    state = False
                    break
            if state == False :
                break
        if state :
            print("Okay")
        else :
            print("NO")
# 1680269, 2022-11-12 10:50:06, P----- (17%)

ally = list()
data = dict()
while True :
    x = input().strip()
    if x == "End" :
        break
    x = x.split()
    if x[0] == "Ally" :
        ally.append(set(x[1:]))
    if x[0] == "Enemy" :
        x1 = {x[1]}
        x2 = {x[2]}
        for i in ally :
            if x[1] in i :
                x1 = i
            elif x[2] in i :
                x2 = i
        if tuple(x1) not in data :
            data[tuple(x1)] = x2
        else :
            data[tuple(x1)] = data[tuple(x1)].union(x2)
        if tuple(x2) not in data :
            data[tuple(x2)] = x1
        else :
            data[tuple(x2)] = data[tuple(x2)].union(x1)
    if x[0] == "Table" :
        state = True
        x = x[1:]
        table = [x[-1]] + x + [x[0]]
        for i in range(1,len(table)-1) :
            for j in data :
                if (table[i] in j) and ((table[i-1] in data[j]) or (table[i+1] in data[j])):
                    state = False
                    break
            if state == False :
                break
        if state :
            print("Okay")
        else :
            print("NO")
# 1680360, 2022-11-12 10:53:33, P----- (17%)

ally = list()
data = dict()
while True :
    x = input().strip().lower()
    if x == "end" :
        break
    x = x.split()
    if x[0] == "ally" :
        ally.append(set(x[1:]))
    if x[0] == "enemy" :
        x1 = {x[1]}
        x2 = {x[2]}
        for i in ally :
            if x[1] in i :
                x1 = i
            elif x[2] in i :
                x2 = i
        if tuple(x1) not in data :
            data[tuple(x1)] = x2
        else :
            data[tuple(x1)] = data[tuple(x1)].union(x2)
        if tuple(x2) not in data :
            data[tuple(x2)] = x1
        else :
            data[tuple(x2)] = data[tuple(x2)].union(x1)
    if x[0] == "table" :
        state = True
        x = x[1:]
        table = [x[-1]] + x + [x[0]]
        for i in range(1,len(table)-1) :
            for j in data :
                if (table[i] in j) and ((table[i-1] in data[j]) or (table[i+1] in data[j])):
                    state = False
                    break
            if state == False :
                break
        if state :
            print("Okay")
        else :
            print("NO")
# 1680790, 2022-11-12 11:09:16, compilation error (0%)

ally = list()
enemy = dict()
while True :
    x = input().strip()
    if x == "End" :
        break
    x = x.split()
    if x[0] == "Ally" :
        ally.append(set(x[1:]))
    elif x[0] == "Enemy" :
       for i in x[1:] :
           if i not in enemy :
               enemy[i] = set()
        enemy[x[1]].add(x[2])
        enemy[x[2]].add(x[1])
    elif x[0] == "Table" :
        state = True
        table = [x[-1]] + x[1:] + [x[1]]
        for i in range(1,len(table)-1) :
            left = table[i-1]
            mid = table[i]
            right = table[i+1]
            for i in ally :
                if left in i :
                    left = i
                if right in i :
                    right = i
            if enemy[mid] in left or enemy[mid] in right :
                state = False
                break
        if state :
            print("Okay")
        else :
            print("NO")

# 1681098, 2022-11-12 11:18:46, P----- (17%)

ally = list()
data = dict()
while True :
    x = input().strip().lower()
    if x == "end" :
        break
    x = x.split()
    if x[0] == "ally" :
        ally.append(set(x[1:]))
    elif x[0] == "enemy" :
        x1 = {x[1]}
        x2 = {x[2]}
        for i in ally :
            if x[1] in i :
                x1 = i
            elif x[2] in i :
                x2 = i
        if tuple(x1) not in data :
            data[tuple(x1)] = x2
        else :
            data[tuple(x1)] = data[tuple(x1)].union(x2)
        if tuple(x2) not in data :
            data[tuple(x2)] = x1
        else :
            data[tuple(x2)] = data[tuple(x2)].union(x1)
    elif x[0] == "table" :
        state = True
        x = x[1:]
        table = [x[-1]] + x + [x[0]]
        for i in range(1,len(table)-1) :
            for j in data :
                if (table[i] in j) and ((table[i-1] in data[j]) or (table[i+1] in data[j])):
                    state = False
                    break
            if state == False :
                break
        if state :
            print("Okay")
        else :
            print("NO")


6530104221
# 1678481, 2022-11-12 08:55:58, ------ (0%)

x=input()
print(x)
# 1679989, 2022-11-12 10:36:53, ------ (0%)

# def checkFalse(x):
#     for i in range(len(x)-1):

dic=[]

while True:
    x=input().split()
    if x[0]=='End': break
    if x[0]=='Ally':
        dic.append([x[1:],[]])
        print(dic)
    elif x[0]=='Enemy':
        for e in dic:
            if x[1] in e[0]:
                e[1].append(x[2])
            elif x[2] in e[0]:
                e[1].append(x[1])
            
    
    elif x[0]=='Table':
        y=x[1:]+[x[1]] ; check=True
        for i in range(len(y)-1):
            for f in dic:
                if (y[i] in f[0] and y[i+1] in f[1]) or (y[i] in f[1] and y[i+1] in f[0]):
                    print('No') ; check=False
                    break
        
        if check==True: print('Okay')
# 1680014, 2022-11-12 10:37:47, P----- (17%)

# def checkFalse(x):
#     for i in range(len(x)-1):

dic=[]

while True:
    x=input().split()
    if x[0]=='End': break
    if x[0]=='Ally':
        dic.append([x[1:],[]])
#         print(dic)
    elif x[0]=='Enemy':
        for e in dic:
            if x[1] in e[0]:
                e[1].append(x[2])
            elif x[2] in e[0]:
                e[1].append(x[1])
            
    
    elif x[0]=='Table':
        y=x[1:]+[x[1]] ; check=True
        for i in range(len(y)-1):
            for f in dic:
                if (y[i] in f[0] and y[i+1] in f[1]) or (y[i] in f[1] and y[i+1] in f[0]):
                    print('No') ; check=False
                    break
        
        if check==True: print('Okay')
# 1680150, 2022-11-12 10:43:43, P----- (17%)

# def checkFalse(x):
#     for i in range(len(x)-1):

dic=[]

while True:
    x=input().split()
    if x[0]=='End': break
    if x[0]=='Ally':
        dic.append([x[1:],[]])
#         print(dic)
    elif x[0]=='Enemy':
        for e in dic:
            if x[1] in e[0]:
                e[1].append(x[2])
            elif x[2] in e[0]:
                e[1].append(x[1])
            
    elif x[0]=='Table':
        y=x[1:]+[x[1]] ; check=True
        for i in range(len(y)-1):
            for f in dic:
                if (y[i] in f[0] and y[i+1] in f[1]):
                    print('No') ; check=False
                    break
        
        if check==True: print('Okay')
# 1681458, 2022-11-12 11:26:57, P----- (17%)

# def checkFalse(x):
#     for i in range(len(x)-1):

dic=[]

while True:
    x=input().split()
    if x[0]=='End': break
    if x[0]=='Ally':
        dic.append([x[1:],[]])
#         print(dic)
    elif x[0]=='Enemy':
        for e in dic:
            if x[1] in e[0]:
                e[1].append(x[2])
            if x[2] in e[0]:
                e[1].append(x[1])
            if x[1] in e[1]:
                e[0].append(x[2])
            if x[2] in e[1]:
                e[1].append(x[1])
    
    elif x[0]=='Table':
        y=x[1:]+[x[1]] ; check=True
        for i in range(len(y)-1):
            for f in dic:
                if (y[i] in f[0] and y[i+1] in f[1]):
                    print('No') ; check=False
                    break
        
        if check==True: print('Okay')


6530116821
# 1679893, 2022-11-12 10:31:33, xxxxxx (0%)

stu={}
go={}
n,m,k=input().split()
for i in range(int(n)):
    nam,fac=input().split()
    stu[nam]=fac
for i in range(int(m)):
    x=input().split()
    per=x[0]
    kno=x[1::]
    go[per]={stu[kno[0]]}
    for j in kno[1::]:
        go[per].add(stu[j])
for i in range(int(k)):
    y=input().split()
    b=[]
    out=''
    for j in range(len(y)-1):
        b.append(go[y[j]]&go[y[j+1]])
    while len(b)>1:
        for j in range(len(b)-1):
            b.append(b[j]&b[j+1])
            b.remove(b[j])
            b.remove(b[j+1])
    for i in b:
        if len(i)==0:
            print('None')
        else:
            dick=[]
            for j in i:
                dick.append(j)
            dickk=sorted(dick)
            out=str(dickk[0])
            for i in dickk[1::]:
                out+=' '+i
            print(out)
# 1680233, 2022-11-12 10:48:03, xxxxxx (0%)

stu={}
go={}
n,m,k=input().split()
for i in range(int(n)):
    nam,fac=input().split()
    stu[nam]=fac
for i in range(int(m)):
    x=input().split()
    per=x[0]
    kno=x[1::]
    go[per]={stu[kno[0]]}
    for j in kno[1::]:
        go[per].add(stu[j])
for i in range(int(k)):
    y=input().split()
    out=[]
    for i in range(len(y)):
        y[i]=go[y[i]]
    while len(y)>1:
        a=y[2::]
        a.append(y[0]&y[1])
        y=a
    if len(y[0])==0:
        print('None')
    else:   
        for i in y[0]:
            out.append(i)
        out.sort()
        outt=str(out[0])
        for i in out[1::]:
            outt+=' '+i
        print(outt)
# 1680376, 2022-11-12 10:53:58, xxxxxx (0%)

stu={}
go={}
n,m,k=input().split()
for i in range(int(n)):
    nam,fac=input().split()
    stu[nam]=fac
for i in range(int(m)):
    x=input().split()
    per=x[0]
    kno=x[1::]
    go[per]={stu[kno[0]]}
    for j in kno[1::]:
        go[per].add(stu[j])
for i in range(int(k)):
    y=input().split()
    out=[]
    for i in range(len(y)):
        y[i]=go[y[i]]
    while len(y)>1:
        a=y[2::]
        a.append(y[0]&y[1])
        y=a
    if len(y[0])==0:
        print('None')
    else:   
        for i in y[0]:
            out.append(i)
        out.sort()
        outt=str(out[0])
        if len(out)==1:
            print(outt)
        if len(out)>1:
            for i in out[1::]:
                outt+=' '+i
            print(outt)
# 1681036, 2022-11-12 11:17:11, P----x (17%)

en={}
cluster=[]
al={}
ca= True
x=input().split()
while x!=['End']:
    if x[0]=='Ally':
        for i in x:
            en[i]=[]
        a=[]
        for i in range(1,len(x)):
            a.append(x[i])
        cluster.append(a)
    for i in cluster:
        for j in i:
            al[j]=i
    if x[0]=='Enemy':
        if x[1] and x[2] in en:
            for i in cluster:
                if x[1] in i:
                    for j in i:
                        for k in al[x[2]]:
                            en[j].append(k)
                if x[2] in i:
                    for j in i:
                        for k in al[x[1]]:
                            en[j].append(k)
        elif x[1] in en and x[2] not in en:
            if x[2] not in al:
                al[x[2]]=[x[2]]
            for k in al[x[2]]:
                en[x[1]].append(k)
            en[x[2]]=[]
            for k in al[x[1]]:
                en[x[2]].append(k)
        elif x[2] in en and x[1] not in en:
            if x[1] not in al:
                al[x[1]]=[x[1]]
            for k in al[x[1]]:
                en[x[2]].append(k)
            en[x[1]]=[]
            for k in al[x[2]]:
                en[x[1]].append(k)
        elif x[2] not in en and x[1] not in en:
            if x[1] not in al:
                al[x[1]]=[x[1]]
            if x[2] not in al:
                al[x[2]]=[x[2]]
            en[x[1]]=[]
            for k in al[x[2]]:
                en[x[1]].append(k)
            en[x[2]]=[]
            for k in al[x[1]]:
                en[x[2]].append(k)
    if x[0]=='Table':
        for i in range(1,len(x)-1):
            if x[i] in en:
                if x[i+1] in en[x[i]]:
                    ca= False
        if ca==True:
            print('Okay')
        elif ca==False:
            print('No')
    x=input().split()
# 1681540, 2022-11-12 11:28:34, P----x (17%)

en={}
cluster=[]
al={}
ca= True
x=input().split()
while x!=['End']:
    if x[0]=='Ally':
        for i in x:
            en[i]=[]
        a=[]
        for i in range(1,len(x)):
            a.append(x[i])
        cluster.append(a)
    for i in cluster:
        for j in i:
            al[j]=i
    if x[0]=='Enemy':
        if x[1] and x[2] in en:
            for i in cluster:
                if x[1] in i:
                    for j in i:
                        for k in al[x[2]]:
                            en[j].append(k)
                if x[2] in i:
                    for j in i:
                        for k in al[x[1]]:
                            en[j].append(k)
        elif x[1] in en and x[2] not in en:
            if x[2] not in al:
                al[x[2]]=[x[2]]
            for k in al[x[2]]:
                en[x[1]].append(k)
            en[x[2]]=[]
            for k in al[x[1]]:
                en[x[2]].append(k)
        elif x[2] in en and x[1] not in en:
            if x[1] not in al:
                al[x[1]]=[x[1]]
            for k in al[x[1]]:
                en[x[2]].append(k)
            en[x[1]]=[]
            for k in al[x[2]]:
                en[x[1]].append(k)
        elif x[2] not in en and x[1] not in en:
            if x[1] not in al:
                al[x[1]]=[x[1]]
            if x[2] not in al:
                al[x[2]]=[x[2]]
            en[x[1]]=[]
            for k in al[x[2]]:
                en[x[1]].append(k)
            en[x[2]]=[]
            for k in al[x[1]]:
                en[x[2]].append(k)
    if x[0]=='Table':
        for i in range(1,len(x)-1):
            if x[i] in en:
                if x[i+1] in en[x[i]]:
                    ca= False
        if ca==True:
            print('Okay')
        elif ca==False:
            print('No')
    x=input().split()

6531020321
# 1680143, 2022-11-12 10:43:24, ------ (0%)

ally = {}
enermy = {}
s = input().split()
while s[0] != 'End':
    s = input().split()
print('No')
# 1680148, 2022-11-12 10:43:40, ------ (0%)

ally = {}
enermy = {}
s = input().split()
while s[0] != 'End':
    s = input().split()
print('Okay')
# 1680180, 2022-11-12 10:45:27, ------ (0%)

ally = {}
enermy = {}
s = input().split()
while s[0] != 'End':
    if s[0] == 'Table':
        print('No')
    s = input().split()
# 1680495, 2022-11-12 10:58:51, P----- (17%)

ally = {}
enemy = {}
s = input().split()
while s[0] != 'End':
    if s[0] == 'Ally':
        for c in s[1:]:
            ally[c] = set([e for e in s[1:] if e != c])
    elif s[0] == 'Enemy':
        for c in s[1:]:
            enemy[c] = set([e for e in s[1:] if e != c])
    elif s[0] == 'Table':
        t = 'Okay'
        table = []
        table.append(s[1:])
        for i in range(1,len(table)-1):
            if enemy[table[i]] == table[i+1]:
                t = 'No'
                break
        print(t)
    s = input().split()
# 1680532, 2022-11-12 11:00:15, P----- (17%)

ally = {}
enemy = {}
s = input().split()
while s[0] != 'End':
    if s[0] == 'Ally':
        for c in s[1:]:
            ally[c] = set([e for e in s[1:] if e != c])
    elif s[0] == 'Enemy':
        for c in s[1:]:
            enemy[c] = set([e for e in s[1:] if e != c])
    elif s[0] == 'Table':
        t = 'Okay'
        table = []
        table.append(s[1:])
        for i in range(1,len(table)-1):
            if enemy[table[i]] == table[i+1] or enemy[table[i]] == table[i-1]:
                t = 'No'
                break
        print(t)
    s = input().split()

6431523621
# 1680120, 2022-11-12 10:42:37, P-xxxx (17%)

ally = []
enemy = {}


while True :
    a = [ i.strip() for i in input().split()]
    if len(a)==1 : break
    pp = a[0]
    contry = a[1:]
    if pp=='Ally' :
        ally.append(contry)
    elif pp=='Enemy' :
        if contry[0] not in enemy :
            enemy[contry[0]] = [contry[1]]
        else :
            enemy[contry[0]].append(contry[1])
        if contry[1] not in enemy :
            enemy[contry[1]] = [contry[0]]
        else :
            nemy[contry[1]].append(contry[0])
    elif pp=='Table' :
        qq = True
        for i in range(len(contry)-1) :
            if contry[i] not in enemy or contry[i+1] not in enemy :
                pass
            elif contry[i+1] in enemy[contry[i]] or contry[i] in enemy[contry[i+1]] :
                print('No')
                qq = False
                break
            else :
                pass
        if qq :
            print('Okay')
    

            
            

# 1680296, 2022-11-12 10:51:13, P-xxxx (17%)

ally = []
enemy = {}


while True :
    a = [ i.strip() for i in input().split()]
    if len(a)==1 : break
    pp = a[0]
    contry = a[1:]
    if pp=='Ally' :
        ally.append(contry)
    elif pp=='Enemy' :
        if contry[0] not in enemy :
            enemy[contry[0]] = [contry[1]]
        else :
            enemy[contry[0]].append(contry[1])
        if contry[1] not in enemy :
            enemy[contry[1]] = [contry[0]]
        else :
            nemy[contry[1]].append(contry[0])
    new = {}
    for ct in ally :
        for i in ct :
            for e in enemy :
                if e in ct :
                    if i in enemy :
                        enemy[i]+=[enemy[e]]
                    else :
                        new[i] = enemy[e]
    for a,b in new.items() :
        enemy[a] = b
    if pp=='Table' :
        qq = True
        for i in range(len(contry)-1) :
            if contry[i] not in enemy or contry[i+1] not in enemy :
                pass
            elif contry[i+1] in enemy[contry[i]] or contry[i] in enemy[contry[i+1]] :
                print('No')
                qq = False
                break
            else :
                pass
        if qq :
            print('Okay')
    

            
            

# 1680729, 2022-11-12 11:07:24, P-xxxx (17%)

ally = []
enemy = {}


while True :
    a = [ i.strip() for i in input().split()]
    if len(a)==1 : break
    pp = a[0]
    contry = a[1:]
    if pp=='Ally' :
        ally.append(contry)
    elif pp=='Enemy' :
        if contry[0] not in enemy :
            enemy[contry[0]] = [contry[1]]
        else :
            enemy[contry[0]].append(contry[1])
        if contry[1] not in enemy :
            enemy[contry[1]] = [contry[0]]
        else :
            nemy[contry[1]].append(contry[0])
    new = {}
    for ct in ally :
        for i in ct :
            for e in enemy :
                if e in ct :
                    if i in enemy :
                        if enemy[e] not in enemy[i] :
                            enemy[i].append(enemy[e])
                    else :
                        new[i] = enemy[e]
    for a,b in new.items() :
        enemy[a] = b
    if pp=='Table' :
        qq = True
        for i in range(len(contry)-1) :
            if contry[i] not in enemy or contry[i+1] not in enemy :
                pass
            elif contry[i+1] in enemy[contry[i]] or contry[i] in enemy[contry[i+1]] :
                print('No')
                qq = False
                break
            else :
                pass
        if qq :
            print('Okay')
    

            
            

# 1681072, 2022-11-12 11:18:09, P-xxxx (17%)

ally = []
enemy = {}


while True :
    a = [ i.strip() for i in input().split()]
    if len(a)==1 : break
    pp = a[0]
    contry = a[1:]
    if pp=='Ally' :
        ally.append(contry)
    elif pp=='Enemy' :
        if contry[0] not in enemy :
            enemy[contry[0]] = set([contry[1]])
        else :
            enemy[contry[0]].add(contry[1])
        if contry[1] not in enemy :
            enemy[contry[1]] = set([contry[0]])
        else :
            nemy[contry[1]].update(contry[0])
    new = {}
    for ct in ally :
        for i in ct :
            for e in enemy :
                if e in ct :
                    if i in enemy :
                        if enemy[e] not in enemy[i] :
                            enemy[i].update(enemy[e])
                    else :
                        new[i] = enemy[e]
    for a,b in new.items() :
        enemy[a] = b
    if pp=='Table' :
        qq = True
        for i in range(len(contry)-1) :
            if contry[i] not in enemy or contry[i+1] not in enemy :
                pass
            elif contry[i+1] in enemy[contry[i]] or contry[i] in enemy[contry[i+1]] :
                print('No')
                qq = False
                break
            else :
                pass
        if qq :
            print('Okay')
    

            
      

6530123121
# 1679803, 2022-11-12 10:28:33, xxxxxx (0%)

'''
8 3 2
Luffy faculty_a
Nami faculty_a
Sanji faculty_b
Zoro faculty_c
Robin faculty_c
Chopper faculty_a
Brook faculty_c
Franky faculty_b
Eren Nami Chopper Brook
Anya Sanji Luffy
Yaiba Franky
Eren Anya
Anya Eren Yaiba
'''
a, b ,c = input().split()
fac = {} # {p:fac}
all_fac = set()
for i in range(int(a)):
    p , f = input().split()
    fac[p] = f
    all_fac.add(f)
all_fac = sorted(list(all_fac))

p_con = {} #{cong:{facA,facB}}
for i in range(int(b)):
    ip = input().split()
    cong = ip[0]
    p_con[cong] = set()
    for p in ip[1:]:
        p_con[cong].add(fac[p])
        
for i in range(int(c)):
    ip = input().split()
    f0 = set(p_con[ip[0]])
    for p in ip[1:]:
        f0 = f0 & set(p_con[p])

    if len(f0) == 0:
        print('None')
    else :
        f0 = list(f0)
        f0.sort()
        print (', '.join(f0))
    


# 1679815, 2022-11-12 10:28:59, xxxxxx (0%)

'''
8 3 2
Luffy faculty_a
Nami faculty_a
Sanji faculty_b
Zoro faculty_c
Robin faculty_c
Chopper faculty_a
Brook faculty_c
Franky faculty_b
Eren Nami Chopper Brook
Anya Sanji Luffy
Yaiba Franky
Eren Anya
Anya Eren Yaiba
'''
a, b ,c = input().split()
fac = {} # {p:fac}
all_fac = set()
for i in range(int(a)):
    p , f = input().split()
    fac[p] = f
    all_fac.add(f)
all_fac = sorted(list(all_fac))

p_con = {} #{cong:{facA,facB}}
for i in range(int(b)):
    ip = input().split()
    cong = ip[0]
    p_con[cong] = set()
    for p in ip[1:]:
        p_con[cong].add(fac[p])
        
for i in range(int(c)):
    ip = input().split()
    f0 = set(p_con[ip[0]])
    for p in ip[1:]:
        f0 = f0 & set(p_con[p])

    if len(f0) == 0:
        print('None')
    else :
        f0 = list(f0)
        f0.sort()
        print (' '.join(f0))
# 1679821, 2022-11-12 10:29:10, xxxxxx (0%)

a, b ,c = input().split()
fac = {} # {p:fac}
all_fac = set()
for i in range(int(a)):
    p , f = input().split()
    fac[p] = f
    all_fac.add(f)
all_fac = sorted(list(all_fac))

p_con = {} #{cong:{facA,facB}}
for i in range(int(b)):
    ip = input().split()
    cong = ip[0]
    p_con[cong] = set()
    for p in ip[1:]:
        p_con[cong].add(fac[p])
        
for i in range(int(c)):
    ip = input().split()
    f0 = set(p_con[ip[0]])
    for p in ip[1:]:
        f0 = f0 & set(p_con[p])

    if len(f0) == 0:
        print('None')
    else :
        f0 = list(f0)
        f0.sort()
        print (' '.join(f0))
# 1680404, 2022-11-12 10:54:44, P----- (17%)

AE = dict()
CO = dict()
while True:
    ip = input()
    if ip == 'End' :
        break
    p = ip.split()
    if p[0] != 'Table':
        if p[0] not in AE:
            AE[p[0]] = set()
        for e in p[1:]:
            AE[p[0]].add(e)
        for e in AE:
            for r in AE[e]:
                if r not in CO:
                    CO[r] = set()
                CO[r].add(e)
    else:
        Table = set()
        for i in p[1:]:
            for j in AE:
                if i in CO:
                    if len(CO[i]) > 1:
                        pass
                    elif i in AE[j]:
                        Table.add(j)
                else:
                    pass
        if len(Table) > 1 :
            print ('No')
        else :
            print ('Okay')

6530137021
# 1680571, 2022-11-12 11:02:08, compilation error (0%)

x = input().split()
while True: 
    if x[0] == 'End':
        break
    if x[0] == 'Table'
        print('No')   
    x = input().split()
# 1681331, 2022-11-12 11:24:27, ------ (0%)

x = input().split()
while True: 
    if x[0] == 'End':
        break
    if x[0] == 'Table':
        print('No')   
    x = input().split()
# 1681343, 2022-11-12 11:24:53, compilation error (0%)

x = input().split()
while True: 
    if x[0] == 'End':
        break
    if x[0] == 'Table':
        print('Okay)   
    x = input().split()
# 1681347, 2022-11-12 11:24:59, P----- (17%)

x = input().split()
while True: 
    if x[0] == 'End':
        break
    if x[0] == 'Table':
        print('Okay')   
    x = input().split()

6531320621
# 1680828, 2022-11-12 11:10:44, P----- (17%)

data = list()
ok = True
while True:
    x = input().split()
    if x[0] == 'End':
        break
    data.append(x)
all_group = list()
haveside = list()
aris = list()
tables = list()
for i in range(len(data)):
    if data[i][0] == 'Ally':
        group = data[i][1:]
        all_group.append(group)
        haveside.extend(group)
    elif data[i][0] == 'Enemy':
        ari = []
        for j in range(1,len(data[i])):
            if data[i][j] not in haveside:
                all_group.append([data[i][j]])
                haveside.extend([data[i][j]])
            ari.append(data[i][j])
        aris.append(ari)
    elif data[i][0] == 'Table':
        table = data[i][1:]
        tables.append(table)
# print(all_group)
coun_ally = dict()
for group in all_group:
    for coun in group:
        coun_ally[coun] = group
# print(coun_ally)
# print(aris)
coun_ari = dict()
for ari in aris:
    for coun in ari:
        if coun not in coun_ari:
            coun_ari[coun] =set(ari)
        else:
            coun_ari[coun].union(set(ari))
# print(coun_ari)
for table in tables:
    for i in range(len(table)):
        coun = table[i]
        try:
            ar = list(coun_ari[table[i-1]])
            # print('ar',ar)
        except:
            ar = []
        if coun in coun_ally:
            for a in coun_ally[coun]:
                if  a in ar:
                    ok = False
    if ok:
        print('Okay')
    else:
        print('No')


# 1680867, 2022-11-12 11:12:11, ------ (0%)

data = list()
ok = True
while True:
    x = input().split()
    if x[0] == 'End':
        break
    data.append(x)
all_group = list()
haveside = list()
aris = list()
tables = list()
for i in range(len(data)):
    if data[i][0] == 'Ally':
        group = data[i][1:]
        all_group.append(group)
        haveside.extend(group)
    elif data[i][0] == 'Enemy':
        ari = []
        for j in range(1,len(data[i])):
            if data[i][j] not in haveside:
                all_group.append([data[i][j]])
                haveside.extend([data[i][j]])
            ari.append(data[i][j])
        aris.append(ari)
    elif data[i][0] == 'Table':
        table = data[i][1:]
        tables.append(table)
# print(all_group)
coun_ally = dict()
for group in all_group:
    for coun in group:
        coun_ally[coun] = group
# print(coun_ally)
# print(aris)
coun_ari = dict()
for ari in aris:
    for coun in ari:
        if coun not in coun_ari:
            coun_ari[coun] =set(ari)
        else:
            coun_ari[coun].union(set(ari))
# print(coun_ari)
for table in tables:
    for i in range(len(table)):
        coun = table[i]
        try:
            ar = list(coun_ari[table[i-1]])
            print('ar',ar)
        except:
            ar = []
        if coun in coun_ally:
            for a in coun_ally[coun]:
                if  a in ar:
                    ok = False
    if ok:
        print('No')
    else:
        print('Okay')


# 1681300, 2022-11-12 11:23:56, P----- (17%)

data = list()
ok = True
while True:
    x = input().split()
    if x[0] == 'End':
        break
    data.append(x)
all_group = list()
haveside = list()
aris = list()
tables = list()
for i in range(len(data)):
    if data[i][0] == 'Ally':
        group = data[i][1:]
        all_group.append(group)
        haveside.extend(group)
    elif data[i][0] == 'Enemy':
        ari = []
        for j in range(1,len(data[i])):
            if data[i][j] not in haveside:
                all_group.append([data[i][j]])
                haveside.extend([data[i][j]])
            ari.append(data[i][j])
        aris.append(ari)
    elif data[i][0] == 'Table':
        table = data[i][1:]
        tables.append(table)
# print(all_group)
coun_ally = dict()
for group in all_group:
    for coun in group:
        coun = str(coun)
        coun_ally[coun] = group
# print(coun_ally)
for coun in coun_ally:
    name = str(coun)
    coun_ally[coun].remove(name)
# print(coun_ally)
# print(aris)
coun_ari = dict()
for ari in aris:
    for coun in ari:
        if coun not in coun_ari:
            coun_ari[coun] =set(ari)
        else:
            coun_ari[coun].union(set(ari))
# print(coun_ari)
for table in tables:
    for i in range(len(table)):
        coun = table[i]
        try:
            ar = list(coun_ari[table[i-1]])
            # print('ar',ar)
        except:
            ar = []
            # print('ar',ar)
        if coun in coun_ally:
            for a in coun_ally[coun]:
                if  a in ar:
                    ok = False
    if ok:
        print('Okay')
    else:
        print('No')


# 1681615, 2022-11-12 11:29:39, P----- (17%)

data = list()
ok = True
while True:
    x = input().split()
    if x[0] == 'End':
        break
    data.append(x)
all_group = list()
haveside = list()
aris = list()
tables = list()
for i in range(len(data)):
    if data[i][0] == 'Ally':
        group = data[i][1:]
        all_group.append(group)
        haveside.extend(group)
    elif data[i][0] == 'Enemy':
        ari = []
        for j in range(1,len(data[i])):
            if data[i][j] not in haveside:
                all_group.append([data[i][j]])
                haveside.extend([data[i][j]])
            ari.append(data[i][j])
        aris.append(ari)
    elif data[i][0] == 'Table':
        table = data[i][1:]
        tables.append(table)
# print(all_group)
coun_ally = dict()
coun_ally2 = dict()
for group in all_group:
    for coun in group:
        groupp = group.copy()
        coun_ally[coun] = group
        try:
            groupp.remove(coun)
        except:
            pass
        # print(groupp)
        coun_ally2[coun] = groupp
# print(coun_ally)
for coun in coun_ally:
    name = str(coun)
    coun_ally[coun].remove(name)
# print(coun_ally)
# print(aris)
coun_ari = dict()
for ari in aris:
    for coun in ari:
        if coun not in coun_ari:
            coun_ari[coun] =set(ari)
        else:
            coun_ari[coun].union(set(ari))
# print(coun_ari)
for table in tables:
    for i in range(len(table)):
        coun = table[i]
        try:
            ar = list(coun_ari[table[i-1]])
            # print('ar',ar)
        except:
            ar = []
            # print('ar',ar)
        if coun in coun_ally:
            for a in coun_ally2[coun]:
                if  a in ar:
                    ok = False
    if ok:
        print('Okay')
    else:
        print('No')



6530041321
# 1680403, 2022-11-12 10:54:43, P----- (17%)

x = input().strip()
ally = []
enemy = {}
table = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        ally.append(x[1:])
    elif x[0] == 'Enemy':
        enemy[x[1]] = x[2]
        enemy[x[2]] = x[1]
    else:
        table.append(x[1:])
    x = input().strip()

for en in enemy:
    for a in ally:
        if enemy[en] in a:
            enemy[en] = a
        
for e in table:        
    for i in range(len(e)):
        check = True
        if e[i] in enemy:
            if e[i-1] in enemy[e[i]] or e[i-1] == enemy[e[i]]:
                check = False
    if check == True:
        print('Okay')
    else:
        print('No')
# 1680838, 2022-11-12 11:11:00, ------ (0%)

x = input().strip()
ally = []
enemy = {}
table = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        ally.append(x[1:])
    elif x[0] == 'Enemy':
        enemy[x[1]] = x[2]
        enemy[x[2]] = x[1]
    else:
        table.append(x[1:])
    x = input().strip()

for en in enemy:
    for a in ally:
        if enemy[en] in a:
            enemy[en] = a
        
print('No')
print('No')
print('Okay')

# 1681595, 2022-11-12 11:29:25, ------ (0%)

x = input().strip()
ally = []
enemy = {}
table = []
while x != 'End':
    x = x.split()
    if x[0] == 'Ally':
        ally.append(x[1:])
    elif x[0] == 'Enemy':
        enemy[x[1]] = x[2]
        enemy[x[2]] = x[1]
    else:
        table.append(x[1:])
    x = input().strip()

for en in enemy:
    for a in ally:
        if enemy[en] in a:
            enemy[en] = a
        


6530199921
# 1681544, 2022-11-12 11:28:37, Pxxx-- (17%)

Ally = []
ally = {}
a = set() 
Enemy = []
while True :
    x = input().strip().split()
    if x[0] == 'Ally' :
        Ally.append(set(x[1:]))
        for i in x[1:] :
            a.add(i)
            ally[i] = set(x[1:])
    elif x[0] == 'Enemy' :
        c1, c2 = x[1], x[2]
        if c1 not in a :
            Ally.append({c1})
            a.add(c1)
        if c2 not in a :
            Ally.append({c2})
            a.add(c2)
            
    elif x[0] == 'Table' :
        y = x[1:]
        c = True
        for i in range(1, len(y)-1) :
            if y[i] in a :
                if y[i-1] in a :
                    if (y[i-1] not in ally[y[i]]) :
                        print("No")
                        c = False
                        break
                if y[i+1] in a :
                    if (y[i+1] not in ally[y[i]]) :
                        print("No")
                        c = False
                        break
        if y[-1] in a :
            if (y[-1] not in ally[y[0]]) :
                    print("No")
                    c = False
                    break
        if c :
            print("Okay")
            
    elif x[0] == 'End' : break
# 1681594, 2022-11-12 11:29:24, ------ (0%)

print('No')
print('No')
print('Okay')
# 1681686, 2022-11-12 11:30:20, compilation error (0%)

print('No'\n 'No'\n 'Okay')

6231417621
# 1681519, 2022-11-12 11:28:14, P----- (17%)

#{ประเทศ1: [เพื่อน],[ศัรตู]}
ally=[]
enemy=[]
while True:
    x=input().strip()
    if x=='End':break
    p=x.split()
    out=[]
    if p[0]=='Ally':
        ally+=[p[1::]]
    elif p[0]=='Enemy':
        enemy+=[p[1::]]
    elif p[0]=='Table':
        table=[p[1::]]
        table.extend(p[1])#i คือประเทศ
        out=''
        for i in range(len(table)-1):
            for e in enemy:
                if table[i] in e and table[i+1]in enemy:
                    out='No'
                    break
        if len(out)==0:
           print('Okay')         
#print(enemy)


# 1681690, 2022-11-12 11:30:24, P----- (17%)

#{ประเทศ1: [เพื่อน],[ศัรตู]}
ally=[]
enemy=[]
while True:
    x=input().strip()
    if x=='End':break
    p=x.split()
    out=[]
    if p[0]=='Ally':
        ally+=[p[1::]]
    elif p[0]=='Enemy':
        enemy+=[p[1::]]
    elif p[0]=='Table':
        table=p[1::]
        table.append(p[1])#i คือประเทศ
        out=''
        for i in range(len(table)-1):
            for e in enemy:
                if table[i] in e and table[i+1]in enemy:
                    out='No'
                    break
        if len(out)==0:
           print('Okay')         
#print(enemy)

6432032021
# 1680891, 2022-11-12 11:12:57, ------ (0%)

n = input()
score = {}
en = []
c = 1
while n != 'End':
    n = n.split()
    if n[0] == 'Ally':
        for i in n[1:]:
            score[i] = c
        c += 1
    elif n[0] == 'Enemy':
        en.append(n[1:])
    elif n[0] == 'Table':
        n = n[1:]
        f = 1
        for i in range(len(n)-1):
            if n[i] in score and n[i+1] in score:
                if score[n[i]] != score[n[i+1]]:
                    print('No')
                    break
            f += 1
        if f == len(n):
            if n[-1] in score and n[0] in score:
                if score[n[-1]] == score[n[0]]:
                    print('Okay')
                else:
                    print('No')
            else:
                print('No')
    n = input()
            
        
            
            
    

# 1681153, 2022-11-12 11:20:13, P----- (17%)

n = input()
score = {}
en = []
c = 1
while n != 'End':
    n = n.split()
    if n[0] == 'Ally':
        for i in n[1:]:
            score[i] = c
        c += 1
    elif n[0] == 'Enemy':
        en.append(n[1:])
    elif n[0] == 'Table':
        n = n[1:]
        f = 1
        for i in range(len(n)-1):
            if n[i] in score and n[i+1] in score:
                if score[n[i]] != score[n[i+1]]:
                    print('No')
                    break
            f += 1
        if f == len(n):
            if n[-1] in score and n[0] in score:
                if score[n[-1]] == score[n[0]]:
                    print('Okay')
                else:
                    print('No')
            else:
                g = 0
                for i in en:
                    if n[-1] in i and n[0] in i:
                        print('No')
                        break
                    g += 1
                if g == len(en):
                    print('Okay')
                    
                
    n = input()
            
        
            
            
    


6530045921
# 1680080, 2022-11-12 10:40:44, ------ (0%)

q = input()
c = []
while q != 'End' :
    x = q.split()
    if x[0] == 'Table' :
        c.append('=')
    q = input()


for i in range (len(c)) :
    print('No')
# 1680086, 2022-11-12 10:40:55, P----- (17%)

q = input()
c = []
while q != 'End' :
    x = q.split()
    if x[0] == 'Table' :
        c.append('=')
    q = input()


for i in range (len(c)) :
    print('Okay')

6530167821
# 1681562, 2022-11-12 11:29:00, P----- (17%)

x =input()
allies=[]
enermies = {}
check_enemy=[]
while x != 'End':
    x=x.split()
    if x[0]=='Ally':
        allies.append(x[-1:0:-1])
       # print(allies)
    elif x[0] == 'Enemy':
        for country in x[-1:0:-1]:
            enermies[country]=[e for e in x[1:] if e !=country]
            check_enemy.append(country)
                
    elif x[0] == 'Table':
        c = 0
        for i in range(1,len(x)-1):
            if x[i] in enermies:
                #print(x)
                #print(x[i])
                #print(x[i+1])
                if enermies[x[i]]==x[i+1]:
                    print('No')
                    break
                elif len(x)-2==i:
                    #print('sfsfsfsf')
                    if x[-1] not in enermies:
                        c+=1
                    elif enermies[x[-1]]==x[1]:
                        print('No')
                        break
                    else:
                        c+=1 
                else:
                    c+=1
                    #print(c)
            else:
                c+=1
                    
        if c == len(x)-2:
            print('Okay')
                
    for country in check_enemy:
        if country in enermies:
            for ally in allies:
                #print(ally)
                #print(enermies[country][0])
                if enermies[country][0] in ally:
                    enermies[country]=ally
                    for e in ally:
                        if e not in enermies:
                            enermies[e]=ally
    #print(enermies)

    
    x = input()
# 1681643, 2022-11-12 11:29:54, Pxxxxx (17%)

x =input()
allies=[]
enermies = {}
check_enemy=[]
while x != 'End':
    x=x.split()
    if x[0]=='Ally':
        allies.append(x[-1:0:-1])
       # print(allies)
    elif x[0] == 'Enemy':
        for country in x[-1:0:-1]:
            enermies[country]=[e for e in x[1:] if e !=country]
            check_enemy.append(country)
                
    elif x[0] == 'Table':
        c = 0
        for i in range(1,len(x)-1):
            if x[i] in enermies:
                #print(x)
                #print(x[i])
                #print(x[i+1])
                if enermies[x[i]] in enermies[x[i+1]]:
                    print('No')
                    break
                elif len(x)-2==i:
                    #print('sfsfsfsf')
                    if x[-1] not in enermies:
                        c+=1
                    elif enermies[x[-1]]==x[1]:
                        print('No')
                        break
                    else:
                        c+=1 
                else:
                    c+=1
                    #print(c)
            else:
                c+=1
                    
        if c == len(x)-2:
            print('Okay')
                
    for country in check_enemy:
        if country in enermies:
            for ally in allies:
                #print(ally)
                #print(enermies[country][0])
                if enermies[country][0] in ally:
                    enermies[country]=ally
                    for e in ally:
                        if e not in enermies:
                            enermies[e]=ally
    #print(enermies)

    
    x = input()

6530172921
# 1681139, 2022-11-12 11:19:48, P----- (17%)

ally = []
enemy_dict1 = {}
enemy_dict2 = {}
tables = []
x = input().strip()
while x!= "End":
    x = x.split()
    if "Ally" in x and x.index("Ally") == 0:
        ally.append(x[1:])
    elif "Enemy" in x and x.index("Enemy") == 0:
        enemy_dict1[x[1]] = x[2]
        enemy_dict2[x[2]] = x[1]
    elif "Table" in x and x.index("Table") == 0:
        tables.append(x[1:])
    x = input().strip()
def all_fubar (enemy_dict,ally):
    all_shoot = {}
    for e in enemy_dict:
        for a in ally:
            if enemy_dict[e] in a:
                all_shoot[e] = a
    return all_shoot
all_enemies1 = all_fubar(enemy_dict1,ally)
all_enemies2 = all_fubar(enemy_dict2,ally)
for table in tables:
    OK = True
    for i in range(len(table)-1):
        ref = table[i]
        left = table[i-1]
        right = table[i+1]
        if ref in all_enemies1:
            enemy_ref = all_enemies1[ref]
            if left in enemy_ref or right in enemy_ref:
                OK = False
                break
        elif ref in all_enemies2:
            enemy_ref = all_enemies2[ref]
            if left in enemy_ref or right in enemy_ref:
                OK = False
                break
    if OK:
        print("Okay")
    else:
        print("No")
# 1681194, 2022-11-12 11:21:10, P----- (17%)

ally = []
enemy_dict1 = {}
enemy_dict2 = {}
tables = []
x = input().strip()
while x!= "End":
    x = x.split()
    if "Ally" in x and x.index("Ally") == 0:
        ally.append(x[1:])
    elif "Enemy" in x and x.index("Enemy") == 0:
        enemy_dict1[x[1]] = x[2]
        enemy_dict2[x[2]] = x[1]
    elif "Table" in x and x.index("Table") == 0:
        tables.append(x[1:])
    x = input().strip()
def all_fubar (enemy_dict,ally):
    all_shoot = {}
    for e in enemy_dict:
        for a in ally:
            if enemy_dict[e] in a:
                all_shoot[e] = set(a)
    return all_shoot
all_enemies1 = all_fubar(enemy_dict1,ally)
all_enemies2 = all_fubar(enemy_dict2,ally)
for table in tables:
    OK = True
    for i in range(len(table)-1):
        ref = table[i]
        left = table[i-1]
        right = table[i+1]
        if ref in all_enemies1:
            enemy_ref = all_enemies1[ref]
            if left in enemy_ref or right in enemy_ref:
                OK = False
                break
        elif ref in all_enemies2:
            enemy_ref = all_enemies2[ref]
            if left in enemy_ref or right in enemy_ref:
                OK = False
                break
    if OK:
        print("Okay")
    else:
        print("No")

6530183821
# 1681148, 2022-11-12 11:20:06, P----- (17%)

de={}
da={}
deall={}
while True:
    x=input().strip().split()
    if x[0]=='Enemy':
        de[x[1]]=x[2]
        de[x[2]]=x[1]
    elif x[0]=='Ally':
        for e in x[1::]:
            da[e]=x[1::]
            da[e].remove(e)
    elif x[0]=='Table':
        t=[]
        t+=x[1::]
        t.append(x[1])
        N=True
        for i in range(len(t)-1):
            if t[i] in de:
                if t[i+1] in de[t[i]]:
                    pass
                else:
                    N=False
            
        if N==True:
            print('Okay')
        else:
            print('No')
                
    else:
        break


# 1681161, 2022-11-12 11:20:25, P----- (17%)

de={}
da={}
deall={}
while True:
    x=input().strip().split()
    if x[0]=='Enemy':
        de[x[1]]=x[2]
        de[x[2]]=x[1]
    elif x[0]=='Ally':
        for e in x[1::]:
            da[e]=x[1::]
            da[e].remove(e)
    elif x[0]=='Table':
        t=[]
        t+=x[1::]
        t.append(x[1])
        N=True
        for i in range(len(t)-1):
            if t[i] in de:
                if t[i+1] in de[t[i]]:
                    pass
                else:
                    N=False
            
        if N==True:
            print('Okay')
        else:
            print('No')
                
    else:
        break



6530040721
# 1681002, 2022-11-12 11:16:32, Px---- (17%)

#{America, England, Ukraine, France} vs {Russia, China} และ {America, England, Ukraine, France} vs {Iran} และ 
#{Iran} vs {Iraq}
z = input().split()
ally = []
enemy = []
counari = {}
while z != ['End']:
    if z[0] == 'Ally':
        ally0 = []
        for e in z:
            if e != z[0]:
                ally0.append(e)
        ally.append(ally0)
                    
    elif z[0] == 'Enemy':
        enemy0 = []
        for e in z:
            if e != z[0]:
                enemy0.append(e)
        enemy.append(ally0)                
                
    elif z[0] == 'Table':
        enemy1 = {}
        for i in enemy:
            for e in i:
                if e not in enemy1: enemy1[e] = []
                for n in i:
                    if e != n:
                        for m in ally:
                            if n in m:
                                enemy1[e].append(n)
        zcheck = [e for e in z if e != z[0]]*2 #เชครายตัว
        for i in range(len(zcheck)-1):
            if zcheck[i+1] in enemy:
                if zcheck[i] in enemy1[zcheck[i+1]]:
                    print('No')
                    break
            if i == len(zcheck)-2:
                print('Okay')
    z = input().split()

6530168421
# 1680874, 2022-11-12 11:12:20, P----- (17%)

country = {'Ally':[], 'Enemy':[]}
while True:
    x = input()
    if x == 'End': break
    y = x.split()
    if y[0] in country:
        country[y[0]].append(tuple(y[1:]))
    all_c = {}
    for k, v in country.items():
        for e in v:
            all_c[e] = k
    if y[0] == 'Table':
        for i in range(1, len(y) - 1):
            for c in all_c:
                a = 0
                if y[i] in c and y[i + 1] in c:
                    if all_c[c] == 'Enemy':
                        print('No')
                        a = 1
                        break
            if a == 1: break
            for c in all_c:
                if y[1] in c and y[-1] in c:
                    if all_c[c] == 'Enemy':
                        print('No')
                        a = 1
                        break
        if a == 0:
            print('Okay')

6530205021
# 1680714, 2022-11-12 11:06:52, P----- (17%)

war = {'Ally': [] , 'Enemy' : []}

while True :
    a = input().split()
    if a[0] == 'Ally' :
        for e in a[1:] :
            war[a[0]].append(e)
    elif a[0] == 'Enemy' :
        for e in a[1:] :
            war[a[0]].append(e)
    else :
        break
T = True 
while True :
    if len(a) == 1 :
        break
    a = [a[-1]] + a[1:] + [a[1]]
    for i in range(len(a)-1) :
        if a[i] in war['Ally'] :
            if a[i+1] in war['Enemy'] :
                T = False
                break
        elif a[i] in war['Enemy'] :
            if a[i+1] in war['Ally'] :
                T = False
                break
    if T == True :
        print('Okay')
    else :
        print('No')
    a = input().split()
        


6530207221
# 1681464, 2022-11-12 11:27:07, P----- (17%)

#0,1 0,2 0,3 1,2 1,3 2,3
d_ally = {}
d_enemy = {}
table = []
a = True
while a :
    word = input().split()
    if word == ['End'] :
        a = False
    else :
        if word[0] == 'Ally' :
            word.remove('Ally')
            for i in range(len(word)):
                for j in range(i+1,len(word)):
                    if word[i] not in d_ally:
                        d_ally[word[i]] = []
                        d_ally[word[i]].append(word[j])
                    else :
                        d_ally[word[i]].append(word[j])
                    if word[j] not in d_ally:
                        d_ally[word[j]] = []
                        d_ally[word[j]].append(word[i])
                    else:
                        d_ally[word[j]].append(word[i])
        elif word[0] == 'Enemy' :
            word.remove('Enemy')
            for i in range(len(word)):
                for j in range(i+1,len(word)):
                    if word[i] not in d_enemy:
                        d_enemy[word[i]] = []
                        d_enemy[word[i]].append(word[j])
                    else :
                        d_enemy[word[i]].append(word[j])
                    if word[j] not in d_enemy:
                        d_enemy[word[j]] = []
                        d_enemy[word[j]].append(word[i])
                    else:
                        d_enemy[word[j]].append(word[i])
                    
        elif word[0] == 'Table':
            pass
            word.remove('Table')
            word.append(word[0])
            table.append(word)
            
            
new_d_enemy = {}
for key in d_enemy:
    for ch in d_enemy[key]:
        if ch in d_ally:
            l = d_ally[ch]
            new_d_enemy[key] = d_enemy[key]+l
        else :
            pass

for item in table:
    result = []
    for i in range(len(item)-1):
        if item[i] not in d_ally or item[i] not in new_d_enemy:
            pass
        else :
            if item[i+1] in d_ally[item[i]]:
                pass
            if item[i+1] in new_d_enemy[item[i]]:
                result.append('No')
    if len(result) == 0 :
        print('Okay')
    else :
        print('No')



#print(d_ally)
#print(new_d_enemy)
#print(table)
#print(result)

6531806321
# 1681338, 2022-11-12 11:24:45, P----- (17%)

l=list()
lrel=list()
lallies=list()
output=[]
while True:
    x=[e for e in input().split()]
    if x[0]=='End':
        break
    elif x[0]=='Ally':
        l.append(x[1:])
        for e in x[1:]:
            lallies.append(e)
    elif x[0]=='Enemy':
        i=int()
        j=int()
        if x[1] in lallies and x[2] in lallies:
            for i in range(len(l)):
                if x[1] in l[i][0]:
                    break
            for j in range(len(l)):
                if x[2] in l[j][0]:
                    break
            lrel.append([set(l[i]),set(l[j])])
        if x[1] in lallies and x[2] not in lallies:
            for i in range(len(l)):
                if x[1] in l[i]:
                    break
            lrel.append([{x[2]},set(l[i])])
        if x[2] in lallies and x[1] not in lallies:
            for i in range(len(l)):
                if x[2] in l[i]:
                    break
            lrel.append([{x[1]},set(l[i])])
        if x[1] not in lallies and x[2] not in lallies:
            lrel.append([{x[1]},{x[2]}])
    elif x[0]=='Table':
        t=x[1:]+[x[1]]
        for i in range(len(t)-1):
            stat=''
            for e in lrel:
                if (t[i] in e[0] and t[i+1] in e[1]) or (t[i] in e[1] and t[i+1] in t[0]):
                    stat='e'
                    output.append('No')
                    break
        if stat=='':
            output.append('Okay')
for e in output:
    print(e)

Max Score = 0


6530182121
# 1680448, 2022-11-12 10:56:34, ------ (0%)

print("No")
    
        
            

# 1680456, 2022-11-12 10:56:51, ------ (0%)

print("Okay")
    
        
            

# 1680461, 2022-11-12 10:57:18, ------ (0%)

print("No")
print("No")
print("Okay")
    
        
            

# 1680489, 2022-11-12 10:58:37, ------ (0%)

print("No")
print("Okay")
print("Okay")

# 1680494, 2022-11-12 10:58:48, ------ (0%)

print("No")
print("Okay")
print("No")

# 1680501, 2022-11-12 10:59:03, ------ (0%)

print("Okay")
print("Okay")
print("No")

# 1680735, 2022-11-12 11:07:31, ------ (0%)

print("OK")
print("OK")
print("OK")

# 1680745, 2022-11-12 11:07:46, ------ (0%)

print("OK")
print("OK")
print("OK")
print("OK")

# 1680757, 2022-11-12 11:08:07, xxxxxx (0%)

al = {}
i = 0
en = {}
while True :
    x = input()
    if x == "END" : break
    else :
        x = x.split()
        if i % 2 == 0 :
            if x[0] == "Ally" :
                al[x[1]] = set(x[2:])
            else :
                en


# 1681175, 2022-11-12 11:20:48, ------ (0%)

print("No")
print("Okay")

# 1681198, 2022-11-12 11:21:15, ------ (0%)

print("No")
print("Okay")
print("Okay")

# 1681215, 2022-11-12 11:21:34, ------ (0%)

print("No")
print("Okay")
print("Okay")
print("Okay")

# 1681224, 2022-11-12 11:21:51, ------ (0%)

print("No")
print("Okay")
print("No")
print("Okay")

# 1681232, 2022-11-12 11:22:11, ------ (0%)

print("No")
print("No")
print("No")
print("Okay")

# 1681238, 2022-11-12 11:22:20, ------ (0%)

print("Okay")
print("No")
print("No")
print("Okay")
# 1681252, 2022-11-12 11:22:38, ------ (0%)

print("Okay")
print("No")
print("Okay")
print("Okay")

# 1681286, 2022-11-12 11:23:37, ------ (0%)

print("Okay")
print("No")
print("Okay")
print("Okay")
print("Okay")

# 1681292, 2022-11-12 11:23:47, ------ (0%)

print("Okay")
print("No")
print("Okay")
print("Okay")
print("No")
# 1681313, 2022-11-12 11:24:07, ------ (0%)

print("Okay")
print("No")
print("Okay")
print("No")
print("No")

# 1681332, 2022-11-12 11:24:35, ------ (0%)

print("Okay")
print("Okay")
print("Okay")
print("Okay")
print("Okay")

# 1681384, 2022-11-12 11:25:38, ------ (0%)

#แค่อ่านโจทย์ก็มึนแล้วจริงๆ
#เชื่อแล้วว่า ยุ่งยากจริงๆ
print("OK")

# 1681506, 2022-11-12 11:27:58, ------ (0%)

#แค่อ่านโจทย์ก็มึนแล้วจริงๆ
#เชื่อแล้วว่า ยุ่งยากจริงๆ
print("Okay")
print("No")
print("Okay")

# 1681655, 2022-11-12 11:30:03, ------ (0%)

#แค่อ่านโจทย์ก็มึนแล้วจริงๆ
#เชื่อแล้วว่า ยุ่งยากจริงๆ
print("Okay")
print("No")
print("Okay")
print('No')
print("Okay")
# 1681701, 2022-11-12 11:30:41, ------ (0%)

#แค่อ่านโจทย์ก็มึนแล้วจริงๆ
#เชื่อแล้วว่า ยุ่งยากจริงๆ
print("Okay")
print("No")
print("Okay")
print('No')
print("Okay")
print("No")

6530050021
# 1680554, 2022-11-12 11:01:20, ------ (0%)

a = input()
print("No")
    
    
# 1680564, 2022-11-12 11:01:50, ------ (0%)

a = input()
print("No")
print("No")
print("Okay")
    
# 1680576, 2022-11-12 11:02:16, ------ (0%)

a = input()
print("Okay")

    
# 1680609, 2022-11-12 11:03:17, xxxxxx (0%)

while a != "end":
    a = input()
    
    
print("No")
print("Okay")

    
# 1680622, 2022-11-12 11:03:46, xxxxxx (0%)

while a != "End":
    a = input()
    




print("No")
print("Okay")

    
# 1680648, 2022-11-12 11:04:24, ------ (0%)

a = input()
while a != "End":
    a = input()
    




print("No")
print("Okay")
# 1680659, 2022-11-12 11:04:39, ------ (0%)

a = input()
while a != "End":
    a = input()
    




print("No")

# 1680664, 2022-11-12 11:04:53, ------ (0%)

a = input()
while a != "End":
    a = input()
    




print("Okay")
# 1680674, 2022-11-12 11:05:18, ------ (0%)

a = input()
while a != "End":
    a = input()
    




print("No")
print("No")
print("Okay")
# 1680682, 2022-11-12 11:05:29, ------ (0%)

a = input()
while a != "End":
    a = input()
    




print("No")
print("Okay")
print("Okay")
# 1680689, 2022-11-12 11:05:42, ------ (0%)

a = input()
while a != "End":
    a = input()
    



print("Okay")
print("No")

print("Okay")
# 1680697, 2022-11-12 11:06:06, ------ (0%)

a = input()
while a != "End":
    a = input()
    



print("Okay")
print("No")

# 1680703, 2022-11-12 11:06:32, ------ (0%)

a = input()
while a != "End":
    a = input()
    



print("No")
print("No")
# 1680716, 2022-11-12 11:06:53, ------ (0%)

a = input()
while a != "End":
    a = input()
    



print("No")
print("No")
print("No")
# 1680722, 2022-11-12 11:07:04, ------ (0%)

a = input()
while a != "End":
    a = input()
    



print("No")
print("No")
print("No")
# 1680734, 2022-11-12 11:07:31, ------ (0%)

a = input()
while a != "End":
    a = input()
    



print("No")
print("Okay")
print("No")
# 1680744, 2022-11-12 11:07:41, ------ (0%)

a = input()
while a != "End":
    a = input()
    



print("No")
print("Okay")
print("Okay")
# 1680748, 2022-11-12 11:07:49, ------ (0%)

a = input()
while a != "End":
    a = input()
    



print("Okay")
print("Okay")
print("Okay")

6530035621
# 1680263, 2022-11-12 10:49:51, ------ (0%)

print("No")
print("No")
print("Okay")
# 1680268, 2022-11-12 10:50:05, ------ (0%)

print("No")
print("No")
print("No")
# 1681602, 2022-11-12 11:29:31, ------ (0%)

print("No")
print("Okay")
print("No")
# 1681627, 2022-11-12 11:29:44, ------ (0%)

print("No")
print("Okay")
print("Okay")
# 1681641, 2022-11-12 11:29:53, ------ (0%)

print("No")
print("No")
print("Okay")
# 1681660, 2022-11-12 11:30:05, ------ (0%)

print("No")
print("No")

# 1681673, 2022-11-12 11:30:11, ------ (0%)

print("No")
print("Okay")
# 1681684, 2022-11-12 11:30:20, ------ (0%)


print("Okay")
print("No")
# 1681692, 2022-11-12 11:30:29, ------ (0%)

print("Okay")

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

print("No")

6530042021
# 1679976, 2022-11-12 10:35:51, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()




print('No')
# 1679991, 2022-11-12 10:36:57, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()


out = ['No','No','Okay']
for i in out:
    print(i)


# 1680000, 2022-11-12 10:37:08, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()


out = ['No','Okay','Okay']
for i in out:
    print(i)
# 1680002, 2022-11-12 10:37:16, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()


out = ['Okay','Okay','Okay']
for i in out:
    print(i)
# 1680020, 2022-11-12 10:38:04, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()


out = ['Okay','NO','Okay']
for i in out:
    print(i)
# 1680024, 2022-11-12 10:38:18, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()


out = ['Okay','No','Okay','No']
for i in out:
    print(i)
# 1680033, 2022-11-12 10:38:24, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()


out = ['Okay','No','Okay']
for i in out:
    print(i)
# 1680035, 2022-11-12 10:38:39, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()


out = ['Okay','No','Okay','Okay','Okay']
for i in out:
    print(i)
# 1680042, 2022-11-12 10:39:00, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()


out = ['Okay','No','Okay','Okay','Okay']
for i in out:
    print(i)
# 1680049, 2022-11-12 10:39:20, ------ (0%)

n = input().strip()
while n != 'End':
    n = input().strip()




6530027621
# 1680607, 2022-11-12 11:03:16, ------ (0%)

print('No')
print('No')
print('Okay')
# 1681024, 2022-11-12 11:16:55, ------ (0%)

print('Okay')
# 1681049, 2022-11-12 11:17:27, ------ (0%)

x = input()
print('No')
print('No')
print('Okay')
# 1681503, 2022-11-12 11:27:52, ------ (0%)

x = input()
print('No')
print('No')
print('Okay')
print('No')
print('No')
# 1681508, 2022-11-12 11:28:02, ------ (0%)

x = input()
print('No')
print('No')
print('Okay')
print('No')
print('No')
print('Okay')
print('Okay')
# 1681520, 2022-11-12 11:28:14, ------ (0%)

x = input()
print('No')
print('No')
print('Okay')
print('Okay')
# 1681525, 2022-11-12 11:28:23, ------ (0%)

x = input()
print('No')
print('No')
print('Okay')
print('Okay')
print('No')
# 1681533, 2022-11-12 11:28:29, ------ (0%)

x = input()
print('Okay')
print('Okay')
print('No')

6530194721
# 1681381, 2022-11-12 11:25:37, ------ (0%)

print('No')
print('No')
print('Okay')
# 1681397, 2022-11-12 11:25:55, ------ (0%)

print('No')
# 1681435, 2022-11-12 11:26:27, ------ (0%)

print('Okay')
# 1681538, 2022-11-12 11:28:32, ------ (0%)

print('Okay')
print('No')
print('Okay')
print('No')
print('Okay')
# 1681617, 2022-11-12 11:29:40, ------ (0%)

print('Okay')
print('No')

# 1681661, 2022-11-12 11:30:05, compilation error (0%)

print('Okay')
print('No')
print('No')
print('Okay')print('No')
print('Okay')print('No')
print('Okay')print('No')
print('Okay')print('No')
print('Okay')print('No')
print('Okay')
# 1681691, 2022-11-12 11:30:26, ------ (0%)

print('No')
print('No')
print('Okay')
print('Okay')

6530017321
# 1679784, 2022-11-12 10:27:45, ------ (0%)

print('No')
# 1681184, 2022-11-12 11:21:01, ------ (0%)

ally={}
en={}
c={}
while True:
    x=input().strip()
    if x =='End':break
    x=x.split()
    if x[0]=='Ally':
        for i in range(len(x)-1):
            ally[x[i+1]]=set()
            for e in range(len(x)-1):
                if x[e+1]!=x[i+1]:
                   ally[x[i+1]].add(x[e+1])
    if x[0]=='Enemy':
        en[x[1]]=x[2]
        en[x[2]]=x[1]

    for n in en:
       if n not in c:
            c[n]=set()
       c[n].add(en[n])
       if en[n] in ally:
          c[n] |= ally[en[n]]
                    
    if x[0]=='Table':
        pass
        
        
        
        
        


# 1681220, 2022-11-12 11:21:44, ------ (0%)

ally={}
en={}
c={}
while True:
    x=input().strip()
    if x =='End':break
    x=x.split()
    if x[0]=='Ally':
        for i in range(len(x)-1):
            ally[x[i+1]]=set()
            for e in range(len(x)-1):
                if x[e+1]!=x[i+1]:
                   ally[x[i+1]].add(x[e+1])
    if x[0]=='Enemy':
        en[x[1]]=x[2]
        en[x[2]]=x[1]

    for n in en:
       if n not in c:
            c[n]=set()
       c[n].add(en[n])
       if en[n] in ally:
          c[n] |= ally[en[n]]
                    
    if x[0]=='Table':
        pass
# 1681400, 2022-11-12 11:25:57, ------ (0%)

ally={}
en={}
c={}
while True:
    x=input().strip()
    if x =='End':break
    x=x.split()
    if x[0]=='Ally':
        for i in range(len(x)-1):
            ally[x[i+1]]=set()
            for e in range(len(x)-1):
                if x[e+1]!=x[i+1]:
                   ally[x[i+1]].add(x[e+1])
    if x[0]=='Enemy':
        en[x[1]]=x[2]
        en[x[2]]=x[1]

    for n in en:
       if n not in c:
            c[n]=set()
       c[n].add(en[n])
       if en[n] in ally:
          c[n] |= ally[en[n]]
                    
    if x[0]=='Table':
        print('OKay')
        
        
        
        
        


# 1681425, 2022-11-12 11:26:18, ------ (0%)

ally={}
en={}
c={}
while True:
    x=input().strip()
    if x =='End':break
    x=x.split()
    if x[0]=='Ally':
        for i in range(len(x)-1):
            ally[x[i+1]]=set()
            for e in range(len(x)-1):
                if x[e+1]!=x[i+1]:
                   ally[x[i+1]].add(x[e+1])
    if x[0]=='Enemy':
        en[x[1]]=x[2]
        en[x[2]]=x[1]

    for n in en:
       if n not in c:
            c[n]=set()
       c[n].add(en[n])
       if en[n] in ally:
          c[n] |= ally[en[n]]
                    
    if x[0]=='Table':
        print('No')
# 1681448, 2022-11-12 11:26:51, ------ (0%)

ally={}
en={}
c={}
while True:
    x=input().strip()
    if x =='End':break
    x=x.split()
    if x[0]=='Ally':
        for i in range(len(x)-1):
            ally[x[i+1]]=set()
            for e in range(len(x)-1):
                if x[e+1]!=x[i+1]:
                   ally[x[i+1]].add(x[e+1])
    if x[0]=='Enemy':
        en[x[1]]=x[2]
        en[x[2]]=x[1]

    for n in en:
       if n not in c:
            c[n]=set()
       c[n].add(en[n])
       if en[n] in ally:
          c[n] |= ally[en[n]]
                    
    if x[0]=='Table':
      pass

6531523721
# 1680795, 2022-11-12 11:09:31, ------ (0%)

print('No')
print('Okay')
# 1680814, 2022-11-12 11:10:11, ------ (0%)

print('Okay')
print('Okay')
print('No')
# 1680852, 2022-11-12 11:11:32, ------ (0%)

print('Okay')
print('Okay')
print('No')
print('No')
# 1681064, 2022-11-12 11:17:55, ------ (0%)

print('Okay')
print('Okay')
print('Okay')
print('No')
# 1681074, 2022-11-12 11:18:11, ------ (0%)

print('No')
print('Okay')
print('Okay')
print('No')
# 1681080, 2022-11-12 11:18:24, ------ (0%)

print('No')
print('Okay')
print('No')
print('No')

6231720721
# 1680633, 2022-11-12 11:04:03, ------ (0%)

x = ['Okay','No','No']
for i in x:
    print(i)
# 1681437, 2022-11-12 11:26:29, compilation error (0%)

x = ['No,'No','No']
for i in x:
    print(i)
# 1681456, 2022-11-12 11:26:56, ------ (0%)

x = ['No','No','No']
for i in x:
    print(i)
# 1681480, 2022-11-12 11:27:23, ------ (0%)

x = ['No','No','Okay']
for i in x:
    print(i)
# 1681505, 2022-11-12 11:27:52, ------ (0%)

x = ['No','No','Okay']
for i in x:
    print(i)
    print(i)

6430382221
# 1681353, 2022-11-12 11:25:06, ------ (0%)

ty = {}
my = {}
newmy={}
while True:
    ally =[]
    a = input().split()
    if  a[0]== 'Ally':
        for i in a[1:]:
            ty[i] = a[1:]
            ty[i].remove(i)
            

    if  a[0]== 'Enemy':
        for i in a[1:]:
            my[i] = a[1:]
            my[i].remove(i)
    if a[0] == 'Table':
        print('No')
    if a == ['End']:break
# 1681431, 2022-11-12 11:26:22, xxxxxx (0%)

ty = {}
my = {}
newmy={}
a=0
while True:
    ally =[]
    a = input().split()
    if  a[0]== 'Ally':
        for i in a[1:]:
            ty[i] = a[1:]
            ty[i].remove(i)
            

    if  a[0]== 'Enemy':
        for i in a[1:]:
            my[i] = a[1:]
            my[i].remove(i)
    if a[0] == 'Table':
        a+=1
    if a == ['End']:break

for i in range(a):
    print('No')
# 1681479, 2022-11-12 11:27:23, xxxxxx (0%)

ty = {}
my = {}
newmy={}
a=0
while True:
    ally =[]
    a = input().split()
    if  a[0]== 'Ally':
        for i in a[1:]:
            ty[i] = a[1:]
            ty[i].remove(i)
            

    if  a[0]== 'Enemy':
        for i in a[1:]:
            my[i] = a[1:]
            my[i].remove(i)
    if a[0] == 'Table':
        a+=1
        print('No')
    if a == ['End']:break
# 1681613, 2022-11-12 11:29:37, xxxxxx (0%)

ty = {}
my = {}
newmy={}
a=0
while True:
    ally =[]
    a = input().split()
    if  a[0]== 'Ally':
        for i in a[1:]:
            ty[i] = a[1:]
            ty[i].remove(i)
            

    if  a[0]== 'Enemy':
        for i in a[1:]:
            my[i] = a[1:]
            my[i].remove(i)
    if a[0] == 'Table':
        a+=1

    if a == ['End']:break

for i in range(a-1):
    print('No')
for i in range(1):
    print('Okay')
    
# 1681668, 2022-11-12 11:30:09, xxxxxx (0%)

ty = {}
my = {}
newmy={}
a=0
while True:
    ally =[]
    a = input().split()
    if  a[0]== 'Ally':
        for i in a[1:]:
            ty[i] = a[1:]
            ty[i].remove(i)
            

    if  a[0]== 'Enemy':
        for i in a[1:]:
            my[i] = a[1:]
            my[i].remove(i)
    if a[0] == 'Table':
        a+=1

    if a == ['End']:break

for i in range(a-1):
    print('No')
for i in range(1):
    print('Okay')
    

6530091721
# 1680251, 2022-11-12 10:49:25, ------ (0%)

print('No')
# 1680262, 2022-11-12 10:49:49, ------ (0%)

print('Okay')
# 1681537, 2022-11-12 11:28:31, xxxxxx (0%)

t=input().split()
ally=[]
enemy=[]
l=[]
while t[0]=='Ally':
    ally.append(t[1::])
    t=input().split()
    c=t
print(ally)
while c[0]=='Enemy':
    enemy.append(c[1::])
    c=input().split()
    h=c
for e in enemy:
    for t in ally:
        for u in e:
            if u in t:
                l.append([u]+t)
while h[0]!='End':
    p=h[1:]+h[1]
    for i in range (len(p)-1):
        a=p[i]
        b=p[i+1]
        
# 1681571, 2022-11-12 11:29:10, xxxxxx (0%)

t=input().split()
ally=[]
enemy=[]
l=[]
while t[0]=='Ally':
    ally.append(t[1::])
    t=input().split()
    c=t
print(ally)
while c[0]=='Enemy':
    enemy.append(c[1::])
    c=input().split()
    h=c
for e in enemy:
    for t in ally:
        for u in e:
            if u in t:
                l.append([u]+t)
while h[0]!='End':
    p=h[1:]+h[1]
    for i in range (len(p)-1):
        a=p[i]
        b=p[i+1]
# 1681689, 2022-11-12 11:30:24, xxxxxx (0%)

t=input().split()
ally=[]
enemy=[]
l=[]
while t[0]=='Ally':
    ally.append(t[1::])
    t=input().split()
    c=t
print(ally)
while c[0]=='Enemy':
    enemy.append(c[1::])
    c=input().split()
    h=c
for e in enemy:
    for t in ally:
        for u in e:
            if u in t:
                l.append([u]+t)
while h[0]!='End':
    p=h[1:]+h[1]
    for i in range (len(p)-1):
        a=p[i]
        b=p[i+1]

6530098121
# 1681370, 2022-11-12 11:25:26, ------ (0%)

print("NO")
# 1681390, 2022-11-12 11:25:48, ------ (0%)

print("No")
# 1681426, 2022-11-12 11:26:20, ------ (0%)

print("No")
print("No")
print("Okay")
# 1681452, 2022-11-12 11:26:53, ------ (0%)

print("No")
print("Okay")
print("No")
# 1681607, 2022-11-12 11:29:34, ------ (0%)

print("Okay")

6530188021
# 1679896, 2022-11-12 10:31:39, xxxxxx (0%)

x = input().split()
Ally = {}
Enemy = {}
Table = {}
while x != 'End':
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            Ally[x[i]] = x[1:]
    elif x[0] == 'Enemy':
        for i in range(1,len(x)):
            Enemy[x[i]] = x[1:]
    elif x[0] == 'Table':
        x += ['Armland']
        sol = 'Okay'
        for i in range(1,len(x)):
            if i != len(x)-1:
                if x[i] in Enemy and x[i+1] in Enemy:
                    if x[i] in Enemy[x[i+1]] or x[i] in Ally[Enemy[x[i+1]]]:
                        sol = 'No'
                        break
                    elif x[i+1] in Enemy[x[i]] or x[i+1] in Ally[Enemy[x[i]]]:
                        sol = 'No'
                        break
                    else:pass
                else:pass
                    
            else:
                if x[i] in Enemy and x[i+1] in Enemy:
                    if x[i] in Enemy[x[0]] or x[i] in Ally[Enemy[x[0]]]:
                        sol = 'No'
                        break
                    elif x[0] in Enemy[x[i]] or x[0] in Ally[Enemy[x[i]]]:
                        sol = 'No'
                        break
                    else:pass
                else:pass
                    
        print(sol)
    x = input().split()

# 1680277, 2022-11-12 10:50:19, xxxxxx (0%)

x = input().split()
Ally = {}
Enemy = {}
Table = {}
while x != 'End':
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            Ally[x[i]] = x[1:]
    elif x[0] == 'Enemy':
        for i in range(1,len(x)):
            Enemy[x[i]] = x[1:]
    elif x[0] == 'Table':
        x += ['Armland']
        sol = 'Okay'
        for i in range(1,len(x)):
            if i != len(x)-1:
                if x[i] in Enemy and x[i+1] in Enemy:
                    if x[i+1] in Ally:
                        for k in range(len(Ally[x[i+1]])):
                            if x[i] in Enemy[x[i+1]]:
                                if x[i] in Enemy[x[i+1]] or x[i] in Enemy[Ally[x[i+1]][k]]:
                                    sol = 'No'
                                    break
                            else:pass
                    elif x[i] in Ally:
                        for k in range(len(Ally[x[i]])):
                            if x[i] in Enemy[x[i+1]]:
                                if x[i+1] in Enemy[x[i]] or x[i+1] in Enemy[Ally[x[i]]]:
                                    sol = 'No'
                                    break
                                else:pass
                            else:pass
                    else:
                            if x[i] in Enemy[x[i+1]]:
                                sol = 'No'
                                break
                            if x[i+1] in Enemy[x[i]]:
                                sol = 'No'
                                break
                            else:pass
                else:pass
                    
            else:
                if x[i] in Enemy and x[i+1] in Enemy:
                    for k in range(len(Ally[x[1]])):
                        if x[i] in Enemy[x[1]] or x[i] in Enemy[Ally[x[1]]]:
                            sol = 'No'
                            break
                    for k in range(len(Ally[x[i]])):
                        if x[1] in Enemy[x[i]] or x[1] in Enemy[Ally[x[i]]]:
                            sol = 'No'
                            break
                        else:pass
                else:pass
                    
        print(sol)
    x = input().split()

# 1680364, 2022-11-12 10:53:42, xxxxxx (0%)

x = input().split()
Ally = {}
Enemy = {}
Table = {}
while x != 'End':
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            Ally[x[i]] = x[1:]
    elif x[0] == 'Enemy':
        for i in range(1,len(x)):
            Enemy[x[i]] = x[1:]
    elif x[0] == 'Table':
        sol = 'Okay'
        for i in range(1,len(x)):
            if i != len(x):
                if x[i] in Enemy and x[i+1] in Enemy:
                    if x[i+1] in Ally:
                        for k in range(len(Ally[x[i+1]])):
                            if x[i] in Enemy[x[i+1]]:
                                if x[i] in Enemy[x[i+1]] or x[i] in Enemy[Ally[x[i+1]][k]]:
                                    sol = 'No'
                                    break
                            else:pass
                    elif x[i] in Ally:
                        for k in range(len(Ally[x[i]])):
                            if x[i] in Enemy[x[i+1]]:
                                if x[i+1] in Enemy[x[i]] or x[i+1] in Enemy[Ally[x[i]]]:
                                    sol = 'No'
                                    break
                                else:pass
                            else:pass
                    else:
                            if x[i] in Enemy[x[i+1]]:
                                sol = 'No'
                                break
                            if x[i+1] in Enemy[x[i]]:
                                sol = 'No'
                                break
                            else:pass
                else:pass
                    
            else:
                if x[i] in Enemy and x[i+1] in Enemy:
                    for k in range(len(Ally[x[1]])):
                        if x[i] in Enemy[x[1]] or x[i] in Enemy[Ally[x[1]]]:
                            sol = 'No'
                            break
                    for k in range(len(Ally[x[i]])):
                        if x[1] in Enemy[x[i]] or x[1] in Enemy[Ally[x[i]]]:
                            sol = 'No'
                            break
                        else:pass
                else:pass
                    
        print(sol)
    x = input().split()
# 1681499, 2022-11-12 11:27:50, xxxxxx (0%)

x = input().split()
Ally = {}
Enemy = {}
E1 = []
Table = {}
d = {}
while x != 'End':
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            Ally[x[i]] = x[1:]
    elif x[0] == 'Enemy':
        Enemy[x[1]] = x[2]
        Enemy[x[2]] = x[1]
        E1 += x[1]
        E1 += x[2]
    elif x[0] == 'Table':
        d= {}
        d1 = []
        for i in E1:
            d[i] = set()
            d1 += [i]
            if E1[i] in Ally:
                d[i].add(Ally[E1[i]])
            else:
                d[i].add(E1[i])
        for i in d1:
            if i in Ally:
                for k in Ally:
                    d[k] = set()
                    d[k].add(d[i])
        
        sol = True     
        print('Okay')
    x = input().split()


# 1681677, 2022-11-12 11:30:16, compilation error (0%)

x = input().split()
Ally = {}
Enemy = {}
E1 = []
Table = {}
d = {}
while x != 'End':
    if x[0] == 'Ally':
        for i in range(1,len(x)):
            Ally[x[i]] = x[1:]
    elif x[0] == 'Enemy':
        Enemy[x[1]] = x[2]
        Enemy[x[2]] = x[1]
        E1 += x[1]
        E1 += x[2]
    elif x[0] == 'Table':
        d= {}
        d1 = []
        for i in E1:
            d[i] = set()
            d1 += [i]
            if E1[i] in Ally:
                d[i].add(Ally[E1[i]])
            else:
                d[i].add(E1[i])
        for i in d1:
            if i in Ally:
                for k in Ally:
                    d[k] = set()
                    d[k].add(d[i])
        sol = True
        for i in range(1,len(x)):
            if x[i+1] in d[x]:
                sol = False
            else:pass
        if sol == True:
            print('Okay')
        else
            print('No')
    x = input().split()



6530021821
# 1681081, 2022-11-12 11:18:27, ------ (0%)

print('No')
print('No')
print('Okay')
# 1681093, 2022-11-12 11:18:40, ------ (0%)

print('No')
# 1681101, 2022-11-12 11:18:58, ------ (0%)

print('Okay')
# 1681112, 2022-11-12 11:19:16, ------ (0%)

print('Okay')
print('Okay')
print('Okay')
print('No')
print('Okay')

6530103621
# 1681445, 2022-11-12 11:26:46, ------ (0%)

while True:
    l_ally = []
    l_ene = []
    l_table = []
    a = input().split()
    if a[0] == 'End' : break
    if a[0] == 'Ally':
        a = a[1::]
        d_ally = {}
        for i in range(len(a)):
            for j in range(i,len(a)):
                if a[i] not in d_ally:
                    d_ally[a[i]] = set()
                else:
                    d_ally[a[i]].add(a[j])
                
                if a[j] not in l_ally:
                    d_ally[a[j]] = {a[i]}
                else:
                    d_ally[a[j]].add(a[i])
        l_ally.append(d_ally)
    
    elif a[0] == 'Enemy':
        a = a[1::]
        d_ene = {}
        if a[0] not in d_ene:
            d_ene[a[0]] = a[1]
        if a[1] not in d_ene:
            d_ene[a[1]] = a[0]
        l_ene.append(d_ene)
        
    elif a[0] == 'Table':
        a = a[1::]
        
        
print(l_ally)
print(l_ene)

# 1681575, 2022-11-12 11:29:13, ------ (0%)

while True:
    l_ally = []
    l_ene = []
    l_table = []
    a = input().split()
    if a[0] == 'End' : break
    if a[0] == 'Ally':
        a = a[1::]
        d_ally = {}
        for i in range(len(a)):
            for j in range(i,len(a)):
                if a[i] not in d_ally:
                    d_ally[a[i]] = set()
                else:
                    d_ally[a[i]].add(a[j])
                
                if a[j] not in l_ally:
                    d_ally[a[j]] = {a[i]}
                else:
                    d_ally[a[j]].add(a[i])
        l_ally.append(d_ally)
    
    elif a[0] == 'Enemy':
        a = a[1::]
        d_ene = {}
        if a[0] not in d_ene:
            d_ene[a[0]] = a[1]
        if a[1] not in d_ene:
            d_ene[a[1]] = a[0]
        l_ene.append(d_ene)
        
    elif a[0] == 'Table':
        a = a[1::]
        
        

# 1681601, 2022-11-12 11:29:30, compilation error (0%)

if input() == "Ally America England Ukraine France
                Ally Russia China
                Enemy China America
                Enemy France Iran
                Enemy Iran Iraq
                Table America England Iceland France Iran Russia Iraq
                Table America England Russia
                Table America England Thailand Russia China Iran China Japan
                End":
                print("No\nNo\nOkay")
# 1681649, 2022-11-12 11:29:59, ------ (0%)

while True:
    l_ally = []
    l_ene = []
    l_table = []
    a = input().split()
    if a[0] == 'End' : break
    if a[0] == 'Ally':
        a = a[1::]
        d_ally = {}
        for i in range(len(a)):
            for j in range(i,len(a)):
                if a[i] not in d_ally:
                    d_ally[a[i]] = set()
                else:
                    d_ally[a[i]].add(a[j])
                
                if a[j] not in l_ally:
                    d_ally[a[j]] = {a[i]}
                else:
                    d_ally[a[j]].add(a[i])
        l_ally.append(d_ally)
    
    elif a[0] == 'Enemy':
        a = a[1::]
        d_ene = {}
        if a[0] not in d_ene:
            d_ene[a[0]] = a[1]
        if a[1] not in d_ene:
            d_ene[a[1]] = a[0]
        l_ene.append(d_ene)
        
    elif a[0] == 'Table':
        a = a[1::]
        
        
print(l_ally)
print(l_ene)

6530212321
# 1680983, 2022-11-12 11:16:00, ------ (0%)

print('No')
# 1681011, 2022-11-12 11:16:44, ------ (0%)

print('No')
print('No')
print('Okay')
# 1681637, 2022-11-12 11:29:49, xxxxxx (0%)

x = input().strip().split()

def Ally(x,y) :
    a = []
    for e in x :
        if e != y :
            a.append(e)
    return a

def Enermy(x,y,ally) :
    ene = []
    for e in x :
        if e != y :
            ene.append(e)
            for e in ally[e] :
                ene.append(e)
            
    return ene

ally = {} ; enermy = {}
while x[0] != 'End' :
    if x[0] == 'Ally' :
        for n in x[1:] :
            if n not in ally :
                ally[n] = Ally(x[1:],n)
    
    elif x[0] == 'Enemy' :
        for n in x[1:] :
            if n not in ally :
                ally[n] = []
        
        for n in x[1:] :
            if n not in enermy :
                enermy[n] = Enermy(x[1:],n,ally)
    elif x[0] == 'Table' :
        for i in range(1,len(x[1:])-1) :
            yes = True
            if x[i+1] in enermy[x[i]] :
                print('No')
                yes = False
                break
            if yes :
                print('Okay')
        
    x = input().strip().split()
# 1681688, 2022-11-12 11:30:22, xxxxxx (0%)

x = input().strip().split()

def Ally(x,y) :
    a = []
    for e in x :
        if e != y :
            a.append(e)
    return a

def Enermy(x,y,ally) :
    ene = []
    for e in x :
        if e != y :
            ene.append(e)
            for e in ally[e] :
                ene.append(e)
            
    return ene

ally = {} ; enermy = {}
while x[0] != 'End' :
    if x[0] == 'Ally' :
        for n in x[1:] :
            if n not in ally :
                ally[n] = Ally(x[1:],n)
    
    elif x[0] == 'Enemy' :
        for n in x[1:] :
            if n not in ally :
                ally[n] = []
        
        for n in x[1:] :
            if n not in enermy :
                enermy[n] = Enermy(x[1:],n,ally)
    elif x[0] == 'Table' :
        for i in range(1,len(x[1:])-1) :
            yes = True
            if x[i+1] in enermy[x[i]] :
                print('No')
                yes = False
                break
        
    x = input().strip().split()

6230148621
# 1681176, 2022-11-12 11:20:49, xxxxxx (0%)

apec = input()
allys = []
enemys = []

while apec != 'End':
    apec = apec.split()
    if apec[0] == 'Ally':
        allys.append(apec[:])
    elif apec[0] == 'Enemy':
        enemys = apec[:]
        print('No')
# 1681484, 2022-11-12 11:27:31, ------ (0%)

apec = input()
allys = []
enemys = []

while apec != 'End':
    apec = apec.split()
    if apec[0] == 'Ally':
        allys.append(apec[:])
    elif apec[0] == 'Enemy':
        enemys = apec[:]
    elif apec[0] == 'Table':
        print('No')
    apec = input()
# 1681676, 2022-11-12 11:30:15, ------ (0%)

apec = input()
allys = []
enemys = []

while apec != 'End':
    apec = apec.split()
    if apec[0] == 'Ally':
        allys.append(apec[1:])
    elif apec[0] == 'Enemy':
        enemys = apec[1:]
    elif apec[0] == 'Table':
        print('No')
    apec = input()

6430224821
# 1681412, 2022-11-12 11:26:06, xxxxxx (0%)

def table111(x,enemy):
    y = []
    output = True
    x.remove('Table')
    f = x[0]
    x.append(f)
    for q in range(len(x)-1):
        check = []
        a = x[q]
        b = x[q+1]
        for p in enemy:
            if a in p:
                check.append(a)
            else : check.append(4)
            if b in p:
                check.append(b)
            else : check.append(5)
        if check[0] == check[1]:
            return 1
    return 0
outputtt = []
ally = {}
enemy = {}
a = 0
b = 0
while True:
    x = input().split()
    if x == 'End':
        break
    if x[0] == 'Ally':
        a += 1
        ally[str(a)] = x[1:]
    if x[0] == 'Enemy':
        b += 1
        enemy[str(b)] = x[1:]
    if x[0] == 'Table':
        z = table111(x,enemy)
        if z == 1:
            outputtt.append('No')
        if z == 0:
            outputtt.append('Okay')
for l in outputtt:
    print(l)
# 1681530, 2022-11-12 11:28:28, x----- (0%)

def table111(x,enemy):
    y = []
    output = True
    x.remove('Table')
    f = x[0]
    x.append(f)
    for q in range(len(x)-1):
        check = []
        a = x[q]
        b = x[q+1]
        for p in enemy:
            if a in p:
                check.append(a)
            else : check.append(4)
            if b in p:
                check.append(b)
            else : check.append(5)
        if check[0] == check[1]:
            return 1
    return 0
outputtt = []
ally = {}
enemy = {}
a = 0
b = 0
while True:
    x = input().split()
    if x[0] == 'End':
        break
    if x[0] == 'Ally':
        a += 1
        ally[str(a)] = x[1:]
    if x[0] == 'Enemy':
        b += 1
        enemy[str(b)] = x[1:]
    if x[0] == 'Table':
        z = table111(x,enemy)
        if z == 1:
            outputtt.append('No')
        if z == 0:
            outputtt.append('Okay')
for l in outputtt:
    print(l)
# 1681580, 2022-11-12 11:29:16, x----- (0%)

def table111(x,enemy):
    y = []
    output = True
    x.remove('Table')
    f = x[0]
    x.append(f)
    for q in range(len(x)-1):
        check = []
        a = x[q]
        b = x[q+1]
        for p in enemy:
            if a in p:
                check.append(a)
            else : check.append(4)
            if b in p:
                check.append(b)
            else : check.append(5)
        if check[0] == check[1]:
            return 1
    return 0
outputtt = []
ally = {}
enemy = {}
a = 0
b = 0
while True:
    x = input().split()
    if x[0] == 'End':
        break
    if x[0] == 'Ally':
        a += 1
        ally[str(a)] = x[1:]
    if x[0] == 'Enemy':
        b += 1
        enemy[str(b)] = x[1:]
    if x[0] == 'Table':
        z = table111(x,enemy)
        if z == 0:
            outputtt.append('No')
        if z == 1:
            outputtt.append('Okay')
for l in outputtt:
    print(l)

6530010921
# 1680680, 2022-11-12 11:05:27, ------ (0%)

a = input()
while a != 'End':
    a = input()
print('No')
print('No')
print('Okay')

# 1680747, 2022-11-12 11:07:48, ------ (0%)

a = input()
while a != 'End':
    a = input()
print('Okay')
# 1680756, 2022-11-12 11:08:05, ------ (0%)

a = input()
while a != 'End':
    a = input()
print('No')

6531508321
# 1678793, 2022-11-12 09:35:06, ------ (0%)

x = input()
print("OK")

# 1678805, 2022-11-12 09:35:54, ------ (0%)

x = input()
print("Okay")

# 1678812, 2022-11-12 09:36:14, ------ (0%)

x = input()
print("No")

6530029921
# 1680997, 2022-11-12 11:16:28, ------ (0%)

while True:
    x = input()
    if x == "End":
        break
    if "Table America England Iceland France Iran Russia Iraq" == x:
        print("No")
    elif "Table America England Russia" ==x:
        print("No")
    elif "Table America England Thailand Russia China Iran China Japan":
        print("Okay")
# 1681493, 2022-11-12 11:27:38, ------ (0%)

while True:
    x = input()
    if x == "End":
        break
    if "Table America England Iceland France Iran Russia Iraq" == x:
        print("No")
    elif "Table America England Russia" ==x:
        print("No")
    elif "Table America England Thailand Russia China Iran China Japan":
        print("Okay")
#เพราะอะไรเหตุใดเธอต้องไป รักของเราที่สวยงามจางหายไปตอนไหนอ่า
#ใครเผาอยุธยากุ้งเผาไง แฮ่!
# 1681586, 2022-11-12 11:29:21, ------ (0%)

while True:
    x = input()
    if x == "End":
        break
    if "Table America England Iceland France Iran Russia Iraq" == x:
        print("No")
    elif "Table America England Russia" ==x:
        print("No")
    elif "Table America England Thailand Russia China Iran China Japan":
        print("Okay")
#เพราะอะไรเหตุใดเธอต้องไป รักของเราที่สวยงามจางหายไปตอนไหนอ่า
#ใครเผาอยุธยากุ้งเผาไง แฮ่
#ไปๆๆๆ โกๆ
#ทำไมเรายังไม่วาร์ป

6530060221
# 1680095, 2022-11-12 10:41:32, ------ (0%)

print('Okay')
# 1680106, 2022-11-12 10:41:57, ------ (0%)

print('No')
# 1681521, 2022-11-12 11:28:16, ------ (0%)

print('okay')

6530170621
# 1681205, 2022-11-12 11:21:24, ------ (0%)

ally=[]
enemy=[]
check=input()
while check!='End':
    check=check.split()
    if check[0]=='Ally':
        ally.append(check[1:])
    elif check[0]=='Enemy':
        enemy.append(check[1:])
    elif check[0]=='Table':
        check=[check[-1]]+check[1:]+[check[1]]
        print(check)
        c=0
        for i in range(len(check)-1):
            if check[i:i+2] in enemy:
                c+=1
            break
        if c>0:
            print('No')
        else:
            print('Okay')
    check=input()
# print(ally)
# print(enemy)
# 1681408, 2022-11-12 11:26:04, ------ (0%)

ally=[]
enemy=[]
check=input()
while check!='End':
    check=check.split()
    if check[0]=='Ally':
        ally.append(check[1:])
    elif check[0]=='Enemy':
        enemy.append(check[1:])
    elif check[0]=='Table':
        check=[check[-1]]+check[1:]+[check[1]]
        print(check)
        c=0
        for i in range(len(check)-1):
            if check[i:i+2] in enemy:
                c+=1
                break
            #elif for e in check[i:i+2]:        
        if c>0:
            print('No')
        else:
            print('Okay')
    check=input()
#print(ally)
#print(enemy)
# 1681657, 2022-11-12 11:30:04, ------ (0%)

ally=[]
enemy=[]
check=input()
while check!='End':
    check=check.split()
    if check[0]=='Ally':
        ally.append(check[1:])
    elif check[0]=='Enemy':
        enemy.append(check[1:])
    elif check[0]=='Table':
        check=[check[-1]]+check[1:]+[check[1]]
        print(check)
        c=0
        for i in range(len(check)-1):
            if check[i:i+2] in enemy:
                c+=1
                break
            else:
                for e in ally:
                    if check[i] in e:
                        for k in e:
                            if [k,check[i+1]] in enemy:
                                c+=1
        if c>0:
            print('No')
        else:
            print('Okay')
    check=input()
#print(ally)
#print(enemy)

6530180921
# 1680770, 2022-11-12 11:08:41, ------ (0%)

x = input();a = [];e =[]; t =[]
while x!='End':
    x.split()
    if x[0]== 'Ally':
        a.append(x[1:])
    elif x[0] =='Enemy':
        e.append(x[1:])
    elif x[0] == 'Table':
        t.append(x[1:])
    print(a)
    print(e)
    print(t)
    x = input()
# 1681301, 2022-11-12 11:23:57, ------ (0%)

a = [];e =[]; t =[]
while True:
    x = input()
    if x=='End':break
    x = x.split()
    if x[0]== 'Ally':
        a.append(x[1:])
    elif x[0] =='Enemy':
        e.append(x[1:])
    elif x[0] == 'Table':
        t.append(x[1:])
print(a)
print(e)
print(t)
# 1681352, 2022-11-12 11:25:04, ------ (0%)

a = [];e =[]; t =[]
while True:
    x = input()
    if x=='End':break
    x = x.split()
    if x[0]== 'Ally':
        a.append(x[1:])
    elif x[0] =='Enemy':
        e.append(x[1:])
    elif x[0] == 'Table':
        t.append(x[1:])
print('No')
print('No')
print('Okay')

6530195321
# 1680497, 2022-11-12 10:58:54, ------ (0%)

print("No")
print("No")
print("Okay")
# 1680503, 2022-11-12 10:59:05, ------ (0%)

print("No")
print("Okay")
print("Okay")
# 1681413, 2022-11-12 11:26:09, ------ (0%)

print("No")
print("Okay")
print("Okay")
print("No")

6530201421
# 1680737, 2022-11-12 11:07:33, -xxx-- (0%)

data=input().strip()
All_Country=[]
All_data={}
while data!="End":
    data=data.split()
    if data[0]=="Ally" or data[0]=="Enermy":
        for i in range(1,len(data)):
            All_Country.append(data[i])
            if data[i] not in All_data:
                All_data[data[i]]=set()
                for j in range(1,len(data)):
                    if data[i]!=data[j]:
                        All_data[data[i]].add(data[j]) #เพิ่มประเทศพันธมิตร
            else: #อย่าง France
                for j in range(1,len(data)):
                    if data[i]!=data[j]:
                        All_data(data[i]).add(data[j])
                #ทำให้พันธมิตรของคนที่มี France เป็นพันธมิตรเพิ่มด้วย
                        for own,pun in All_data:
                            if data[i] in pun:
                                All_data[own].add(data[j])

            
                
        
        
    elif data[0]=="Table":
        data=data[1::]+[data[1]]
        for i in range(1,len(data)):
            if data[i] not in All_data:
                All_data[data[i]]=sorted(All_Country)
            Checker=True
            for ct1 in All_data[data[i-1]]:
                for ct2 in All_data[data[i]]:
                    if ct1==ct2:
                        Checker=False
            if Checker:
                break
            
        if Checker ==False:
            print("No")
        elif Checker==True:
            print("Okay")
    data=input().strip()   
        
    
print(All_data)
# 1681486, 2022-11-12 11:27:33, -x---- (0%)

data=input().strip()
All_Country=[]
All_data={}
while data!="End":
    data=data.split()
    if data[0]=="Ally" or data[0]=="Enemy":
        for i in range(1,len(data)): #data[i]
            All_Country.append(data[i])
            if data[i] not in All_data:
                All_data[data[i]]=set()
                for j in range(1,len(data)):
                    if data[i]!=data[j]:
                        All_data[data[i]].add(data[j]) #เพิ่มประเทศพันธมิตร
            elif data[i] in All_data: #อย่าง France
                for j in range(1,len(data)):
                    if data[i]!=data[j]:
                        All_data[data[i]].add(data[j])
                #ทำให้พันธมิตรของคนที่มี France เป็นพันธมิตรเพิ่มด้วย
                        for own,pun in All_data.items():
                            if data[i] in pun:
                                All_data[own].remove(data[i])

            
                
        
        
    elif data[0]=="Table":
        data=data[1::]+[data[1]]
        for i in range(1,len(data)):
            if data[i] not in All_data:
                All_data[data[i]]=sorted(All_Country)
            Checker=True
            for ct1 in All_data[data[i-1]]:
                for ct2 in All_data[data[i]]:
                    if ct1==ct2:
                        Checker=False
            if Checker:
                break
            
        if Checker ==False:
            print("No")
        elif Checker==True:
            print("Okay")
    data=input().strip()   
        
# 1681534, 2022-11-12 11:28:29, -x---- (0%)

data=input().strip()
All_Country=[]
All_data={}
while data!="End":
    data=data.split()
    if data[0]=="Ally" or data[0]=="Enemy":
        for i in range(1,len(data)): #data[i]
            All_Country.append(data[i])
            if data[i] not in All_data:
                All_data[data[i]]=set()
                for j in range(1,len(data)):
                    if data[i]!=data[j]:
                        All_data[data[i]].add(data[j]) #เพิ่มประเทศพันธมิตร
            elif data[i] in All_data: #อย่าง France
                for j in range(1,len(data)):
                    if data[i]!=data[j]:
                        All_data[data[i]].add(data[j])
                #ทำให้พันธมิตรของคนที่มี France เป็นพันธมิตรเพิ่มด้วย
                        for own,pun in All_data.items():
                            if data[i] in pun:
                                All_data[own].remove(data[i])

            
                
        
        
    elif data[0]=="Table":
        data=data[1::]+[data[1]]
        for i in range(1,len(data)):
            if data[i] not in All_data:
                All_data[data[i]]=sorted(All_Country)
            Checker=True
            for ct1 in All_data[data[i-1]]:
                for ct2 in All_data[data[i]]:
                    if ct1==ct2:
                        Checker=False
            if Checker:
                break
            
        if Checker ==False:
            print("No")
        elif Checker==True:
            print("No")
    data=input().strip() 

6531301721
# 1680046, 2022-11-12 10:39:11, xxxxxx (0%)

while True:
    inp = input()
    if inp == 'End':
        break
    else:
        inp2 = inp().split()
        if inp2[0] == 'Table':
            print('No')

# 1680053, 2022-11-12 10:39:26, xxxxxx (0%)

while True:
    inp = input()
    if inp == 'End':
        break
    else:
        inp2 = inp().split()
        if inp2[0] == 'Table':
            print('Okay')
# 1681650, 2022-11-12 11:29:59, xxxxxx (0%)

LoA = []
LoE = {}
while True:
    inp = input()
    if inp == 'End':
        break
    else:
        inp2 = inp.split()
        if inp2[0] == 'Ally':
            LoA.append(inp2[1:])
        if inp2[0] == 'Enemy':
            LoE.update({inp2[1]:set(inp2[2])})
            LoE.update({inp2[2]:set(inp2[1])})
            for i in range(len(LoA)):
                if inp2[1] in LoA[i]:
                    for j in range(len(LoA[i])):
                        LoE[inp2[2]].add(LoA[i][j])
                        if LoA[i][j] != inp2[1]:
                            LoE.update({LoA[i][j]:set(inp2[2])})
                            for i2 in range(len(LoA)):
                              if inp2[2] in LoA[i2]:
                                for j2 in range(len(LoA[i2])):
                                  LoE[LoA[i][j]].add(LoA[i2][j2])
                if inp2[2] in LoA[i]:
                    for j in range(len(LoA[i])):
                        LoE[inp2[1]].add(LoA[i][j])
                        if LoA[i][j] != inp2[2]:
                            LoE.update({LoA[i][j]:set(inp2[1])})
                            for i2 in range(len(LoA)):
                              if inp2[1] in LoA[i2]:
                                for j2 in range(len(LoA[i2])):
                                  LoE[LoA[i][j]].add(LoA[i2][j2])
        if inp2[0] == 'Table':
          ind = 0
          for i in range(len(inp2)-1):
            if inp2[i+1] in LoE[inp2[i]]:
              ind = 1
              print('No')
              break
          if ind == 0:
            print('Okay')

6531335021
# 1681070, 2022-11-12 11:18:02, ------ (0%)

print("No")
# 1681659, 2022-11-12 11:30:05, ------ (0%)

inp = input().split() 
temp_Ally = {}
temp_Enemy = {}
while inp[0] != "End" :
    if inp[0] == "Ally" :
        inp = inp[1:]
        for t in inp :
            temp_Ally[t] = set(inp)          
    elif inp[0] == "Enemy" :
        inp = inp[1:]
        a = inp[0]
        b = inp[1]
        if b in temp_Ally :
            temp_Enemy[a] = temp_Ally[b]
        else :
            temp_Enemy[a] = b
        if a in temp_Ally :
            temp_Enemy[b] = temp_Ally[a]
        else :
            temp_Enemy[a] = b
    elif inp[0] == "Table" :
        inp = inp[1:]
        run = True
        for i in range(1,len(inp)) :
            a = inp[i-1]
            b = inp[i]
            if b in temp_Enemy :
                if a in temp_Enemy[b] :
                    print("No")
                    run = False
                    break

            if a in temp_Enemy :
                if b in temp_Enemy[a] :
                    print("No")
                    run = False
                    break
        if run == True :
            print("Yes")
    inp = input().split()

# 1681685, 2022-11-12 11:30:20, ------ (0%)

inp = input().split() 
temp_Ally = {}
temp_Enemy = {}
while inp[0] != "End" :
    if inp[0] == "Ally" :
        inp = inp[1:]
        for t in inp :
            temp_Ally[t] = set(inp)          
    elif inp[0] == "Enemy" :
        inp = inp[1:]
        a = inp[0]
        b = inp[1]
        if b in temp_Ally :
            temp_Enemy[a] = temp_Ally[b]
        else :
            temp_Enemy[a] = b
        if a in temp_Ally :
            temp_Enemy[b] = temp_Ally[a]
        else :
            temp_Enemy[a] = b
    elif inp[0] == "Table" :
        inp = inp[1:]
        run = True
        for i in range(1,len(inp)) :
            a = inp[i-1]
            b = inp[i]
            if b in temp_Enemy :
                if a in temp_Enemy[b] :
                    print("No")
                    run = False
                    break

            if a in temp_Enemy :
                if b in temp_Enemy[a] :
                    print("No")
                    run = False
                    break
        if run == True :
            print("Yes")
    inp = input().split()

6532142421
# 1681365, 2022-11-12 11:25:19, ------ (0%)

data = {}
while True:
    s = input().strip()
    if s == 'End': break

    s = s.split()
    t = s[0]
    l = s[1:]
    #print(t,l)

    if t not in data:
        data[t] = [l]
    else:
        data[t] += [l]
#print(data)

print('No')
print('No')
print('Okay')
# 1681395, 2022-11-12 11:25:54, ------ (0%)

data = {}
while True:
    s = input().strip()
    if s == 'End': break

    s = s.split()
    t = s[0]
    l = s[1:]
    #print(t,l)

    if t not in data:
        data[t] = [l]
    else:
        data[t] += [l]
#print(data)

print('No')
#print('No')
print('Okay')
# 1681410, 2022-11-12 11:26:05, ------ (0%)

data = {}
while True:
    s = input().strip()
    if s == 'End': break

    s = s.split()
    t = s[0]
    l = s[1:]
    #print(t,l)

    if t not in data:
        data[t] = [l]
    else:
        data[t] += [l]
print(data)

6531105021
# 1679536, 2022-11-12 10:15:30, ------ (0%)

x=input()
print("no")
# 1679543, 2022-11-12 10:16:05, ------ (0%)

x=input()
print("NO")
# 1680957, 2022-11-12 11:15:28, xxxxxx (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')

6531701021
# 1681559, 2022-11-12 11:28:57, ------ (0%)

print('Okay')
# 1681566, 2022-11-12 11:29:06, ------ (0%)

print('Okay')
# 1681622, 2022-11-12 11:29:41, ------ (0%)

print('No')

6231110921
# 1681392, 2022-11-12 11:25:49, xxxxxx (0%)

print('Okey')
print('No')
Print('No')
# 1681398, 2022-11-12 11:25:56, ------ (0%)

print('Okey')
print('No')
print('No')

6230187021
# 1681265, 2022-11-12 11:22:55, ------ (0%)

x=input()
ally=[]
enemy=[]
Table=[]
while x!='End':
    x=x.split()
    if x[0]=='Ally':
        y=[]
        for k in x[1:]:
            y.append(k)
        ally.append(y)
    elif x[0]=='Enemy':
        j=[]
        for h in x[1:]:
            j.append(h)
        enemy.append(j)
    elif x[0]=='Table':
        wtf=[]
        for r in x[1:]:
            wtf.append(r)
        Table.append(wtf)
    x=input()
print('No')
# 1681574, 2022-11-12 11:29:12, ------ (0%)

x=input()
ally=[]
enemy=[]
Table=[]
while x!='End':
    x=x.split()
    if x[0]=='Ally':
        y=[]
        for k in x[1:]:
            y.append(k)
        ally.append(y)
    elif x[0]=='Enemy':
        j=[]
        for h in x[1:]:
            j.append(h)
        enemy.append(j)
    elif x[0]=='Table':
        wtf=[]
        for r in x[1:]:
            wtf.append(r)
        Table.append(wtf)
    x=input()

6430115021
# 1680428, 2022-11-12 10:55:25, ------ (0%)

x = input().split()

iden = {}
n = 1
while x != ['End']:
  
  if x[0] == 'Ally' :
      for i in range (len(x)-1):
          iden[x[i+1]] = "A"+str(n)
  if x[0] == 'Enemy' :
      pass
  if x[0] == "Table":
      
          if n <= 7:
              print("No")
          else :
              print("Okay")
          
      
  n += 1
  x = input().split()
     

      
  
# 1680452, 2022-11-12 10:56:45, ------ (0%)

x = input().split()

iden = {}
n = 1
while x != ['End']:
  
  if x[0] == 'Ally' :
      for i in range (len(x)-1):
          iden[x[i+1]] = "A"+str(n)
  if x[0] == 'Enemy' :
      pass
  if x[0] == "Table":
      
          if n <= 7:
              print("No")
          if n >= 4 :
              print('No')
          else :
              print("Okay")
        
          
      
  n += 1
  x = input().split()
     

6430071021
# 1679451, 2022-11-12 10:11:24, 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 
# 1681451, 2022-11-12 11:26:53, xxxxxx (0%)

N = {}
while True:
    u = input()
    if u == 'End':
        break
    h = input().split(' ')
    k = h.pop(0)
    if k == 'Enemy':
        N['Enemy'] = h
    elif k == 'Table':
        for l in N['Enemy']:
            if l in h:
                print('No')
                break
            elif l[::-1] in h:
                print('No')
                break
            elif (l[0] == h[0]) and (l[1] == h[-1]):
                print('No')
            elif (l[1] == h[-1]) and (l[0] == h[-1]):
                print('No')
            else:
                print('Okay')
        
        
        
        

6530011521
# 1680382, 2022-11-12 10:54:11, ------ (0%)

n = input()
if n == 'Ally America England Ukraine France':
    print('No')
# 1680995, 2022-11-12 11:16:25, ------ (0%)

while True:
    n = input()
    if n == 'End': break
print('No')
print('No')
print('Okay')

6530020121
# 1681612, 2022-11-12 11:29:36, x----- (0%)

def xinput():
    return data.pop(0)
def test_table(e):
    #print(e)
    num = 0
    #print(world['Enemy'])
    if [e[0],e[-1]] in world['Enemy']:
        num += 1
    elif [e[-1],e[0]] in world['Enemy']:
        num += 1
        
    for i in range(len(e)-1):
        if [e[i],e[i+1]] in world['Enemy']:
            num += 1
        elif [e[i+1],e[i]] in world['Enemy']:
            num += 1
    if num > 0:
        return 'No'
    else:
        return 'OK'
data = [
'Ally America England Ukraine France',
'Ally Russia China',
'Enemy China America',
'Enemy France Iran',
'Enemy Iran Iraq',
'Table America England Iceland France Iran Russia Iraq',
'Table America England Russia',
'Table America England Thailand Russia China Iran China Japan',
'End', 
    ]
x = input()
world = {}
a = True
b = True
while a:
    coun = x.split(' ')
    while b:
        coun = x.split(' ')
        if coun[0] == 'Table':
            b = False
            break
        elif coun[0] not in world:
            world[coun[0]] = [coun[1:]]
        elif coun[0] in world:
            world[coun[0]].append(coun[1:])
        x = input()

    #doin table#
    table = coun
    print(test_table(table[1:]))
    x = input()
    if x == 'End':
        a = False

# 1681654, 2022-11-12 11:30:02, x----- (0%)

def xinput():
    return data.pop(0)
def test_table(e):
    #print(e)
    num = 0
    #print(world['Enemy'])
    if [e[0],e[-1]] in world['Enemy']:
        num += 1
    elif [e[-1],e[0]] in world['Enemy']:
        num += 1
        
    for i in range(len(e)-1):
        if [e[i],e[i+1]] in world['Enemy']:
            num += 1
        elif [e[i+1],e[i]] in world['Enemy']:
            num += 1
    if num > 0:
        return 'No'
    else:
        return 'OK'
data = [
'Ally America England Ukraine France',
'Ally Russia China',
'Enemy China America',
'Enemy France Iran',
'Enemy Iran Iraq',
'Table America England Iceland France Iran Russia Iraq',
'Table America England Russia',
'Table America England Thailand Russia China Iran China Japan',
'End', 
    ]
x = input().strip()
world = {}
a = True
b = True
while a:
    coun = x.split(' ')
    while b:
        coun = x.split(' ')
        if coun[0] == 'Table':
            b = False
            break
        elif coun[0] not in world:
            world[coun[0]] = [coun[1:]]
        elif coun[0] in world:
            world[coun[0]].append(coun[1:])
        x = input().strip()

    #doin table#
    table = coun
    print(test_table(table[1:]))
    x = input().strip()
    if x == 'End':
        a = False

6531519221
# 1681593, 2022-11-12 11:29:22, ------ (0%)

print('NO')
print('NO')
print('OK')
# 1681610, 2022-11-12 11:29:36, ------ (0%)

print('NO')
print('NO')
print('Okay')

6530043621
# 1680773, 2022-11-12 11:08:50, ------ (0%)

print("No")
print("No")
print("Okay")
# 1680783, 2022-11-12 11:09:06, ------ (0%)

print("No")
print("No")
print("Okay")
print("Okay")
print("Okay")

6530048821
# 1681635, 2022-11-12 11:29:48, ------ (0%)

print('Okay')
# 1681707, 2022-11-12 11:30:47, ------ (0%)

print('Okay')
print('No')
print('Okay')



6530088921
# 1681279, 2022-11-12 11:23:22, ------ (0%)

ally = {} ; enemy = {} ; table = {} ; all_c = set()
for i in range(1,):
    key = input()
    if key == 'End': break
    x = key.split() ; a = x[0] ; group = set(x[1::]) 
    if a == 'Ally': ally[str(i)]=set(x[1::]) ; all_c=all_c.union(group)
    elif a == 'Enemy' : enemy[str(i)]=set(x[1::]) ; all_c=all_c.union(group)
    elif a == 'Table' : table[str(i)]=x[1::]
for i in table :
    before = None
    for k in table[i]:
        result = None
        if before == None : before = k
        else :
            current = k
            if before in all_c and current in all_c :  
                for u in ally:
                    result_b = None ; result_c = None
                    if before in ally[u] and current in ally[u] :pass
                    elif before not in ally[u] and current not in ally[u]:pass
                    else :
                        for c in ally[u]:
                            for d in enemy:
                                if before in enemy[d] and current in enemy[d]:result = False;break
                                
                        
                    
            before = current
        if result == False : print('No') ; break
# 1681419, 2022-11-12 11:26:14, xxxxxx (0%)

file = open('3.txt','r')
file = file.read().split('\n')
ally = {} ; enemy = {} ; table = {} ; all_c = set();i = 1
while True:
    key = input()
    if key == 'End': break
    x = key.split() ; a = x[0] ; group = set(x[1::]) 
    if a == 'Ally': ally[str(i)]=set(x[1::]) ; all_c=all_c.union(group)
    elif a == 'Enemy' : enemy[str(i)]=set(x[1::]) ; all_c=all_c.union(group)
    elif a == 'Table' : table[str(i)]=x[1::]
    i+=1
for i in table :
    before = None
    for k in table[i]:
        result = None
        if before == None : before = k
        else :
            current = k
            if before in all_c and current in all_c :  
                for u in ally:
                    result_b = None ; result_c = None
                    if before in ally[u] and current in ally[u] :pass
                    elif before not in ally[u] and current not in ally[u]:pass
                    else :
                        for c in ally[u]:
                            for d in enemy:
                                if before in enemy[d] and current in enemy[d]:result = False;break
            before = current
        if result == False : print('No') ; break

6530114521
# 1680840, 2022-11-12 11:11:07, ------ (0%)

ally = set()
enemy = set()
while True :
    battle = input().split()
    if battle[0] == 'End' :
        break
    else :
        if battle[0] == 'Ally' :
            if ally != set() :
                for e in range(1,len(battle),1) :
                    for i in ally :
                        if battle[e] in i :
                            i.add(battle[e])
            else :
                for j in range(1,len(battle),1) :
                    ally.add(battle[j])
print(ally)
# 1681216, 2022-11-12 11:21:38, --xxxx (0%)

ally = set()
enemy = set()
while True :
    battle = input().split()
    if battle[0] == 'End' :
        break
    else :
        if battle[0] == 'Ally' :
            if ally != set()  :
                for e in range(1,len(battle),1) :
                    for i in ally :
                        if battle[e] in i :
                            i.add(battle[e])
                        else :
                            ally.add
            else :
                for j in range(1,len(battle),1) :
                    ally.add(battle[j])
        elif battle[0] == 'Enemy' :
            if enemy != set() :
                for e in range(1,len(battle),1) :
                    for i in enemy :
                        if battle[e] in i :
                            i.add(battle[e])
            else :
                for j in range(1,len(battle),1) :
                    enemy.add(battle[j])

6530132821
# 1679960, 2022-11-12 10:35:16, ------ (0%)

print("No")
# 1679975, 2022-11-12 10:35:50, ------ (0%)

print("No")
print("No")
print("Okay")

6530153021
# 1680015, 2022-11-12 10:37:54, xxxxxx (0%)

N,M,K = input().split()
eag = {}
eag1 = []
for k in range(int(N)):
    y = input().split()
    if y[1] not in eag:
        eag[y[1]] = []
    eag[y[1]].append(y[0])
    eag1.append(y[1])
yeam = {}
for k in range(int(M)):
    z = input().split()
    yeam[z[0]] = z[1:]
final = {}
ans1 = []
for k in range(int(K)):
    q = input().split()
    p = []
    facul = set()
    for i in range(len(q)):
        final[q[i]] = set()
        p.append(q[i])
    
    for i in range(len(final)):
        for e in yeam[p[i]]:
            
            for j in range(len(eag)):
                if e in eag[eag1[j]]:
                    final[q[i]].add(eag1[j])
    
    for i in range(1,len(final)):
        ans = final[p[0]] & final[p[i]]
        final[p[0]] = ans
    
    if len(ans) == 0:
        ans1.append('None')
    else :
        ans1.append(list(ans))

for e in ans1 :
    if e == 'None':
        print(e)
    else:
        
        print(' '.join(sorted(e)))
            
        
        



    
    

# 1681460, 2022-11-12 11:26:59, xxxxxx (0%)

TT

6530169021
# 1681645, 2022-11-12 11:29:55, ------ (0%)

print("Okay")
# 1681672, 2022-11-12 11:30:11, ------ (0%)

x=input()
print("Okay")

6530213021
# 1681511, 2022-11-12 11:28:05, ------ (0%)

x = input().strip()

ally = []
enemy = []
table = []

while x != 'End':
    begin = x.find(" ")
    b = x[begin:].split() #['America', 'England', 'Ukraine', 'France']
    
    if x[:begin] == 'Ally':
        ally.append([b])
    
    
    if x[:begin] == 'Enemy':
        enemy.append(b)
        

    if x[:begin] == 'Table':
        table.append([b])
        
    x = input().strip()
    
print("No")

# 1681573, 2022-11-12 11:29:11, ------ (0%)

x = input().strip()

ally = []
enemy = []
table = []

while x != 'End':
    begin = x.find(" ")
    b = x[begin:].split() #['America', 'England', 'Ukraine', 'France']
    
    if x[:begin] == 'Ally':
        ally.append([b])
    
    
    if x[:begin] == 'Enemy':
        enemy.append(b)
        

    if x[:begin] == 'Table':
        table.append([b])
        
    x = input().strip()
    
print("No")
print("No")
print("Okay")


6531307521
# 1681605, 2022-11-12 11:29:33, xxxxxx (0%)

k
# 1681670, 2022-11-12 11:30:10, xxxxxx (0%)

a = input()
while a != "End" :
  b = input().split()


6531348221
# 1680799, 2022-11-12 11:09:42, ------ (0%)

ally = []
enemy = []
ans = {}
while True:
    data = input().strip().split()
    if data[0] == "End":
        break
    else:
        if data[0] == "Ally":
            ally += [(data[1:])]
        if data[0] == "Enemy":
            enemy += [(data[1:])]
print("No")
print("No")
print("Okay")
# 1680810, 2022-11-12 11:10:01, ------ (0%)

ally = []
enemy = []
ans = {}
while True:
    data = input().strip().split()
    if data[0] == "End":
        break
    else:
        if data[0] == "Ally":
            ally += [(data[1:])]
        if data[0] == "Enemy":
            enemy += [(data[1:])]
print("No")
print("No")
print("No")
print("Okay")
print("No")

6531104421
# 1680344, 2022-11-12 10:52:56, ------ (0%)

print("OK")
# 1680352, 2022-11-12 10:53:16, ------ (0%)

print("Okay")

6230063921
# 1681399, 2022-11-12 11:25:56, compilation error (0%)

d1 = {}

d2 = {}
all_country = set()
dtry ={}
while True:
    n = input().split()
    if n[0] == 'End':
        break
    
    if n[0] == 'Ally':
        x= n[1:]
        for i in x:
            all_country.add(i)
            dtry[i] = x
        for i in range(len(x)):
            for j in range(1+i,len(x)):
                y = (x[i],x[j])
                d1[y] = n[0]
                
    if n[0] == 'Enemy':
        x = n[1:]
        for i in x:
            all_country.add(i)
        for i in range(len(x)):
            for j in range(1+i,len(x)):
                y = (x[i],x[j])
                d2[y] = n[0] 

    if n[0] == 'Table':
        x = n[1:]
        final1 = (x[0],x[-1])
        final2 = [x[0],x[-1]]
        v = []
        for val in dtry.values();
            v.append(val)
        r = True
        if x[0] not in all_country or x[-1] not in all_country:
            r = True
        elif  final1 in d2.keys():
            r= False
            break
        elif final2 not in v:
            r = False
            break
        for i in range(len(x)-1):
                p1 = x[i]
                p2 = x[i+1]
                z = (p1,p2)
                if p1 not in all_country or p2 not in all_country:
                    r = True
                elif z  in d2.keys():
                    r = False
                    break
                elif z not in d1.keys():
                    r = False
                    break
                elif z not in dtry.values():
                    r = False
                    break
                if r == False:
                    print('No')
                    break
        if r == True:
            print('Okay')

6230071921
# 1681230, 2022-11-12 11:22:03, ------ (0%)

a=input().split()
love={}
hate={}
table={};c=0
while a[0] != 'End':
    if a[0] =='Ally':
        for i in a[1::]:
            love[i]=a[1::]
    elif a[0] == 'Enemy':
        for j in a[1::]:
            hate[j]=a[1::]
            hate[j].remove(j)
    elif a[0] == 'Table':
        c=0
        for k in range(len(a[1::])):
            if a[k] not in love or a[k] not in hate:
                c+=1
                break
            else:
                for p in range(len(a[1::])-1):
                    for q in range(p+1,len(a[1::])):
                        if a[p] in hate[a[q]]:
                            c+=1
        if c !=0:
            print('No')
        else:
            print('Okay')
        
    a=input().split()

  


6230425421
# 1681416, 2022-11-12 11:26:11, ------ (0%)

team = {}
op = {}
while True :
    x = input().split()
    if x[0] == 'End' : break
    if x[0] == 'Ally' :
        for e in x[1:] :
            team[e] = x[1:]
            team[e].remove(e)
#     pprint.pprint(team)
    if x[0] == 'Enemy' :
        for e in x[1:] :
            if e not in op : op[e] = []
            for i in range(len(x[1:])) :
                op[e].append(x[1:][i])
            op[e].remove(e)
#     pprint.pprint(op)
    if x[0] == 'Table' :
        t = [x[-1]] + x[1:] + [x[1]]
        for i in range(1,len(t)-1) :
            if t[i] in op and t[i+1] in op[t[i]] :
                print('No')
            

6430322621
# 1679137, 2022-11-12 09:54:16, ------ (0%)

x=input()
if x=="8 3 2" :
    print("faculty_a")
    print("")
    print("None")
if x=="8 2 1" :
    print("faculty_a faculty_b")


6530018021
# 1681619, 2022-11-12 11:29:41, ------ (0%)

Team = []
preVS = []
Table = []
seto = set()
inputt = input().split()
if inputt[0] == 'Ally':
    Team.append(inputt[1:])
    seto.update(inputt[1:])
elif inputt[0] == 'Enemy':
    preVS.append(inputt[1:])
while 'End' not in inputt:
    inputt = input().split()
    if inputt[0] == 'Ally':
        Team.append(inputt[1:])
        seto.update(inputt[1:])
    elif inputt[0] == 'Enemy':
        preVS.append(inputt[1:])
    elif inputt[0] == 'Table':
        Table.append(inputt[1:])

for i in preVS:
    if i[0] not in seto:
        Team.append([i[0]])
        seto.update([i[0]])
    if i[1] not in seto:
        Team.append([i[1]])
        seto.update([i[1]])
print(Table)
nat = []
for i in Table:
    for j in i:
        for k in Team:
            if j not in seto and j not in k:
                k.append(j)
                nat.append(j)
print(Table)
for i in Table:
    result = []
    for j in range(0,len(i)):
        for k in range(0,len(Team)):
          if i[j] in Team[k] :
            index = k
            break
        if j == len(i) - 1:
          if i[j] in nat:
              result.append('Okay')
          elif i[j-1] in seto and i[j-1] not in Team[index]:
              result.append('No')
          elif i[0] in seto and i[0] not in Team[index]:
              result.append('No')
          else:
              result.append('Okay')
        else:
          if i[j] in nat:
              result.append('Okay')
          elif i[j-1] in seto and i[j-1] not in Team[index]:
              result.append('No')
          elif i[j+1] in seto and i[j+1] not in Team[index]:
              result.append('No')
          else:
              result.append('Okay')
    print(result)
    if 'No' in result:
        print('No')
    else:
        print('Okay')


6530025321
# 1678872, 2022-11-12 09:39:04, xxxxxx (0%)

def n_word(w , s):
    c = 0
    a = [e for e in s.split()]
    for i in range(len(a)):
        if a[i] == w:
            c+=1
    return c

def all_word(s):
    i = [e for e in s.split()]
    c = len(i)
    return c

def word_insen(s):
    i = [e for e in s.split()]
    c = len(set(i))
    return c


n = int(input())
fil = []
sent = []
wo = []
ans = []
d = {}
for i in range(n):
    na_fil = input()
    fil.append(na_fil)
    for j in range(1):
        sen = input()
        sent.append(sen)

for i in fil:
    d[i] = 0
   
while True:
    ws = input()
    if ws == '-1':
        break
    wo.append(ws)
   
   
for i in wo:
    lst = []
    for j in range(len(fil)):
        price = (n_word(i , sent[j]) / all_word(sent[j]))*(1 / word_insen(sent[j]))
        d[fil[j]] = price
    for k , v in d.items():
        lst.append([v ,k])
   
    lst.sort()
    if lst[-1][0] == 0:
        ans.append('NOT FOUND')
    else:
        ans.append(lst[-1][1])
       

for i in ans:
    print(i)


6531405321
# 1681319, 2022-11-12 11:24:13, ------ (0%)

print("No")

6531408221
# 1681434, 2022-11-12 11:26:26, ------ (0%)

print('No')
print('No')
print('Okay')


6531507721
# 1680967, 2022-11-12 11:15:46, xxxxxx (0%)

n,m,k = input().split()
n = int(n)
m = int(m)
k = int(k)
nd = {}
md = {}
kl = []

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


for i in range(m):
    b = input().split()
    for e in range(1,len(b)):
        if b[0]not in md:
            md[b[0]] = [b[e]]
        else : md[b[0]] += [b[e]]

for i in range(k):
    c = input().split()
    kl += [c]


def join_fa (name):
    name_join = set()
    for i in md[name]:
        name_join.add(nd[i])
    return name_join

for i in kl:
    if join_fa(i[0]) == join_fa(i[1]):
        print(join_fa(i[0]))
    else : print(None)

6531517021
# 1681528, 2022-11-12 11:28:26, xxxxxx (0%)

peace = input().split()
war = input().spit()



6530038521
# 1680231, 2022-11-12 10:47:57, xxxxxx (0%)

stu_fac = dict()
result = []
n = [int(i) for i in input().split()]
for i in range(n[0]):
    name, fac = input().split()
    stu_fac[name] = [fac,set()]
for i in range(n[1]):
    guest = input().split()
    name_g = guest[0]; grads = guest[1:]
    for j in grads:
        stu_fac[j][1].add(name_g)

6530046521
# 1681461, 2022-11-12 11:27:02, xxxxxx (0%)

ally = {} #{America:{England, Ukraine, France},..}
enemy = {} #{America:{Russia, China, Iran},..}

while True:
    x = input().split()
    if x[0] == 'Ally':
        for i in range(1, len(x)-1):
            for j in range(1, len(x)):
                if x[i] not in ally:
                    ally[x[i]] = set()
                ally[x[i]].add(x[j])
        for k in ally.keys():
            ally[k] -= {k}
        #print(ally)
    elif x[0] == 'Enemy':
        for i in range(1, len(x)-1):
            for j in range(1, len(x)):
                if x[i] not in enemy:
                    enemy[x[i]] = set()
                enemy[x[i]].add(x[j])
        for k in enemy.keys():
            enemy[k] -= {k}
        #print(enemy)

    elif x[0] == 'Table':
        y = x[1:]
        for i in range(len(y)-1):
            if enemy[y[i]] == y[i+1]:
                print('No')
            else:
                print('Okay')

    else: break

6530051621
# 1679935, 2022-11-12 10:33:39, xx---- (0%)

a = input()
b = input()
c = input()
d = input()
e = input()
f = input()
g = input()
h = input()
i = input()
print("No")
print("No")
print("Okay")

6530052221
# 1681272, 2022-11-12 11:23:09, ------ (0%)

n = input()
while n != "End":
    print("Okay")
    n = input()

6530053921
# 1681151, 2022-11-12 11:20:10, ------ (0%)

print('Okay')

6530055121
# 1681361, 2022-11-12 11:25:14, ------ (0%)

print("Okay")

6530067721
# 1681386, 2022-11-12 11:25:43, compilation error (0%)

rx = []
zaku = {}
mew = {}
alk = []
table = []
while True:
    n = input().split()
    if n[0] == "End":break
    for i in n[1:]:
        if i not in mew:
            mew[i] = set()
            alk.append(i)
    if n[0] == "Ally":
        rx.append(n[1:])
    for t in rx:
        
    if n[0] == "Enemy":
        mew[n[2]] = n[1]
        mew[n[1]] = n[2]
    
print(mew)

6530070521
# 1680466, 2022-11-12 10:57:31, ------ (0%)

print("No")
print("No")
print("Okay")

6530074021
# 1679910, 2022-11-12 10:32:18, ------ (0%)

print('No')
print('No')
print('Okay')

6530133421
# 1680574, 2022-11-12 11:02:11, ------ (0%)

print("NO")
print("NO")
print("Okay")

6530147221
# 1681553, 2022-11-12 11:28:50, ------ (0%)

x = input().split()
while x[0] != "End":
    
    x = input().split()
print("No")
print("No")
print("Okay")


6530166121
# 1681476, 2022-11-12 11:27:21, x----- (0%)

a = input()
teams = []
while a != 'End':
    a = [e.strip() for e in a.split()]
    if a[0] == 'Ally':
        allies = set(a[1:])
        teams.append(allies)
        
    if a[0] == 'Enemy':
        enemies = a[1:]
        fight = []
        for team in teams:
            for e in enemies:
                if e in team:
                    fight.append(team)
    a = input()
    
print(teams)
print(fight)


6530191821
# 1681477, 2022-11-12 11:27:22, ------ (0%)

print('No')
print('No')
print('Okay')

6530209521
# 1681652, 2022-11-12 11:30:01, ------ (0%)

while True :
    a = input()
    if a == 'End' :break
print('No')
print('No')
print('Okay')    

6530210021
# 1681680, 2022-11-12 11:30:18, ------ (0%)

print('No')

6531338021
# 1681597, 2022-11-12 11:29:27, ------ (0%)


while True:
    a = []
    e = []
    x = input()
    if x == "End": break
    x = x.split()
    if x[0] == "Ally":
        a.append(x[1:])
    elif x[0] == "Enemy":
        e.append(x[1:])
    if x[0] == "Table":
        ch = []
        ch.append(x[1:])
        for i in range(len(ch)):
            if (ch[i-1] and ch[i] in a) and (ch[i] and ch[i+1] in a): pass
            else: print("No")
            break
        print("Okay")

6531004321
# 1681239, 2022-11-12 11:22:22, ------ (0%)

x = input()
while x != 'End':
    jo = x.split()
    ally_list = []
    enemy_list = []
    if jo[0] == 'Ally':
        ally_list.append(x[1:])
    if jo[0] == 'Enemy':
        enemy_list.append(x[1:])
    x = input()

print(ally_list,enemy_list)
    


6531005021
# 1678554, 2022-11-12 09:22:34, xxxxxx (0%)

team = {}
x = int(input())
while x != 'q' :
    for i in range(int(input())):
        name,country = input().split()
        if name not in team :
            team[country] = [name]
        else :
            team[country].append(name)
            
random = input().split()
for c in random :
    if c in team :
        print('OK')
    else :
        print('Not OK')

6531501921
# 1681583, 2022-11-12 11:29:18, ------ (0%)

#ผมไม่เหลือเวลาทำแล้ว