#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

int main(){
  ll n;cin >> n;
  string s;cin >> s;
  vl a(n+1);rep(i,n+1)cin >> a[i];
  ll k=inf;rep(i,n)chmin(k,abs(a[i+1]-a[i]));
  cout << k <<endl;
  vvl mat(k,vl(n+1));
  vl use(n+1);
  rep(i,k){
    rep(j,n+1){
      mat[i][j]=a[j]/k;
      use[j]+=a[j]/k;
    }
  }
  rep(i,n+1)a[i]-=use[i];
  rep(i,n+1){
    rep(j,a[i]){
      mat[j][i]++;
    }
  }
  rep(i,k){
    rep(j,n+1)cout << mat[i][j] <<" ";cout << endl;
  }
} 
#include <bits/stdc++.h>
#define PRINT(x) cerr<<#x<<'='<<x<<endl
#define NL(x) " \n"[(x)]
#define sz(x) int((x).size())
#define all(x) begin(x),end(x)
#define mid (l+r)/2
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define lld long long
#define pii pair<int,int>
#define pli pair<lld,int>
#define pil pair<int,lld>
#define pll pair<lld,lld>
#define INF 1000000000
#define LINF 1000000000000000000LL
#define EPS 1e-9
using namespace std;
#define MAXN 200010
lld X[MAXN], Y[MAXN];
lld sgnX[MAXN], sgnY[MAXN];
lld koefX[MAXN], koefY[MAXN];
lld flipped[MAXN];
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int N; cin >> N;
    for(int i = 1; i <= N; i++) cin >> X[i] >> Y[i];
    sgnX[0] = sgnY[0] = 1;
    koefX[0] = koefY[0] = 0;
    flipped[0] = 0;
    int M; cin >> M;
    for(int i = 1; i <= M; i++) {
        int tip; cin >> tip;
        if(tip == 1) {
            koefX[i] = koefY[i-1]; koefY[i] = -koefX[i-1];
            sgnX[i] = sgnY[i-1]; sgnY[i] = -sgnX[i-1];
            flipped[i] = 1^flipped[i-1];
        } else if(tip == 2) {
            koefX[i] = -koefY[i-1]; koefY[i] = koefX[i-1];
            sgnX[i] = -sgnY[i-1]; sgnY[i] = sgnX[i-1];
            flipped[i] = 1^flipped[i-1];
        } else if(tip == 3) {
            lld p; cin >> p;
            koefY[i] = koefY[i-1]; sgnY[i] = sgnY[i-1];
            koefX[i] = 2*p-koefX[i-1]; sgnX[i] = -sgnX[i-1];
            flipped[i] = flipped[i-1];
        } else if(tip == 4) {
            lld p; cin >> p;
            koefX[i] = koefX[i-1]; sgnX[i] = sgnX[i-1];
            koefY[i] = 2*p-koefY[i-1]; sgnY[i] = -sgnY[i-1];
            flipped[i] = flipped[i-1];
        }
    }
    int Q; cin >> Q;
    for(int i = 1; i <= Q; i++) {
        int A, B; cin >> A >> B;

        cout << sgnX[A]*(flipped[A] ? Y[B]:X[B]) + koefX[A] << ' ' << sgnY[A]*(flipped[A] ? X[B]:Y[B]) + koefY[A] << endl;
    }
    return 0;
}
