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

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

d = A("d")
l = B("l")
g = B("g")

d.o = g
l.r = g
g.r = l
assert d.o.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

d = A("d")
l = B("l")
g = B("g")

d.o = g
l.r = g
g.r = l
assert d.o.r.r.txt == "g"