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

m = A("m")
e = B("e")
l = A("l")
n = B("n")
h = B("h")
i = B("i")
g = B("g")

m.s = l
e.u = g
l.s = m
n.u = g
h.u = i
i.u = e
g.u = i
assert i.u.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

m = A("m")
e = B("e")
l = A("l")
n = B("n")
h = B("h")
i = B("i")
g = B("g")

m.s = l
e.u = g
l.s = m
n.u = g
h.u = i
i.u = e
g.u = i
assert i.u.u.u.u.u.u.u.txt == "e"