class A:
    def __init__(self, txt: str):
        self.q: C = 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.r: B = None
        self.s: A = None
        self.x: B = None
        self.o: A = None
        self.txt = txt

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

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

k.q = n
e.p = m
l.r = g
l.x = g
l.s = a
l.o = k
f.x = a
f.y = m
g.p = m
m.p = e
a.q = l
n.r = m
n.x = m
n.s = a
n.o = k
i.r = e
i.s = a
i.x = m
i.o = k
h.x = k
h.y = e
assert m.p.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = 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.r: B = None
        self.s: A = None
        self.x: B = None
        self.o: A = None
        self.txt = txt

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

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

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