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

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

c = A("c")
k = B("k")
g = A("g")
f = A("f")
b = B("b")
d = B("d")
a = B("a")
j = B("j")

c.u = f
k.q = c
g.u = f
f.u = g
b.q = c
d.q = c
a.q = g
j.q = c
assert f.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: A = None
        self.txt = txt

c = A("c")
k = B("k")
g = A("g")
f = A("f")
b = B("b")
d = B("d")
a = B("a")
j = B("j")

c.u = f
k.q = c
g.u = f
f.u = g
b.q = c
d.q = c
a.q = g
j.q = c
assert f.u.u.u.u.u.u.u.u.txt == "f"