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

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

i = A("i")
n = B("n")
j = A("j")
b = B("b")
a = A("a")
l = B("l")
m = A("m")

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

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

i = A("i")
n = B("n")
j = A("j")
b = B("b")
a = A("a")
l = B("l")
m = A("m")

i.r = j
i.q = m
n.v = i
n.z = i
j.r = m
j.q = a
b.v = m
b.z = a
a.r = m
a.q = j
l.v = a
l.z = j
m.r = j
m.q = i
assert n.z.q.r.q.txt == "a"