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

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

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

g.s = b
f.u = m
a.s = c
c.s = a
k.u = m
n.s = a
d.u = m
b.s = g
m.u = f
assert f.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

g.s = b
f.u = m
a.s = c
c.s = a
k.u = m
n.s = a
d.u = m
b.s = g
m.u = f
assert f.u.u.u.u.u.u.txt == "f"