#include <iostream>
#include <vector>
#include <algorithm>
#define INF (1<<29)
using namespace std;

vector<int> cost(vector<int> bp,vector<int> up){
    int M=(1<<20);
    vector<int> costs(M+1,0);
    for(int i=0;i<bp.size();i++){
        costs.at(bp.at(i)+1)=up.at(i);
    }
    for(int i=1;i<M;i++){
        if(costs.at(i)==0){
            costs.at(i)=costs.at(i-1);
        }
    }
    for(int i=1;i<M;i++){
        costs.at(i)=costs.at(i)+costs.at(i-1);
    }
    return costs;
}

vector< vector<int> > WarshallFloyd(vector< vector<int> > D){
    for(int k=0;k<D.size();k++){
        for(int i=0;i<D.size();i++){
            for(int j=0;j<D.at(0).size();j++){
                D.at(i).at(j)=min(D.at(i).at(j),D.at(i).at(k)+D.at(k).at(j));
            }
        }
    }
    return D;
}

int main(){
    int n,m,c,s,g;
    cin >> n >> m >> c >> s >> g;
    while(n>0 || m>0 || c>0){
        vector< vector< vector<int> > > Ds(c,vector< vector<int> >(n,vector<int>(n,INF)));
        for(int l=0;l<c;l++){
            for(int i=0;i<n;i++){
                Ds.at(l).at(i).at(i)=0;
            }
        }
        for(int i=0;i<m;i++){
            int x,y,d,k; cin >> x >> y >> d >> k;
            d=min(d,Ds.at(k-1).at(x-1).at(y-1));
            Ds.at(k-1).at(x-1).at(y-1)=d;
            Ds.at(k-1).at(y-1).at(x-1)=d;
        }
        //cout << "aaaaaa" << endl;
        vector<int>p(c);
        for(int i=0;i<c;i++) cin >> p.at(i);
        vector< vector<int> > q(c),r(c),costs(c);
        for(int i=0;i<c;i++){
            q.at(i)=vector<int>(p.at(i));
            r.at(i)=vector<int>(p.at(i));
            q.at(i).at(0)=0;
            for(int j=1;j<p.at(i);j++){
                cin >> q.at(i).at(j);
            }
            for(int j=0;j<p.at(i);j++){
                cin >> r.at(i).at(j);
            }
            costs.at(i)=cost(q.at(i),r.at(i));
        }
        //cout << "bbbbbbbbb" << endl;
        /*
        for(int l=0;l<c;l++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    cout << Ds.at(l).at(i).at(j) << " ";
                }
                cout << endl;
            }
            cout << endl;
        }
        */


        vector< vector<int> > D(n,vector<int>(n,INF));
        for(int l=0;l<c;l++){
            Ds.at(l)=WarshallFloyd(Ds.at(l));
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    //cout << "ccccccccc" << endl;
                    if(Ds.at(l).at(i).at(j)!=INF){
                        //cout << Ds.at(l).at(i).at(j) << endl;
                        Ds.at(l).at(i).at(j)=costs.at(l).at(Ds.at(l).at(i).at(j));
                    }
                    //cout << "ddddddddd" << endl;
                    D.at(i).at(j)=min(D.at(i).at(j),Ds.at(l).at(i).at(j));
                    //cout << "eeeeeeeeee" << endl;
                }
            }
        }
/*
     for(int l=0;l<c;l++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    cout << Ds.at(l).at(i).at(j) << " ";
                }
                cout << endl;
            }
            cout << endl;
        }
*/
        D=WarshallFloyd(D);
        if(D.at(s-1).at(g-1)!=INF){
            cout << D.at(s-1).at(g-1) << endl;
        }else{
            cout << -1 << endl;
        }
        cin >> n >> m >> c >> s >> g;
    }
}


Measured memory_bytes: 92876