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

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

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

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

class E:
    def __init__(self, txt: str):
        self.q: E = None
        self.v: A = None
        self.u: C = None
        self.w: B = None
        self.o: E = None
        self.txt = txt

c = A("c")
k = B("k")
n = C("n")
m = D("m")
h = E("h")
a = B("a")
b = E("b")
i = A("i")

c.q = a
c.z = a
c.p = a
c.r = m
k.y = m
n.w = b
n.r = k
m.r = i
m.s = n
h.q = b
h.o = b
h.v = c
h.u = n
h.w = k
a.y = m
b.q = h
b.o = h
b.v = i
b.u = n
b.w = k
i.q = k
i.r = m
i.z = a
i.p = a
assert m.r.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: D = None
        self.z: B = None
        self.p: B = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.q: E = None
        self.v: A = None
        self.u: C = None
        self.w: B = None
        self.o: E = None
        self.txt = txt

c = A("c")
k = B("k")
n = C("n")
m = D("m")
h = E("h")
a = B("a")
b = E("b")
i = A("i")

c.q = a
c.z = a
c.p = a
c.r = m
k.y = m
n.w = b
n.r = k
m.r = i
m.s = n
h.q = b
h.o = b
h.v = c
h.u = n
h.w = k
a.y = m
b.q = h
b.o = h
b.v = i
b.u = n
b.w = k
i.q = k
i.r = m
i.z = a
i.p = a
assert m.r.r.r.r.r.r.r.txt == "i"