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

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

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

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

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

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

n.y = i
i.x = f
i.q = f
c.y = f
k.x = i
k.q = m
f.x = k
f.q = k
h.y = i
b.y = m
m.x = i
m.q = i
a.y = i
j.y = m
assert m.q.q.q.x.q.q.txt == "k"