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

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

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

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

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

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

j.o = b
j.r = d
b.z = i
i.z = b
d.o = b
d.r = j
assert b.z.z.z.txt == "i"