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

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

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

class D:
    def __init__(self, txt: str):
        self.o: B = None
        self.v: D = None
        self.txt = txt

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

n.q = g
n.v = g
n.w = m
h.p = n
h.w = g
h.q = e
i.z = g
k.o = d
k.v = a
g.o = h
g.v = a
m.z = k
d.p = e
d.q = e
d.w = a
e.q = a
e.v = a
e.w = i
a.o = h
a.v = g
assert m.z.o.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.v: D = None
        self.w: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.o: B = None
        self.v: D = None
        self.txt = txt

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

n.q = g
n.v = g
n.w = m
h.p = n
h.w = g
h.q = e
i.z = g
k.o = d
k.v = a
g.o = h
g.v = a
m.z = k
d.p = e
d.q = e
d.w = a
e.q = a
e.v = a
e.w = i
a.o = h
a.v = g
assert m.z.o.p.q.txt == "a"