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

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

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

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

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

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

c.q = f
i.u = g
i.o = e
k.u = g
k.o = m
g.q = n
m.u = f
m.o = j
j.u = f
j.o = e
n.q = f
e.u = n
e.o = m
f.q = c
assert k.u.q.q.q.q.q.q.q.q.txt == "f"