Buggy python submission (verdict: Runtime Error):
while 1:
    N, M, C, s, g = map(int, raw_input().split())
    if N == M == 0:
        break
    es = [[] for i in xrange(C)]
    for i in xrange(M):
        x, y, d, c = map(int, raw_input().split())
        if not x < y:
            x, y = y, x
        es[c-1].append((x-1, y-1, d))
    P = map(int, raw_input().split())
    Q = []; R = []
    for i in xrange(C):
        Q.append([0] + map(int, raw_input().split()) + [10**18])
        R.append(map(int, raw_input().split()))
    def calc(c, z):
        p = P[c]; q = Q[c]; r = R[c]
        su = i = 0
        while q[i+1] < z:
            su += (q[i+1] - q[i]) * r[i]
            i += 1
        return su + (z - q[i]) * r[i]

    EA = {}
    INF = 10**18
    for c in xrange(C):
        E = {(i, i): 0 for i in xrange(N)}
        for x, y, d in es[c]:
            E[x, y] = min(E.get((x, y), INF), d)
        for k in xrange(N):
            for i in xrange(N):
                for j in xrange(i+1, N):
                    k1 = min((i, k), (k, i))
                    k2 = min((k, j), (j, k))
                    if k1 in E and k2 in E:
                        E[i, j] = min(E.get((i, j), INF), E[k1] + E[k2])
        for ps in E:
            EA[ps] = min(EA.get(ps, INF), calc(c, E[ps]))
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(i+1, N):
                k1 = min((i, k), (k, i))
                k2 = min((k, j), (j, k))
                if k1 in EA and k2 in EA:
                    EA[i, j] = min(EA.get((i, j), INF), EA[k1] + EA[k2])
    ps = min((s-1, g-1), (g-1, s-1))
    print -1 if ps not in EA else EA[ps]

Fixed submission:
while 1:
    N, M, C, s, g = map(int, raw_input().split())
    if N == M == 0:
        break
    es = [[] for i in xrange(C)]
    for i in xrange(M):
        x, y, d, c = map(int, raw_input().split())
        if not x < y:
            x, y = y, x
        es[c-1].append((x-1, y-1, d))
    P = map(int, raw_input().split())
    Q = []; R = []
    for i in xrange(C):
        Q.append([0] + map(int, raw_input().split()) + [10**18])
        R.append(map(int, raw_input().split()))
    def calc(c, z):
        p = P[c]; q = Q[c]; r = R[c]
        su = i = 0
        while q[i+1] < z:
            su += (q[i+1] - q[i]) * r[i]
            i += 1
        return su + (z - q[i]) * r[i]

    EA = {}
    INF = 10**18
    for c in xrange(C):
        E = {(i, i): 0 for i in xrange(N)}
        V = set()
        for x, y, d in es[c]:
            E[x, y] = min(E.get((x, y), INF), d)
            V.add(x); V.add(y)
        for k in V:
            for i in V:
                for j in V:
                    if not i < j:
                        continue
                    k1 = min((i, k), (k, i))
                    k2 = min((k, j), (j, k))
                    if k1 in E and k2 in E:
                        E[i, j] = min(E.get((i, j), INF), E[k1] + E[k2])
        for ps in E:
            EA[ps] = min(EA.get(ps, INF), calc(c, E[ps]))
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(i+1, N):
                k1 = min((i, k), (k, i))
                k2 = min((k, j), (j, k))
                if k1 in EA and k2 in EA:
                    EA[i, j] = min(EA.get((i, j), INF), EA[k1] + EA[k2])
    ps = min((s-1, g-1), (g-1, s-1))
    print -1 if ps not in EA else EA[ps]