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

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

f.q = c
l.u = i
m.q = c
c.u = m
j.q = h
g.q = c
h.u = i
i.q = h
a.q = l
n.q = c
assert f.q.u.q.u.q.u.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

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

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