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

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

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

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

c = A("c")
e = B("e")
n = C("n")
g = D("g")
f = C("f")
b = A("b")
d = C("d")

c.w = e
e.x = n
e.y = d
e.s = g
n.z = c
g.s = e
g.p = e
f.z = c
b.w = e
d.z = c
assert b.w.x.z.w.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

c = A("c")
e = B("e")
n = C("n")
g = D("g")
f = C("f")
b = A("b")
d = C("d")

c.w = e
e.x = n
e.y = d
e.s = g
n.z = c
g.s = e
g.p = e
f.z = c
b.w = e
d.z = c
assert b.w.x.z.w.s.p.s.txt == "g"