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

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

b = A("b")
f = B("f")
e = A("e")
h = B("h")
a = A("a")
k = B("k")

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

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

b = A("b")
f = B("f")
e = A("e")
h = B("h")
a = A("a")
k = B("k")

b.z = k
f.p = a
e.z = h
h.p = a
a.z = f
k.p = e
assert e.z.p.z.txt == "f"