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

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

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

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

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

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

m.w = a
m.v = a
d.q = m
a.w = m
a.v = m
assert d.q.w.v.txt == "m"