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

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

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

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

n = A("n")
d = B("d")
a = C("a")
f = D("f")
m = A("m")
e = C("e")
i = C("i")
j = A("j")
g = D("g")
h = A("h")

n.w = j
n.p = g
d.s = f
d.x = i
a.u = i
a.s = f
f.z = m
m.w = n
m.p = f
e.u = i
e.s = f
i.u = e
i.s = g
j.w = m
j.p = f
g.z = n
h.w = m
h.p = f
assert m.p.z.p.z.w.p.z.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.p: D = None
        self.txt = txt

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

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

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

n = A("n")
d = B("d")
a = C("a")
f = D("f")
m = A("m")
e = C("e")
i = C("i")
j = A("j")
g = D("g")
h = A("h")

n.w = j
n.p = g
d.s = f
d.x = i
a.u = i
a.s = f
f.z = m
m.w = n
m.p = f
e.u = i
e.s = f
i.u = e
i.s = g
j.w = m
j.p = f
g.z = n
h.w = m
h.p = f
assert m.p.z.p.z.w.p.z.w.w.txt == "m"