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

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

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

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

n = A("n")
d = B("d")
i = C("i")
k = D("k")
a = C("a")
l = D("l")

n.p = a
d.x = n
d.z = n
i.s = d
k.t = l
k.r = l
a.s = d
l.t = k
l.r = k
assert n.p.s.x.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

n = A("n")
d = B("d")
i = C("i")
k = D("k")
a = C("a")
l = D("l")

n.p = a
d.x = n
d.z = n
i.s = d
k.t = l
k.r = l
a.s = d
l.t = k
l.r = k
assert n.p.s.x.p.s.txt == "d"