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

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

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

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

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

h.t = e
a.r = m
a.w = e
a.z = h
e.r = i
n.w = d
d.r = k
d.w = e
d.z = h
k.w = a
m.w = d
j.t = e
b.w = a
i.r = e
assert n.w.r.w.z.t.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

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

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

h.t = e
a.r = m
a.w = e
a.z = h
e.r = i
n.w = d
d.r = k
d.w = e
d.z = h
k.w = a
m.w = d
j.t = e
b.w = a
i.r = e
assert n.w.r.w.z.t.r.r.r.r.r.txt == "i"