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

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

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

class D:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

m = A("m")
f = B("f")
e = C("e")
l = D("l")
k = D("k")
h = A("h")
n = D("n")
d = B("d")

m.x = n
f.u = d
e.o = d
l.p = n
k.p = n
h.x = k
n.p = l
d.u = f
assert l.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

m = A("m")
f = B("f")
e = C("e")
l = D("l")
k = D("k")
h = A("h")
n = D("n")
d = B("d")

m.x = n
f.u = d
e.o = d
l.p = n
k.p = n
h.x = k
n.p = l
d.u = f
assert l.p.p.p.p.txt == "l"