#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include <bitset>
#include<cstring>

#define forn(i,a,n) for(int i=(a);i<(n);i++)
#define ford(i,a,d) for(int i=(a);i>(d);i--)
#define pb push_back

using namespace std;
const long long N=2e5+6;
const long long inf=0x3f3f3f3f;
typedef long long ll;

int a[N];
vector<int> adj[N];

int main()
{
//    ios::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);


    int n,m;
    cin>>n>>m;
    forn(i,1,n+1) cin>>a[i];
    forn(i,0,m)
    {
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
    }

    vector<int> dp(n+1,2e9);
    int ans=-2e9;
    forn(i,1,n+1)
    {
        ans=max(ans,a[i]-dp[i]);
        for(auto j:adj[i])
        {
            dp[j]=min(dp[j],dp[i]);
            dp[j]=min(dp[j],a[i]);
        }
    }
    cout<<ans;
    return 0;

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

vector<vector<ll>> matsum(vector<vector<ll>> A, vector<vector<ll>> B) {
  if (A.size()!=B.size()||A[0].size()!=B[0].size()) return {{}};
  ll h = A.size(), w = A[0].size();
  vector<vector<ll>> result(h,vector<ll>(w,0));
  rep(i,h) rep(j,w) result[i][j] = (A[i][j]+B[i][j])%MOD;
  return result;
}

vector<vector<ll>> matdiff(vector<vector<ll>> A, vector<vector<ll>> B) {
  if (A.size()!=B.size()||A[0].size()!=B[0].size()) return {{}};
  ll h = A.size(), w = A[0].size();
  vector<vector<ll>> result(h,vector<ll>(w,0));
  rep(i,h) rep(j,w) result[i][j] = (MOD+(A[i][j]-B[i][j])%MOD)%MOD;
  return result;
}

vector<vector<ll>> matdot(vector<vector<ll>> A, vector<vector<ll>> B) {
  if (A[0].size()!=B.size()) return {{}};
  ll h = A.size(), w = B[0].size(), x = A[0].size();
  vector<vector<ll>> result(h,vector<ll>(w,0));
  rep(i,h) rep(j,w) rep(k,x) result[i][j] = (result[i][j] + A[i][k]*B[k][j]);
  return result;
}

vector<vector<ll>> matpow(vector<vector<ll>> A, ll n) {
  if (A.size()!=A[0].size()) return {{}};
  int N = A.size();
  vector<vector<ll>> result(N,vector<ll>(N,0)), now;
  copy(all(A),back_inserter(now));
  rep(i,N) result[i][i] = 1;
  ll p2 = 1; 
  while (n>=p2) {
    if (n&p2) result = matdot(result,now);
    now = matdot(now,now); p2 *= 2;
  }
  return result;
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

int main() {
  ll N; cin >> N;
  ll X[N], Y[N]; rep(i,N) cin >> X[i] >> Y[i];
  ll M; cin >> M;
  ll op[M][2] = {}; rep(i,M) { cin >> op[i][0]; if (op[i][0]>=3) cin >> op[i][1]; }
  ll Q; cin >> Q;
  ll A[Q], B[Q]; rep(i,Q) { cin >> A[i] >> B[i]; B[i]--; }

  vector<vector<ll>> ope = { {1,0,0}, {0,1,0}, {0,0,1} };
  vector<vector<vector<ll>>> opmat(M+1); opmat[0] = ope;
  rep(i,M) {
    vector<vector<ll>> mulmat;
    if (op[i][0]==1) {
      mulmat = {
        {0,1,0},
        {-1,0,0},
        {0,0,1}
      };
    }
    else if (op[i][0]==2) {
      mulmat = {
        {0,-1,0},
        {1,0,0},
        {0,0,1}
      };
    }
    else if (op[i][0]==3) {
      mulmat = {
        {-1,0,2*op[i][1]},
        {0,1,0},
        {0,0,1}
      };
    }
    else if (op[i][0]==4) {
      mulmat = {
        {1,0,0},
        {0,-1,2*op[i][1]},
        {0,0,1}
      };
    }
    opmat[i+1] = matdot(mulmat,opmat[i]);
  }

  // rep(i,M+1) {
  //   for (auto x: opmat[i]) debug(all(x));
  //   cout << endl;
  // }

  rep(i,Q) {
    vector<vector<ll>> resmat = matdot(opmat[A[i]],{{X[B[i]]},{Y[B[i]]},{1}});
    cout << resmat[0][0] << " " << resmat[1][0] << endl;
  }
  return 0;
}