#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

class ops
{
    public:
    ll cx, cy, sx, sy;
    bool sw;
    
    ops()
    {
        cx = 0, cy = 0, sx = 1, sy = 1;
        sw = 0;
    }
    
    void t1()
    {
        swap(cx,cy);
        swap(sx,sy);
        sy = -sy;
        sw^=1;
        cy = -cy;
    }
    
    void t2()
    {
        swap(cx,cy);
        swap(sx,sy);
        sx = -sx;
        sw^=1;
        cx = -cx;
    }
    
    void t3(ll p)
    {
        sx = -sx;
        cx = -cx + 2*p;
    }
    
    void t4(ll p)
    {
        sy = -sy;
        cy = -cy + 2*p;
    }
    
    pii get(pii pt)
    {
        if(sw)
            swap(pt.ff, pt.ss);
        pt.ff = pt.ff*sx + cx;
        pt.ss = pt.ss*sy + cy;
        return pt;
    }
    
    void conv(ll ty, ll p = -1)
    {
        if(ty == 1)
            t1();
        else if(ty == 2)
            t2();
        else if(ty == 3)
            t3(p);
        else t4(p);    
    }
};

int main()
{
  FAST/**/
  
  ll n;
  cin>>n;
  pii arr[n];
  rep(n)
        cin>>arr[i].ff>>arr[i].ss;
  
  ll m;
  cin>>m;
  pii op[m];
  rep(m)
  {
      cin>>op[i].ff;
      
      if(op[i].ff>2)
            cin>>op[i].ss;
  }
  
  ll q;
  cin>>q;
  
  pair<pii,ll> quer[q];
  rep(q)
        cin>>quer[i].ff.ff>>quer[i].ff.ss, quer[i].ss = i;
  ops ds;      
  sort(quer,quer+q);
  ll ptr = 0;
  pii ans[q];
  rep(q)
  {
      while(ptr<m && quer[i].ff.ff-1>=ptr){
          //cout<<"applying "<<ptr+1<<' '<<op[ptr].ff<<'\n';
          ds.conv(op[ptr].ff, op[ptr].ss), ptr++;
          //cout<<ds.cx<<" "<<ds.cy<<" "<<ds.sx<<" "<<ds.sy<<'\n';
      }
      pii pt = ds.get(arr[quer[i].ff.ss-1]);
      ans[quer[i].ss] = pt;
  }
  
  rep(q)
        cout<<ans[i].ff<<" "<<ans[i].ss<<'\n';
  
  return 0;
}
   
   
 
#include <bits/stdc++.h>

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> bool chmax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

int dp[1 << 17][17];

int main() {
    int n;
    int x[17], y[17], z[17], d[17][17];

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> z[i];
    }

    fill(d[0], d[n], INF);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            d[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0, z[j] - z[i]);
        }
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    fill(dp[0], dp[1 << n], INF);
    dp[0][0] = 0;
    for (int i = 0; i < (1 << n); ++i) {
        for (int u = 0; u < n; ++u) {
            for (int v = 0; v < n; ++v) {
                if (!(i >> v & 1)) {
                    chmin(dp[i | (1 << v)][v], dp[i][u] + d[u][v]);
                }
            }
        }
    }
    
    cout << dp[(1 << n) - 1][0] << endl;

    return 0;
}