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

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

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

a.q = b
a.v = b
f.z = j
j.z = h
n.q = f
n.v = f
l.q = f
l.v = b
d.q = b
d.v = j
g.q = j
g.v = h
b.z = f
m.q = f
m.v = b
h.z = f
assert j.z.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: B = None
        self.txt = txt

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

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

a.q = b
a.v = b
f.z = j
j.z = h
n.q = f
n.v = f
l.q = f
l.v = b
d.q = b
d.v = j
g.q = j
g.v = h
b.z = f
m.q = f
m.v = b
h.z = f
assert j.z.z.z.z.z.z.z.txt == "h"