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

m = A("m")
l = B("l")
j = A("j")
b = A("b")
e = A("e")
f = A("f")
k = B("k")
g = B("g")

m.u = b
l.s = g
j.u = f
b.u = e
e.u = b
f.u = j
k.s = g
g.s = k
assert j.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.s: B = None
        self.txt = txt

m = A("m")
l = B("l")
j = A("j")
b = A("b")
e = A("e")
f = A("f")
k = B("k")
g = B("g")

m.u = b
l.s = g
j.u = f
b.u = e
e.u = b
f.u = j
k.s = g
g.s = k
assert j.u.u.u.u.txt == "j"