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.w: B = None
        self.x: B = None
        self.txt = txt

e = A("e")
h = B("h")
f = B("f")
c = A("c")
k = B("k")

e.p = k
e.z = f
h.w = k
h.x = f
f.w = k
f.x = h
c.p = k
c.z = k
k.w = f
k.x = f
assert h.x.x.w.w.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.w: B = None
        self.x: B = None
        self.txt = txt

e = A("e")
h = B("h")
f = B("f")
c = A("c")
k = B("k")

e.p = k
e.z = f
h.w = k
h.x = f
f.w = k
f.x = h
c.p = k
c.z = k
k.w = f
k.x = f
assert h.x.x.w.w.txt == "f"