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

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

class C:
    def __init__(self, txt: str):
        self.p: E = None
        self.w: D = None
        self.r: C = None
        self.q: D = None
        self.txt = txt

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

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

a = A("a")
f = B("f")
g = C("g")
i = D("i")
d = E("d")
n = C("n")

a.p = i
a.w = n
f.u = d
f.s = n
g.p = d
g.w = i
g.q = i
g.r = n
i.t = d
d.z = f
d.q = a
n.p = d
n.w = i
n.q = i
n.r = g
assert f.s.p.q.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.w: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.p: E = None
        self.w: D = None
        self.r: C = None
        self.q: D = None
        self.txt = txt

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

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

a = A("a")
f = B("f")
g = C("g")
i = D("i")
d = E("d")
n = C("n")

a.p = i
a.w = n
f.u = d
f.s = n
g.p = d
g.w = i
g.q = i
g.r = n
i.t = d
d.z = f
d.q = a
n.p = d
n.w = i
n.q = i
n.r = g
assert f.s.p.q.w.r.txt == "g"