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

class B:
    def __init__(self, txt: str):
        self.t: D = None
        self.q: D = None
        self.p: C = None
        self.txt = txt

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

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

n = A("n")
l = B("l")
d = C("d")
e = D("e")
i = D("i")
m = D("m")

n.u = m
l.t = e
l.q = m
l.p = d
d.s = n
e.t = m
i.t = e
m.t = e
assert m.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: D = None
        self.q: D = None
        self.p: C = None
        self.txt = txt

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

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

n = A("n")
l = B("l")
d = C("d")
e = D("e")
i = D("i")
m = D("m")

n.u = m
l.t = e
l.q = m
l.p = d
d.s = n
e.t = m
i.t = e
m.t = e
assert m.t.t.t.txt == "e"