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

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

j = A("j")
i = B("i")
c = A("c")

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

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

j = A("j")
i = B("i")
c = A("c")

j.r = c
i.o = c
c.r = j
assert j.r.r.r.txt == "c"