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

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

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

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

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

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

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

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

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

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

n.q = e
m.z = n
i.p = e
i.q = n
i.x = n
i.t = m
d.x = e
e.x = d
assert m.z.q.x.x.txt == "e"