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

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

class C:
    def __init__(self, txt: str):
        self.z: B = None
        self.t: A = None
        self.u: B = None
        self.x: A = None
        self.q: E = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
m = C("m")
g = D("g")
k = E("k")

h.z = m
a.o = m
a.q = h
a.v = h
m.z = a
m.u = a
m.t = h
m.x = h
m.q = k
g.z = a
g.p = h
g.q = k
k.p = m
assert h.z.x.z.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.z: B = None
        self.t: A = None
        self.u: B = None
        self.x: A = None
        self.q: E = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
m = C("m")
g = D("g")
k = E("k")

h.z = m
a.o = m
a.q = h
a.v = h
m.z = a
m.u = a
m.t = h
m.x = h
m.q = k
g.z = a
g.p = h
g.q = k
k.p = m
assert h.z.x.z.t.z.txt == "m"