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

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

m = A("m")
f = B("f")
k = B("k")
n = B("n")
a = B("a")
g = A("g")
j = A("j")
i = A("i")
b = A("b")

m.v = j
m.r = k
f.x = g
f.q = j
k.x = g
k.q = g
n.x = b
n.q = g
a.x = g
a.q = i
g.v = i
g.r = a
j.v = g
j.r = k
i.v = g
i.r = f
b.v = j
b.r = k
assert b.r.q.v.v.r.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.r: B = None
        self.txt = txt

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

m = A("m")
f = B("f")
k = B("k")
n = B("n")
a = B("a")
g = A("g")
j = A("j")
i = A("i")
b = A("b")

m.v = j
m.r = k
f.x = g
f.q = j
k.x = g
k.q = g
n.x = b
n.q = g
a.x = g
a.q = i
g.v = i
g.r = a
j.v = g
j.r = k
i.v = g
i.r = f
b.v = j
b.r = k
assert b.r.q.v.v.r.q.r.txt == "f"