#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[111], B[111];

int cnt[211];

bool dp[211];

int AB[211], BA[211];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) {
	scanf("%d%d", A+i, B+i);
	if (A[i] != -1) A[i]--;
	if (B[i] != -1) B[i]--;
    }

    bool yes = true;
    REP (i, N) {
	if (A[i] == 2*N-1) yes = false;
	if (B[i] == 0) yes = false;
	if (A[i] != -1 && B[i] != -1 && B[i] <= A[i]) yes = false;

	if (A[i] != -1) cnt[A[i]]++;
	if (B[i] != -1) cnt[B[i]]++;
    }

    if (yes) {
	REP (i, 2*N) {
	    if (cnt[i] >= 2) yes = false;
	}
    }

    if (yes) {
	REP (i, N*2) {
	    AB[i] = -2;
	    BA[i] = -2;
	}
	REP (i, N) {
	    if (A[i] != -1) AB[A[i]] = B[i];
	    if (B[i] != -1) BA[B[i]] = A[i];
	}

	dp[0] = true;
	for (int i=0; i<N*2; i+=2) if (dp[i]) {
	    for (int h=1; i+h+h<=N*2; h++) {
		bool ok = true;
		for (int k=i; ok && k<i+h; k++) {
		    if (AB[k] == -1 && BA[k+h] != -2) ok = false;
		    if (BA[k+h] == -1 && AB[k] != -2) ok = false;
		    if (0 <= AB[k] && AB[k] != k+h) ok = false;
		    if (0 <= BA[k]) ok = false;
		    if (0 <= BA[k+h] && BA[k+h] != k) ok = false;
		    if (0 <= AB[k+h]) ok = false;
		}

		if (ok) dp[i+h+h] = true;
	    }
	}

	yes = dp[N*2];
    }

    puts(yes? "Yes": "No");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=1e18;

struct Q{
    int a;
    int b;
    int i;
    bool operator<(const Q &another) const {return a < another.a;};
};

int main(){
    int n; cin >> n;
    VI x(n), y(n);
    REP(i,n) cin >> x[i] >> y[i];
    int m; cin >> m;
    VI op(m), p(m,-1);
    REP(i,m){
        cin >> op[i];
        if(op[i]>=3)
            cin >> p[i];
    }
    int q; cin >> q;
    vector<Q> qu(q);
    REP(i,q){
        cin >> qu[i].a >> qu[i].b;
        qu[i].b--;
        qu[i].i=i;
    }
    sort(ALL(qu));
    qu.push_back({0,0,-1});
    int rad=0;
    bool xr=0, yr=0;
    ll xd=0, yd=0;
    int now=0;
    vector<P> ans(q);
    while(qu[now].a==0){
        ans[qu[now].i]={x[qu[now].b],y[qu[now].b]};
        now++;
    }
    REP(i,m){
        if(op[i]==1){
            rad=(rad+1)%4;
            xd=-xd;
            swap(xd,yd);
            swap(xr,yr);
        }
        else if(op[i]==2){
            rad=(rad+3)%4;
            yd=-yd;
            swap(xd,yd);
            swap(xr,yr);
        }
        else if(op[i]==3){
            xd=-xd+p[i]*2;
            xr=!xr;
        }
        else{
            yd=-yd+p[i]*2;
            yr=!yr;
        }
        while(qu[now].a==i+1){
            int j=qu[now].i;
            ll ansx=x[qu[now].b];
            ll ansy=y[qu[now].b];
            if(rad==0){
                ans[j]={ansx,ansy};
            }
            else if(rad==1){
                ans[j]={ansy,-ansx};
            }
            else if(rad==2){
                ans[j]={-ansx,-ansy};
            }
            else{
                ans[j]={-ansy,ansx};
            }
            ans[j].first=ans[j].first*(xr?-1:1)+xd;
            ans[j].second=ans[j].second*(yr?-1:1)+yd;
            now++;
        }
    }
    REP(i,q){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}