#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int main(){
    int N;
    cin >> N;
    vp r(N),b(N);
    rep(i,N) cin >>r[i].F>>r[i].S;
    rep(i,N) cin >>b[i].F>>b[i].S;
    vi left(N,0);
    vi max(N,0);

    sort(all(b));
    sort(all(r));

    int jj=0;
    int ans=0;
    rep(i,N){//ao
        bool judge=false;
        rep(j,N){//aka
            if(left[j] ==0){
                if(r[j].F<b[i].F && r[j].S<b[i].S && r[j].S>=max[i]){
                    max[i]=r[j].S;
                    jj = j;
                    judge = true;
                }
            } 
        }
        if(judge) {
            ans++;
            left[jj] = 1;
        }
    }
    cout <<ans<<endl;
}
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <bitset>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef unsigned long long ull;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int INF = 1 << 27;
//////////////////////////////
// ?????£?????????????§£
void dfs(int v, int *used, vector< vector<int> > &G, vector<int> &vs){
  used[v] = true;
  REP(i, G[v].size()){
    int next = G[v][i];
    if(!used[next]) dfs(next, used, G, vs);
  }
  vs.push_back(v);
}
void rdfs(int v, int cnt, int *used, vector<int> &cmp, vector< vector<int> > &G){
  used[v] = true;
  cmp[v] = cnt;
  REP(i, G[v].size()){
    int next = G[v][i];
    if(!used[next]) rdfs(next, cnt, used, cmp, G);
  }
}
//G????????????????????°???????????£??\????????????RG????????????????????????????????£??\?????????
//?????????????????????????????????????????????????????£?????????????±?????????????cmp[a] == cmp[b]??????????????°a, b???????????????????±??????????
vector<int> scc(int V, vector< vector<int> > &G, vector< vector<int> > &RG){
  int used[V];
  memset(used, 0, sizeof(used));
  vector<int> vs, cmp(V);
  REP(i, V) if(!used[i]) dfs(i, used, G, vs);
  memset(used, 0, sizeof(used));
  int cnt = 0;
  reverse(vs.begin(), vs.end());
  REP(i, vs.size()) if(!used[vs[i]]) rdfs(vs[i], cnt++, used, cmp, RG);
  return cmp;
}

int main() {
	int v, e; cin >> v >> e;
	vector<vi> vvi(v), rvvi(v);
	REP(i, e) {
		int a,b; cin >> a >> b;
		vvi[a].pb(b);
		rvvi[b].pb(a);
	}
	vi ans = scc(v, vvi, rvvi);
	int q; cin >> q;
	while(q--) {
		int a, b; cin >> a >> b;
		cout << (ans[a] == ans[b]) << endl;
	}

	return 0;
}