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

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

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

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

h = A("h")
i = B("i")
m = C("m")
d = D("d")
l = D("l")
k = B("k")
b = A("b")
e = C("e")
g = C("g")

h.y = i
h.o = b
h.r = b
h.z = l
i.p = k
m.s = k
m.r = e
d.t = i
l.t = k
k.p = i
b.y = i
b.o = h
b.r = h
b.z = d
e.s = i
e.r = g
g.s = i
g.r = m
assert m.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.o: A = None
        self.z: D = None
        self.r: A = None
        self.txt = txt

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

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

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

h = A("h")
i = B("i")
m = C("m")
d = D("d")
l = D("l")
k = B("k")
b = A("b")
e = C("e")
g = C("g")

h.y = i
h.o = b
h.r = b
h.z = l
i.p = k
m.s = k
m.r = e
d.t = i
l.t = k
k.p = i
b.y = i
b.o = h
b.r = h
b.z = d
e.s = i
e.r = g
g.s = i
g.r = m
assert m.r.r.r.r.r.txt == "g"