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

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

i = A("i")
d = B("d")
e = B("e")

i.w = e
d.r = i
d.z = e
e.r = i
e.z = d
assert d.r.w.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

i = A("i")
d = B("d")
e = B("e")

i.w = e
d.r = i
d.z = e
e.r = i
e.z = d
assert d.r.w.z.txt == "d"