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

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

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

n = A("n")
l = B("l")
a = C("a")
h = A("h")
d = A("d")
b = C("b")
f = B("f")
g = A("g")

n.x = f
n.w = l
n.z = l
l.p = a
a.x = d
h.x = l
h.w = f
h.z = f
d.x = l
d.w = l
d.z = l
b.x = d
f.p = b
g.x = f
g.w = f
g.z = f
assert g.w.p.x.w.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.w: B = None
        self.z: B = None
        self.txt = txt

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

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

n = A("n")
l = B("l")
a = C("a")
h = A("h")
d = A("d")
b = C("b")
f = B("f")
g = A("g")

n.x = f
n.w = l
n.z = l
l.p = a
a.x = d
h.x = l
h.w = f
h.z = f
d.x = l
d.w = l
d.z = l
b.x = d
f.p = b
g.x = f
g.w = f
g.z = f
assert g.w.p.x.w.p.x.txt == "d"