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

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

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

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

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

n = A("n")
g = B("g")
e = C("e")
c = D("c")
i = E("i")
m = A("m")

n.v = g
g.x = i
g.q = c
e.y = c
c.s = i
i.z = n
i.v = m
i.p = e
i.t = g
m.v = g
assert g.q.s.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

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

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

n = A("n")
g = B("g")
e = C("e")
c = D("c")
i = E("i")
m = A("m")

n.v = g
g.x = i
g.q = c
e.y = c
c.s = i
i.z = n
i.v = m
i.p = e
i.t = g
m.v = g
assert g.q.s.v.v.txt == "g"