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

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

m = A("m")
b = B("b")
e = A("e")
a = A("a")
j = B("j")

m.v = a
m.q = a
b.v = j
b.u = a
e.v = m
e.q = m
a.v = m
a.q = m
j.v = b
j.u = m
assert j.u.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.q: A = None
        self.txt = txt

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

m = A("m")
b = B("b")
e = A("e")
a = A("a")
j = B("j")

m.v = a
m.q = a
b.v = j
b.u = a
e.v = m
e.q = m
a.v = m
a.q = m
j.v = b
j.u = m
assert j.u.q.q.q.txt == "a"