#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } //1-indexed template struct bit{ int n; vector data; bit(int n_){ n = 1; while(n < n_) n *= 2; data = vector(n+1); for(int i = 0; i <= n; i++) data[i] = 0; } T sum(int i){ T ret = 0; while(i > 0){ ret += data[i]; i -= i&-i; } return ret; } void add(int i, T x){ while(i <= n){ data[i] += x; i += i&-i; } } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, k, q; cin >> n >> k >> q; vector l(k), r(k), c(k), h(k); for(int i = 0; i < k; i++){ cin >> l[i] >> r[i] >> c[i] >> h[i]; } vector pos(q), x(q); for(int i = 0; i < q; i++){ cin >> pos[i] >> x[i]; } vector cnt_l(q, -1), cnt_r(q, k-1); vector ok(q, true); auto judge_final = [&](){ vector imos(n+2); for(int i = 0; i < k; i++){ imos[l[i]] += h[i]; imos[r[i]+1] -= h[i]; } for(int i = 1; i <= n; i++) imos[i] += imos[i-1]; for(int i = 0; i < q; i++){ if(imos[pos[i]] < x[i]){ ok[i] = false; } } }; judge_final(); int rem = 20; while(rem--){ bit bt(n+1); vector> query(k); for(int i = 0; i < q; i++){ if(!ok[i]) continue; if(cnt_r[i] <= cnt_l[i]+1) continue; int x = (cnt_l[i]+cnt_r[i])/2; query[x].push_back(i); } for(int i = 0; i < k; i++){ bt.add(l[i], h[i]); bt.add(r[i]+1, -h[i]); for(int idx: query[i]){ if(bt.sum(pos[idx]) >= x[idx]) cnt_r[idx] = i; else cnt_l[idx] = i; } } } for(int i = 0; i < q; i++){ if(!ok[i]) cout << -1 << endl; else cout << c[cnt_r[i]] << endl; } }