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

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

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

n.q = l
n.v = b
j.p = n
i.p = b
b.q = l
b.v = n
m.q = h
m.v = n
l.p = n
h.p = b
k.p = n
assert k.p.q.p.q.p.q.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: A = None
        self.txt = txt

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

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

n.q = l
n.v = b
j.p = n
i.p = b
b.q = l
b.v = n
m.q = h
m.v = n
l.p = n
h.p = b
k.p = n
assert k.p.q.p.q.p.q.p.v.txt == "b"