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.v: B = None
        self.w: A = None
        self.txt = txt

m = A("m")
b = B("b")
l = A("l")
g = A("g")
j = A("j")
d = A("d")
n = B("n")

m.v = d
m.q = n
b.v = n
b.w = g
l.v = m
l.q = b
g.v = d
g.q = b
j.v = m
j.q = n
d.v = m
d.q = b
n.v = b
n.w = d
assert m.v.q.v.w.v.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.v: B = None
        self.w: A = None
        self.txt = txt

m = A("m")
b = B("b")
l = A("l")
g = A("g")
j = A("j")
d = A("d")
n = B("n")

m.v = d
m.q = n
b.v = n
b.w = g
l.v = m
l.q = b
g.v = d
g.q = b
j.v = m
j.q = n
d.v = m
d.q = b
n.v = b
n.w = d
assert m.v.q.v.w.v.txt == "m"