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

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

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

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

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

h = A("h")
l = B("l")
m = C("m")
a = D("a")
j = E("j")
g = B("g")
i = E("i")
n = E("n")

h.o = n
h.y = j
l.s = i
l.x = i
l.q = h
m.x = g
m.r = a
a.p = g
j.p = n
g.s = n
g.q = h
g.x = i
i.p = j
n.p = j
assert g.s.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: E = None
        self.y: E = None
        self.txt = txt

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

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

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

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

h = A("h")
l = B("l")
m = C("m")
a = D("a")
j = E("j")
g = B("g")
i = E("i")
n = E("n")

h.o = n
h.y = j
l.s = i
l.x = i
l.q = h
m.x = g
m.r = a
a.p = g
j.p = n
g.s = n
g.q = h
g.x = i
i.p = j
n.p = j
assert g.s.p.p.p.p.p.p.txt == "n"