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

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

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

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

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

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

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

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

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

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

g.q = h
g.z = h
d.q = g
n.p = g
n.o = e
n.u = i
a.p = i
a.z = b
m.p = a
m.z = h
e.q = g
b.p = g
b.o = e
b.u = m
h.p = g
h.o = d
h.u = m
j.q = g
i.p = a
i.z = h
assert m.p.p.p.z.o.txt == "e"