class A:
    def __init__(self, txt: str):
        self.w: E = None
        self.p: A = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: E = None
        self.t: A = None
        self.x: C = None
        self.z: C = None
        self.txt = txt

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

k = A("k")
d = B("d")
g = C("g")
j = D("j")
m = E("m")
a = A("a")
c = C("c")
n = E("n")

k.w = m
k.p = a
d.s = m
g.r = c
g.t = a
j.p = m
j.t = k
j.x = c
j.z = c
m.s = d
a.w = n
a.p = k
c.r = g
c.t = k
n.s = d
assert j.p.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: E = None
        self.p: A = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: E = None
        self.t: A = None
        self.x: C = None
        self.z: C = None
        self.txt = txt

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

k = A("k")
d = B("d")
g = C("g")
j = D("j")
m = E("m")
a = A("a")
c = C("c")
n = E("n")

k.w = m
k.p = a
d.s = m
g.r = c
g.t = a
j.p = m
j.t = k
j.x = c
j.z = c
m.s = d
a.w = n
a.p = k
c.r = g
c.t = k
n.s = d
assert j.p.s.s.s.txt == "d"