class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.s: D = None
        self.p: A = None
        self.txt = txt

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

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

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

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

l.r = n
l.s = n
l.p = g
e.p = i
e.q = f
e.r = k
k.v = i
n.o = j
n.v = j
n.y = f
n.s = a
f.r = a
f.s = a
f.p = g
i.v = k
j.p = i
j.r = i
j.q = f
a.o = j
a.y = f
a.v = e
a.s = n
g.r = n
g.s = n
g.p = l
assert k.v.v.v.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.s: D = None
        self.p: A = None
        self.txt = txt

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

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

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

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

l.r = n
l.s = n
l.p = g
e.p = i
e.q = f
e.r = k
k.v = i
n.o = j
n.v = j
n.y = f
n.s = a
f.r = a
f.s = a
f.p = g
i.v = k
j.p = i
j.r = i
j.q = f
a.o = j
a.y = f
a.v = e
a.s = n
g.r = n
g.s = n
g.p = l
assert k.v.v.v.v.v.v.v.v.txt == "k"