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

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

m = A("m")
d = B("d")
i = A("i")
j = B("j")
c = A("c")
n = B("n")
b = A("b")

m.v = b
d.r = n
d.q = b
i.v = b
j.r = n
j.q = i
c.v = m
n.r = d
n.q = i
b.v = c
assert j.r.q.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

m = A("m")
d = B("d")
i = A("i")
j = B("j")
c = A("c")
n = B("n")
b = A("b")

m.v = b
d.r = n
d.q = b
i.v = b
j.r = n
j.q = i
c.v = m
n.r = d
n.q = i
b.v = c
assert j.r.q.v.v.v.txt == "m"