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

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

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

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

n.z = m
m.p = c
m.r = c
g.p = n
g.o = m
c.z = m
l.z = m
assert n.z.r.z.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

n.z = m
m.p = c
m.r = c
g.p = n
g.o = m
c.z = m
l.z = m
assert n.z.r.z.p.z.txt == "m"