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

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

n = A("n")
b = B("b")
l = B("l")
m = A("m")
k = B("k")
c = B("c")
e = A("e")
h = A("h")
d = A("d")
j = A("j")

n.q = d
b.o = n
b.x = l
l.o = n
l.x = k
m.q = h
k.o = n
k.x = l
c.o = d
c.x = k
e.q = m
h.q = d
d.q = j
j.q = m
assert c.x.o.q.q.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

n = A("n")
b = B("b")
l = B("l")
m = A("m")
k = B("k")
c = B("c")
e = A("e")
h = A("h")
d = A("d")
j = A("j")

n.q = d
b.o = n
b.x = l
l.o = n
l.x = k
m.q = h
k.o = n
k.x = l
c.o = d
c.x = k
e.q = m
h.q = d
d.q = j
j.q = m
assert c.x.o.q.q.q.q.q.q.q.q.txt == "h"