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

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

f = A("f")
d = B("d")
b = A("b")
i = B("i")

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

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

f = A("f")
d = B("d")
b = A("b")
i = B("i")

f.z = i
f.r = b
d.u = i
b.z = i
b.r = f
i.u = d
assert f.r.z.u.u.txt == "i"