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

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

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

m = A("m")
c = B("c")
g = C("g")
e = B("e")
n = A("n")
l = A("l")
h = B("h")
a = C("a")

m.o = a
c.p = n
g.u = h
g.z = h
e.p = n
n.o = g
l.o = g
h.p = m
a.u = h
a.z = h
assert n.o.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

m = A("m")
c = B("c")
g = C("g")
e = B("e")
n = A("n")
l = A("l")
h = B("h")
a = C("a")

m.o = a
c.p = n
g.u = h
g.z = h
e.p = n
n.o = g
l.o = g
h.p = m
a.u = h
a.z = h
assert n.o.z.p.txt == "m"