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

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

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

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

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

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

g.p = k
g.r = j
k.y = i
k.q = f
m.q = c
m.w = k
f.q = m
l.r = m
h.p = k
h.r = j
j.p = k
j.r = g
a.q = m
i.r = m
c.q = m
assert k.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: A = None
        self.txt = txt

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

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

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

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

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

g.p = k
g.r = j
k.y = i
k.q = f
m.q = c
m.w = k
f.q = m
l.r = m
h.p = k
h.r = j
j.p = k
j.r = g
a.q = m
i.r = m
c.q = m
assert k.q.q.q.q.q.q.txt == "m"