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

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

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

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

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

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

k.x = l
a.r = g
e.p = g
e.w = l
e.q = a
l.t = i
g.r = k
g.v = i
g.s = l
g.p = a
b.p = h
b.w = l
b.q = a
i.p = g
i.w = l
i.q = a
m.p = g
m.w = l
m.q = a
h.r = k
h.v = i
h.s = l
h.p = a
assert k.x.t.w.t.q.r.s.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

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

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

k.x = l
a.r = g
e.p = g
e.w = l
e.q = a
l.t = i
g.r = k
g.v = i
g.s = l
g.p = a
b.p = h
b.w = l
b.q = a
i.p = g
i.w = l
i.q = a
m.p = g
m.w = l
m.q = a
h.r = k
h.v = i
h.s = l
h.p = a
assert k.x.t.w.t.q.r.s.t.w.txt == "l"