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

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

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

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

n = A("n")
j = B("j")
i = C("i")
l = D("l")
g = D("g")
e = B("e")
k = B("k")

n.z = k
j.s = e
j.w = g
i.x = l
l.x = n
l.s = n
l.y = j
l.p = i
g.x = n
g.s = n
g.y = e
g.p = i
e.s = k
e.w = g
k.s = j
k.w = g
assert n.z.s.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

n = A("n")
j = B("j")
i = C("i")
l = D("l")
g = D("g")
e = B("e")
k = B("k")

n.z = k
j.s = e
j.w = g
i.x = l
l.x = n
l.s = n
l.y = j
l.p = i
g.x = n
g.s = n
g.y = e
g.p = i
e.s = k
e.w = g
k.s = j
k.w = g
assert n.z.s.s.w.txt == "g"