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

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

n = A("n")
d = B("d")
l = B("l")
h = A("h")
m = A("m")
i = B("i")
k = B("k")
e = B("e")
g = A("g")

n.q = g
n.u = m
d.x = h
l.x = g
h.q = m
h.u = g
m.q = n
m.u = h
i.x = h
k.x = g
e.x = g
g.q = m
g.u = m
assert i.x.u.u.q.q.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.u: A = None
        self.txt = txt

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

n = A("n")
d = B("d")
l = B("l")
h = A("h")
m = A("m")
i = B("i")
k = B("k")
e = B("e")
g = A("g")

n.q = g
n.u = m
d.x = h
l.x = g
h.q = m
h.u = g
m.q = n
m.u = h
i.x = h
k.x = g
e.x = g
g.q = m
g.u = m
assert i.x.u.u.q.q.q.u.txt == "h"