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

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

m = A("m")
n = B("n")
j = A("j")
i = A("i")
a = B("a")
f = A("f")
k = B("k")
b = B("b")
e = B("e")
g = A("g")

m.u = j
n.q = b
j.u = m
i.u = m
a.q = b
f.u = g
k.q = n
b.q = k
e.q = n
g.u = f
assert i.u.u.u.u.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

m = A("m")
n = B("n")
j = A("j")
i = A("i")
a = B("a")
f = A("f")
k = B("k")
b = B("b")
e = B("e")
g = A("g")

m.u = j
n.q = b
j.u = m
i.u = m
a.q = b
f.u = g
k.q = n
b.q = k
e.q = n
g.u = f
assert i.u.u.u.u.u.u.u.u.u.u.txt == "j"