#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
#define pi M_PI
typedef pair<ll, ll> llPair;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef priority_queue<ll> pqll;
ll MOD = 1000000007;
/*
Really doe, like really doe
Really doe, like really doe
*/
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t;
    t = 1;
    for (ll z = 0; z < t; ++z)
    {
        ll h, w;
        cin >> h >> w;
        vector<vb> block(h, vb(w, false));
        vector<vll> dp(h, vll(w, 0));
        vector<vll> dig(h + 1, vll(w + 1, 0));
        vector<vll> hor(h + 1, vll(w + 1, 0));
        vector<vll> ver(h + 1, vll(w + 1, 0));
        for (ll i = 0; i < h; ++i)
        {
            for (ll j = 0; j < w; ++j)
            {
                char c;
                cin >> c;
                if (c == '#')
                {
                    block[i][j] = true;
                }
            }
        }
        dp[0][0] = 1;
        dig[1][1] = 1;
        hor[1][1] = 1;
        ver[1][1] = 1;
        for (ll i = 0; i < h; ++i)
        {
            for (ll j = 0; j < w; ++j)
            {
                if (i == 0 && j == 0)continue;
                else if (block[i][j])
                {
                    dp[i][j] = 0;
                    dig[i][j] = 0;
                    hor[i][j] = 0;
                    ver[i][j] = 0;
                }
                else
                {
                    dp[i][j] = hor[i][j + 1] + ver[i + 1][j] + dig[i][j];
                    dp[i][j] %= MOD;
                    hor[i + 1][j + 1] = (hor[i][j + 1] + dp[i][j]) % MOD;
                    dig[i + 1][j + 1] = (dig[i][j] + dp[i][j]) % MOD;
                    ver[i + 1][j + 1] = (ver[i + 1][j] + dp[i][j]) % MOD;
                }
            }
        }
        cout << dp[h - 1][w - 1] << '\n';
    }


    return 0;
}

// time-limit: 2000
#include<bits/stdc++.h>
using namespace std;

#define int long long
const int inf = 1e9 + 7;

void solve(){
    int n;
    cin >> n;
    vector<int> xi(n+1), yi(n+1);
    for(int i=1; i<=n; i++){
        cin >> xi[i] >> yi[i];
    }
    int m;
    cin >> m;
    typedef array<int, 3> arr;

    // 0:x, 1:y, 2:c
    vector<arr> X(m+1), Y(m+1);
    X[0][0] = 1;
    Y[0][1] = 1;
    X[0][1] = X[0][2] = Y[0][0] = Y[0][2] = 0;
    auto neg = [&](arr a){
        for(int i=0; i<3; i++){
            a[i] *= -1;
        }
        return a;
    };
    for(int i=1; i<=m; i++){
        int op;
        cin >> op;
        if(op == 1){
            X[i] = Y[i-1];
            Y[i] = neg(X[i-1]);
        } else if(op == 2){
            X[i] = neg(Y[i-1]);
            Y[i] = X[i-1];
        } else if(op == 3){
            int p;
            cin >> p;
            X[i] = neg(X[i-1]);
            X[i][2] += 2 * p;
            Y[i] = Y[i-1];
        } else{
            int p;
            cin >> p;
            X[i] = X[i-1];
            Y[i] = neg(Y[i-1]);
            Y[i][2] += 2 * p;
        }
    }

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int point, after;
        cin >> after >> point;
        cout << X[after][0]*xi[point] + X[after][1]*yi[point] + X[after][2] << ' ';
        cout << Y[after][0]*xi[point] + Y[after][1]*yi[point] + Y[after][2] << '\n';
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1, t = 0;
    while(t++ < T){
        //cout << "Case #" << t << ": ";
        solve();
    }

    return 0;
}
