#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<ll,int>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define sz(x) int(x.size())
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

struct ed{
  int to,t,k;
  ed(int to,int t,int k):to(to),t(t),k(k){}
};

int main(){
  cci(n,m);
  cci(sx,sy);
  sx--;sy--;

  V<V<ed>> v(n);

  rep(i,0,m){
    cci(x,y);
    x--;y--;

    cci(t,k);

    v[x].eb(y,t,k);
    v[y].eb(x,t,k);
  }

  ll inf=3e18;
  vll dist(n,inf);
  dist[sx]=0;

  minpq<P>q;
  q.push(P(0,sx));

  while(sz(q)){
    ll d=q.top().first;
    int x=q.top().second;
    q.pop();

    if(dist[x]<d)continue;

    for(auto e:v[x]){
      int nx=e.to;
      ll k=e.k;

      ll tm=(d+k-1)/k*k+e.t;

      if(dist[nx]>tm){
        dist[nx]=tm;
        q.push(P(tm,nx));
      }
    }
  }


  ll ans=dist[sy];
  if(ans==inf)ans=-1;

  co(ans);
}
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Incase of close mle change language to c++17 or c++14 
/**#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops”)**/
#include <bits/stdc++.h>  
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n, m, q;
    cin>>n>>m>>q;
    vector <pii> v;
    rep(i,0,n)
    {
        int a, b;
        cin>>a>>b;
        v.pb({a, b});
    }
    sort(all(v));
    int ar[m];
    rep(i,0,m)
    cin>>ar[i];
    while(q--)
    {
        int l, r;
        cin>>l>>r;
        l--,r--;
        vi temp;
        rep(i,0,l)
        temp.pb(ar[i]);
        rep(i,r+1,m)
        temp.pb(ar[i]);
        sort(all(temp));
        mii s;
        int cur=0, ans=0;
        for(auto num:temp)
        {
            while(cur<n && v[cur].ff<=num)
            s[(-v[cur].ss)]++, cur++;
            if(!s.empty())
            {
                auto it=*s.begin();
                ans-=it.ff;
                s[it.ff]--;
                if(s[it.ff]==0)
                s.erase(it.ff);
            }
        }
        cout<<ans<<"\n";
    }
}