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

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

i = A("i")
e = B("e")
a = A("a")
m = B("m")
h = B("h")
k = B("k")

i.u = m
e.p = h
a.u = h
m.p = h
h.p = e
k.p = h
assert h.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

i = A("i")
e = B("e")
a = A("a")
m = B("m")
h = B("h")
k = B("k")

i.u = m
e.p = h
a.u = h
m.p = h
h.p = e
k.p = h
assert h.p.p.p.txt == "e"