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

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

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

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

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

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

d.t = b
l.p = b
l.o = d
b.p = l
b.o = d
assert d.t.o.t.txt == "b"