#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define F first
#define S second
ll MOD = 998244353;
 
ll power(ll base, ll n){
	if (n == 0) return 1;
	if (n == 1) return base;
	ll halfn = power(base, n/2);
	if (n % 2 == 0) return (halfn * halfn) % MOD;
	return (((halfn * halfn) % MOD) * base) % MOD;
}
 
ll inverse(ll n){
	return power(n, MOD-2);
}

ll add(ll a, ll b){
	return (a+b) % MOD;
}

ll mul(ll a, ll b){
	return (a*b) % MOD;
}

ll gcd(ll a, ll b){
	if (a == 0) return b;
	if (a == 1) return 1;
	return gcd(b%a, a);
}

int main(){
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vi X(n), Y(n);
	FOR(i, 0, n) cin >> X[i] >> Y[i];
	int m; cin >> m;
	vector<ll> sX(m+1), sY(m+1), valX(m+1), valY(m+1), cnt(m+1);
	sX[0] = 1; sY[0] = 1; 
	FOR(i, 1, m+1){
		int op; cin >> op;
		if (op == 1){
			cnt[i] = cnt[i-1] + 1;
			valX[i] = valY[i-1];
			valY[i] = -valX[i-1];
			if (cnt[i] % 2 == 1){
				sX[i] = -sX[i-1];
				sY[i] = sY[i-1];
			}else{
				sX[i] = sX[i-1];
				sY[i] = -sY[i-1];
			}
			continue;
		}
		if (op == 2){
			cnt[i] = cnt[i-1] + 1;
			valX[i] = -valY[i-1];
			valY[i] = valX[i-1];
			if (cnt[i] % 2 == 1){
				sX[i] = sX[i-1];
				sY[i] = -sY[i-1];
			}else{
				sX[i] = -sX[i-1];
				sY[i] = sY[i-1];
			}
		}
		if (op == 3){
			ll p; cin >> p;
			cnt[i] = cnt[i-1];
			valX[i] = 2*p - valX[i-1];
			valY[i] = valY[i-1];
			if (cnt[i] % 2 == 0){
				sX[i] = -sX[i-1];
				sY[i] = sY[i-1];
			}else{
				sX[i] = sX[i-1];
				sY[i] = -sY[i-1];
			}
			continue;
		}
		if (op == 4){
			ll p; cin >> p;
			cnt[i] = cnt[i-1];
			valX[i] = valX[i-1];
			valY[i] = 2*p - valY[i-1];
			if (cnt[i] % 2 == 0){
				sX[i] = sX[i-1];
				sY[i] = -sY[i-1];
			}else{
				sX[i] = -sX[i-1];
				sY[i] = sY[i-1];
			}
		}
	}
	int q; cin >> q;
	while (q--){
		int a, b; cin >> a >> b;
		ll x = valX[a], y = valY[a];
		if (cnt[a] % 2 == 1){
			y += sX[a] * X[b-1];
			x += sY[a] * Y[b-1];
		}else{
			x += sX[a] * X[b-1];
			y += sY[a] * Y[b-1];
		}
		cout << x << " " << y << '\n';
	}
	return 0;
}



#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   fastIO
   int n,y; cin>>n>>y;
   map<int,int> mp;
   int ans=0;
   rep(i,0,n){
     int a,b,c; cin>>a>>b>>c;
     mp[a]+=c;
     mp[b+1]-=c;
   }
   int prev=-1;
   rr(mp){
      if(prev!=-1){
        ans+=(val.fi-prev)*y;
      }
      prev=val.fi;
   }
   prev=-1;
   rr(mp){
      if(prev!=-1){
        if(y>mp[prev])ans-=(val.fi-prev)*y,ans+=(val.fi-prev)*mp[prev];
        val.se+=mp[prev];
      }
      prev=val.fi;
   }
   cout<<ans<<"\n";
   return 0;
}
