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

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

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

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

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

h.z = i
h.w = e
h.s = d
e.y = h
e.r = g
d.y = a
d.o = h
b.t = n
b.w = e
c.t = b
c.w = e
a.y = d
a.o = m
n.t = c
n.w = e
i.z = h
i.w = g
i.s = a
g.y = i
g.r = e
m.z = h
m.w = g
m.s = d
assert g.r.y.s.y.y.y.y.o.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.w: B = None
        self.s: C = None
        self.txt = txt

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

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

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

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

h.z = i
h.w = e
h.s = d
e.y = h
e.r = g
d.y = a
d.o = h
b.t = n
b.w = e
c.t = b
c.w = e
a.y = d
a.o = m
n.t = c
n.w = e
i.z = h
i.w = g
i.s = a
g.y = i
g.r = e
m.z = h
m.w = g
m.s = d
assert g.r.y.s.y.y.y.y.o.z.w.txt == "g"