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

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

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

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

g = A("g")
m = B("m")
a = C("a")
i = D("i")
n = B("n")
j = C("j")
c = C("c")

g.w = n
g.p = i
m.u = g
a.w = c
a.r = c
a.p = g
i.y = n
i.s = n
i.w = c
i.x = j
n.u = g
j.w = c
j.r = c
j.p = g
c.w = a
c.r = a
c.p = g
assert m.u.p.y.u.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.p: D = None
        self.txt = txt

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

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

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

g = A("g")
m = B("m")
a = C("a")
i = D("i")
n = B("n")
j = C("j")
c = C("c")

g.w = n
g.p = i
m.u = g
a.w = c
a.r = c
a.p = g
i.y = n
i.s = n
i.w = c
i.x = j
n.u = g
j.w = c
j.r = c
j.p = g
c.w = a
c.r = a
c.p = g
assert m.u.p.y.u.w.u.txt == "g"