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

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

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

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

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

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

b.o = a
d.o = b
d.t = b
a.o = b
assert a.o.o.o.txt == "b"