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

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

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

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

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

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

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