#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const int N = 100000+5; vector<pair<int,int> > a[N], tmp, b[N]; ll sum[N];
struct Segtree { #define lson rt<<1, l, mid #define rson rt<<1|1, mid+1, r vector<pair<int,int> > node[N<<2];
void build(int rt, int l, int r) { node[rt].clear(); for(int i = l;i <= r; i++) { for(int j = 0;j < a[i].size(); j++) { node[rt].push_back(make_pair(a[i][j].first, a[i] [j].second)); } } sort(node[rt].begin(), node[rt].end()); int top = 1; for(int i = 1;i < node[rt].size(); i++) if(node[rt] [i].second > node[rt][top-1].second){ if(node[rt][i].first == node[rt][top-1].first) node[rt][top-1].second = node[rt][i].second; else node[rt][top++] = node[rt][i]; } node[rt].resize(top); if(l == r) return ; int mid = l+r>>1; build(lson); build(rson); }
int query(int rt, int l, int r, int x, int y) { if(l == r) return l; int mid = l+r>>1; if(check(rt<<1, x, y)) return query(lson, x, y); return query(rson, x, y); }
inline bool check(int rt, int x, int y) { int pos = lower_bound(node[rt].begin(), node[rt].end(), make_pair(x+1, 0))-node[rt].begin(); if(pos == 0 || node[rt][pos-1].second < y) return false; return true; } }tree;
int n, m, t;
int main() { //freopen("data.in", "r", stdin); //freopen("data.out", "w", stdout); while(scanf("%d%d%d", &n, &m, &t) != -1) { for(int i = 1;i <= t; i++) sum[i] = 0; for(int i = 1;i <= n; i++) b[i].clear(); int l, r, x; for(int i = 0;i < m; i++) { scanf("%d%d%d", &l, &r, &x); sum[l]++; sum[r+1]--; b[x].push_back(make_pair(l, r)); } for(int i = 1;i <= t; i++) sum[i] += sum[i-1]; for(int i = 1;i <= t; i++) sum[i] += sum[i-1];
for(int i = 1;i <= n; i++) { sort(b[i].begin(), b[i].end()); a[i].clear(); int cur = 1; for(int j = 0;j < b[i].size(); j++) { if(cur < b[i][j].first) a[i].push_back(make_pair(cur, b[i][j].first-1)); cur = max(cur, b[i][j].second+1); } if(cur <= t) { a[i].push_back(make_pair(cur, t)); } } tree.build(1, 1, n); int q, z = 0; scanf("%d", &q); while(q--) { scanf("%d%d", &l, &r); if(r+z <= t) l += z, r += z; else l = t-(r-l), r = t; if(tree.check(1, l, r)) z = tree.query(1, 1, n, l, r); else z = 0; printf("%lld %d\n", sum[r]-sum[l-1], z); } } return 0; }