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

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

a = A("a")
e = B("e")
j = A("j")
k = A("k")
h = A("h")

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

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

a = A("a")
e = B("e")
j = A("j")
k = A("k")
h = A("h")

a.p = e
a.z = e
e.u = a
j.p = e
j.z = e
k.p = e
k.z = e
h.p = e
h.z = e
assert e.u.p.u.z.u.txt == "a"