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

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

d = A("d")
e = B("e")
a = B("a")
b = B("b")
c = B("c")

d.o = c
d.t = c
e.r = d
a.r = d
b.r = d
c.r = d
assert b.r.o.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.t: B = None
        self.txt = txt

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

d = A("d")
e = B("e")
a = B("a")
b = B("b")
c = B("c")

d.o = c
d.t = c
e.r = d
a.r = d
b.r = d
c.r = d
assert b.r.o.r.o.txt == "c"