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

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

m = A("m")
c = B("c")
k = B("k")
d = A("d")
b = B("b")

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

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

m = A("m")
c = B("c")
k = B("k")
d = A("d")
b = B("b")

m.v = d
m.q = b
c.w = d
k.w = d
d.v = m
d.q = k
b.w = d
assert d.v.v.q.txt == "k"