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

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

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

a.u = j
e.q = l
e.y = a
n.u = e
j.q = b
j.y = n
h.q = b
h.y = b
l.u = j
k.u = e
b.u = j
m.q = k
m.y = n
assert n.u.y.u.y.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

a.u = j
e.q = l
e.y = a
n.u = e
j.q = b
j.y = n
h.q = b
h.y = b
l.u = j
k.u = e
b.u = j
m.q = k
m.y = n
assert n.u.y.u.y.txt == "n"