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

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

c = A("c")
b = B("b")
e = B("e")
a = A("a")

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

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

c = A("c")
b = B("b")
e = B("e")
a = A("a")

c.z = b
c.w = a
b.w = a
e.w = a
a.z = b
a.w = c
assert b.w.w.z.txt == "b"