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")
d = B("d")
i = B("i")
l = A("l")
e = A("e")
g = B("g")

m.u = e
d.s = g
i.s = d
l.u = m
e.u = m
g.s = i
assert m.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")
d = B("d")
i = B("i")
l = A("l")
e = A("e")
g = B("g")

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