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

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

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

n = A("n")
g = B("g")
d = C("d")
m = A("m")

n.p = m
n.z = m
n.o = d
g.o = n
g.x = d
g.z = d
d.z = n
d.v = g
m.p = n
m.z = n
m.o = d
assert m.o.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.z: A = None
        self.o: C = None
        self.txt = txt

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

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

n = A("n")
g = B("g")
d = C("d")
m = A("m")

n.p = m
n.z = m
n.o = d
g.o = n
g.x = d
g.z = d
d.z = n
d.v = g
m.p = n
m.z = n
m.o = d
assert m.o.z.z.txt == "m"