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

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

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

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

n = A("n")
e = B("e")
c = C("c")
i = D("i")
m = D("m")
g = A("g")
h = B("h")
a = C("a")
b = D("b")

n.z = a
n.q = c
e.q = n
c.p = i
c.z = m
c.x = b
i.z = b
i.x = b
m.z = b
m.x = b
g.z = c
g.q = c
h.q = g
a.p = m
a.x = m
a.z = i
b.z = m
b.x = i
assert m.x.z.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.q: C = None
        self.txt = txt

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

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

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

n = A("n")
e = B("e")
c = C("c")
i = D("i")
m = D("m")
g = A("g")
h = B("h")
a = C("a")
b = D("b")

n.z = a
n.q = c
e.q = n
c.p = i
c.z = m
c.x = b
i.z = b
i.x = b
m.z = b
m.x = b
g.z = c
g.q = c
h.q = g
a.p = m
a.x = m
a.z = i
b.z = m
b.x = i
assert m.x.z.z.x.txt == "i"