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

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

e = A("e")
m = B("m")
d = B("d")
g = A("g")
b = A("b")
j = B("j")
i = A("i")
c = B("c")
h = A("h")
k = A("k")

e.p = k
m.x = j
d.x = j
g.p = k
b.p = i
j.x = c
i.p = k
c.x = j
h.p = i
k.p = i
assert b.p.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.x: B = None
        self.txt = txt

e = A("e")
m = B("m")
d = B("d")
g = A("g")
b = A("b")
j = B("j")
i = A("i")
c = B("c")
h = A("h")
k = A("k")

e.p = k
m.x = j
d.x = j
g.p = k
b.p = i
j.x = c
i.p = k
c.x = j
h.p = i
k.p = i
assert b.p.p.p.p.p.p.txt == "k"