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

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

b = A("b")
f = B("f")
h = A("h")
g = B("g")
e = A("e")
c = B("c")

b.w = h
b.z = f
f.z = g
h.w = e
h.z = g
g.z = c
e.w = h
e.z = f
c.z = f
assert g.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.z: B = None
        self.txt = txt

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

b = A("b")
f = B("f")
h = A("h")
g = B("g")
e = A("e")
c = B("c")

b.w = h
b.z = f
f.z = g
h.w = e
h.z = g
g.z = c
e.w = h
e.z = f
c.z = f
assert g.z.z.z.z.txt == "c"