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

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

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

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

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

f.w = h
i.r = f
i.p = a
i.v = n
i.o = h
a.p = h
a.u = g
h.o = j
n.r = d
n.p = m
n.v = i
n.o = h
g.p = h
g.u = m
m.p = h
m.u = g
d.w = h
e.w = h
j.w = h
assert i.o.o.w.o.w.o.w.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.txt = txt

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

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

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

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

f.w = h
i.r = f
i.p = a
i.v = n
i.o = h
a.p = h
a.u = g
h.o = j
n.r = d
n.p = m
n.v = i
n.o = h
g.p = h
g.u = m
m.p = h
m.u = g
d.w = h
e.w = h
j.w = h
assert i.o.o.w.o.w.o.w.o.w.txt == "h"