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

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

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

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

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

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

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