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

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

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

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

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

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

d.q = b
d.r = e
b.o = d
e.o = l
l.q = b
l.r = e
assert l.q.o.q.txt == "b"