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

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

i = A("i")
l = B("l")
f = B("f")
j = A("j")
d = A("d")
m = A("m")
g = B("g")
a = A("a")
h = A("h")
n = B("n")

i.q = g
l.u = i
f.u = a
j.q = g
d.q = f
m.q = n
g.u = d
a.q = g
h.q = g
n.u = a
assert d.q.u.q.u.q.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

i = A("i")
l = B("l")
f = B("f")
j = A("j")
d = A("d")
m = A("m")
g = B("g")
a = A("a")
h = A("h")
n = B("n")

i.q = g
l.u = i
f.u = a
j.q = g
d.q = f
m.q = n
g.u = d
a.q = g
h.q = g
n.u = a
assert d.q.u.q.u.q.u.q.txt == "g"