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

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

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

j.r = k
i.o = d
i.r = d
d.o = i
d.r = i
k.r = j
assert i.o.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: B = None
        self.r: B = None
        self.txt = txt

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

j.r = k
i.o = d
i.r = d
d.o = i
d.r = i
k.r = j
assert i.o.r.r.txt == "d"