Codea = False

connections = []
doubles = []

tiles = {
    'H': [],
    'T': [],
    'P': [],
    'F': []
}

for t in ['H', 'T']:
    for i in [6,7]:
        doubles.append([t + str(i), t + str(13-i)])
    for i in [12,13]:
        doubles.append([t + str(i), t + str(25-i)])

for i in range(1,17):
    doubles.append(['P' + str(i), 'P' + str(17-i)])

for i in range(1,4):
    doubles.append(['F' + str(i), 'F' + str(15-i)])
for i in range(6,12):
    doubles.append(['F' + str(i), 'F' + str(17-i)])
for i in range(12,15):
    doubles.append(['F' + str(i), 'F' + str(15-i)])


    
c = []
for i in range(1,7):
    c.append(['H', 13 - i, 'T', i])
connections.append(c)

c = []
for i in range(1,7):
    c.append(['H', 7 - i, 'T', i])
connections.append(c)

c = []
for i in range(13,19):
    c.append(['H', i, 'T', 25 - i])
connections.append(c)

c = []
for i in range(13,19):
    c.append(['H', i, 'T', 13+18 - i])
connections.append(c)

c = []
for i in range(1,7):
    c.append(['H', i, 'P', 17 - i])
connections.append(c)

c = []
for i in range(7,13):
    c.append(['H', i, 'P', 23 - i])
connections.append(c)

c = []
for i in range(13,19):
    c.append(['H', i, 'P', 21 - i])
connections.append(c)

c = []
for i in range(1,7):
    c.append(['H', i, 'F', 15 - i])
connections.append(c)

c = []
for i in range(7,13):
    c.append(['H', i, 'F', 21 - i])
connections.append(c)

connections.append(
    [
        ['F', 7, 'F', 6],
        ['F', 8, 'F', 5],
    ]
)

LP = [
    ['P', 1, 2],
    ['P', 9, 10]
]
LF = [
    ['F', 1, 2],
    ['F', 3, 4]
]

# The 'L' edges on P can align with every other 'L' edge
for l in LP:
    for k in LP + LF:
        connections.append(
            [
                [ l[0], l[1], k[0], k[2] ],
                [ l[0], l[2], k[0], k[1] ],
            ]
        )

# For the F subclusters, only the outer 'L' edge can align with itself
connections.append(
    [
        [ 'F', 1, 'F', 2 ],
        [ 'F', 2, 'F', 1 ]
    ]
)


edges = {}
for i in range(1,19):
    edges['H' + str(i)] = []
    edges['T' + str(i)] = []
for i in range(1,17):
    edges['P' + str(i)] = []
for i in range(1,15):
    edges['F' + str(i)] = []


for c in connections:
    for e in c:
        edges[e[0] + str(e[1])].append(e[2] + str(e[3]))
        edges[e[2] + str(e[3])].append(e[0] + str(e[1]))



redo = True
while redo:
    redo = False
    for d in doubles:
        for e in edges:
            if d[0] in edges[e]:
                for a in edges[d[1]]:
                    if a not in edges[e]:
                        redo = True
                        edges[e].append(a)

adn = {'H': 0, 'T': 18}
for t in ['H', 'T']:
    for i in range(1,19):
        if Codea:
            print('{' + str(i + adn[t]),end=", {")
        else:
            print(t + str(i),end=": ")
            
        a = []
        for e in edges[t + str(i)]:
            if e[0] in ['H', 'T']:
                if Codea:
                    a.append(int(e[1:]) + adn[e[0]])
                else:
                    a.append(e)
        if Codea:
            a.sort()
        else:
            a.sort(key = lambda x: int(x[1:]) + adn[x[0]])
        print(", ".join([str(x) for x in a]), end="")
        if Codea:
            print("}},")
        else:
            print()

