#include <bits/stdc++.h>
//#include <atcoder/all>
//#include "Z:\2_Src\31_Luzhiles_s.git\template\template.cpp"
using namespace std; //using namespace atcoder;
template<typename T>  using ve=vector<T>; 
using ll=long long; using ld=long double; using str=string; using pint=pair<ll,ll>;
using vll=ve<ll>; using vd=ve<ld>; using vs=ve<str>; using vll2=ve<ve<ll>>; 
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define b2e(v) v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]
#define rep(i,n)  for(ll i=0;i<(n);i++)
#define repi(i,n) for(ll i=(n-1);i>=0;i--)
#define repe(e,v) for(auto e:v)
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;
//const int MOD=998244353;

vll t1,k1;
ll calc(ll now, ll idx) {
    //1. 到着時刻を現在位置の時刻tiを使って動的に求める((ti%k==0? ti: ti+k-ti%k) + t)
    ll ans= now%k1[idx]? k1[idx]-now%k1[idx]:0;
    return ans + t1[idx];
} 

#define TEMPT long long int 
template< typename T = TEMPT >
struct Edge {
  int from, to;
  T cost;
  int idx;

  Edge() = default;

  Edge(int from, int to, T cost = 1, int idx = -1) : from(from), to(to), cost(cost), idx(idx) {}

  operator int() const { return to; }
};

template< typename T = TEMPT >
struct Graph {
  vector< vector< Edge< T > > > g;
  int es;

  Graph() = default;

  explicit Graph(int n) : g(n), es(0) {}

  size_t size() const {
    return g.size();
  }

  void add_directed_edge(int from, int to, T cost = 1) {
    g[from].emplace_back(from, to, cost, es++);
  }

  void add_edge(int from, int to, T cost = 1) {
    g[from].emplace_back(from, to, cost, es);
    g[to].emplace_back(to, from, cost, es++);
  }

  void read(int M, int padding = -1, bool weighted = false, bool directed = false) {
    for(int i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      a += padding;
      b += padding;
      T c = T(1);
      if(weighted) cin >> c;
      if(directed) add_directed_edge(a, b, c);
      else add_edge(a, b, c);
    }
  }
};

template< typename T = TEMPT >
using Edges = vector< Edge< T > >;
#undef TEMPT 
#define TEMPT long long int 
template< typename T = TEMPT >
struct ShortestPath {
  vector< T > dist;
  vector< int > from, id;
};

template< typename T = TEMPT >
ShortestPath< T > dijkstra(const Graph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INFL);
  vector< int > from(g.size(), -1), id(g.size(), -1);
  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater<> > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g.g[idx]) {
      //auto next_cost = cost + e.cost;
      auto next_cost = cost + calc(cost, e.cost);
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      from[e.to] = idx;
      id[e.to] = e.idx;
      que.emplace(dist[e.to], e.to);
    }
  }
  return {dist, from, id};
}
#undef TEMPT 

int main() {
    
    ll nn; cin >> nn;
    ll mn; cin >> mn;
    ll x; cin >> x;
    ll y; cin >> y;
    x--; y--;
    
    ve<vll> vv1(mn,vll(4,0));
    rep(i,mn) rep(j,4) cin >> vv1[i][j];

    Graph<> g1(nn);
    rep(i, mn) {
        auto &v1=vv1[i];
        g1.add_edge(v1[0]-1, v1[1]-1, i);
        t1.push_back(v1[2]);
        k1.push_back(v1[3]);
    }

    auto p1=dijkstra(g1, x);

    // 3. 各町について、1からkまで + kからnまでの最短経路を求める
    ll ans=p1.dist[y];
    if(ans<INFL) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}

#include <bits/stdc++.h>

using namespace std;

int main(void) {
	long long N, M, Q;
	cin >> N >> M >> Q;
	vector<pair<long long, long long>> v;
	for(int i = 0; i < N; ++i) {
		long long W, V;
		cin >> W >> V;
		v.push_back({V, W});
	}
	sort(v.begin(), v.end(), greater<pair<long long, long long>>());
	vector<pair<long long, int>> x;
	for(int i = 0; i < M; ++i) {
		long long X;
		cin >> X;
		x.push_back({X, i + 1});
	}
	sort(x.begin(), x.end());
	for(int q = 0; q < Q; ++q) {
		long long L, R;
		cin >> L >> R;
		long long ans = 0;
		vector<bool> used(N, false);
		for(int i = 0; i < M; ++i) {
			if(L <= x[i].second && x[i].second <= R) continue;
			for(int j = 0; j < N; ++j) {
				if(!used[j] && v[j].second <= x[i].first) {
					ans += v[j].first;
					used[j] = true;
					break;
				}
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

