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

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

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

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

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

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

d.t = m
d.w = l
l.q = d
m.t = d
m.w = l
assert d.t.w.q.txt == "d"