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

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

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

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

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

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

g.u = a
n.s = f
i.u = g
f.s = n
a.u = m
e.u = a
h.s = n
c.u = i
m.u = a
assert h.s.s.s.s.s.s.s.s.txt == "f"