class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

n = A("n")
m = B("m")
e = B("e")
g = B("g")
c = A("c")
b = A("b")
h = B("h")
a = B("a")
k = A("k")

n.p = b
m.y = a
e.y = a
g.y = m
c.p = b
b.p = k
h.y = g
a.y = m
k.p = n
assert b.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

n = A("n")
m = B("m")
e = B("e")
g = B("g")
c = A("c")
b = A("b")
h = B("h")
a = B("a")
k = A("k")

n.p = b
m.y = a
e.y = a
g.y = m
c.p = b
b.p = k
h.y = g
a.y = m
k.p = n
assert b.p.p.p.p.p.txt == "n"