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

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

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

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

m = A("m")
n = B("n")
c = C("c")
i = D("i")
k = B("k")
e = A("e")
g = B("g")
a = B("a")
d = D("d")
f = C("f")

m.x = c
n.z = e
n.p = g
n.r = f
n.v = d
c.r = g
c.y = g
c.p = f
c.z = i
i.w = d
k.z = m
k.p = a
k.r = c
k.v = d
e.x = f
g.z = m
g.p = n
g.r = c
g.v = i
a.z = m
a.p = n
a.r = c
a.v = d
d.w = i
f.r = g
f.p = c
f.z = i
f.y = a
assert m.x.z.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

m = A("m")
n = B("n")
c = C("c")
i = D("i")
k = B("k")
e = A("e")
g = B("g")
a = B("a")
d = D("d")
f = C("f")

m.x = c
n.z = e
n.p = g
n.r = f
n.v = d
c.r = g
c.y = g
c.p = f
c.z = i
i.w = d
k.z = m
k.p = a
k.r = c
k.v = d
e.x = f
g.z = m
g.p = n
g.r = c
g.v = i
a.z = m
a.p = n
a.r = c
a.v = d
d.w = i
f.r = g
f.p = c
f.z = i
f.y = a
assert m.x.z.w.w.w.w.txt == "i"