/*

強連結成分アルゴリズムアルゴリズム

input:有向グラフG
output:各店の属する強連結成分を表す関数comp:V(G)->N

*/

#include <vector>
#include <functional>
using namespace std;

vector<int> scc(const vector<vector<int>>& G){
    vector<int> comp(G.size(),-1);
    vector<int> R(G.size(),0);
    int N = 0;
    vector<int> psi(G.size(),-1);
    vector<int> psi_inv(G.size(),-1);

    function<void(int)> visit1 = [&](int v){
        R[v] = 1;
        for(int w : G[v]){
            if(R[w] == 0) visit1(w);
        }
        psi[v] = N;
        psi_inv[N] = v;
        N = N + 1;
    };

    for(int i = 0;i < G.size();i++){
        if(R[i] == 0) visit1(i);
    }

    R.assign(G.size(),0);
    int K = 0;

    vector<vector<int>> rev_G(G.size());

    for(int v = 0;v < G.size();v++){
        for(int to : G[v]) rev_G[to].push_back(v);
    }

    function<void(int)> visit2 = [&](int v){
        R[v] = 1;
        for(int w : rev_G[v]){
            if(R[w] == 0) visit2(w);
        }
        comp[v] = K;
    };

    for(int i = G.size() - 1;i >= 0;i--){
        if(R[psi_inv[i]] == 0){
            visit2(psi_inv[i]);
            K = K + 1;
        }
    }
    return comp;
}

#include <iostream>

int main(){
    int v;
    int e;
    cin >> v >> e;
    vector<vector<int>> G(v);
    for(int i = 0;i < e;i++){
        int x,y;
        cin >> x >> y;
        G[x].push_back(y);
    
    }

    auto res = scc(G);

    int q;
    cin >> q;

    for(int i = 0;i < q;i++){
        int x,y;
        cin >> x >> y;
        cout << (res[x] == res[y]) << endl;
    }
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, m, q; cin >> n >> m >> q;
    vector<vector<int>> S(n, vector<int>(n));
    rep(i, m){
        int l, r; cin >> l >> r; l--, r--;
        S[l][r]++;
    }
    rep(i, n){
        rep(j, n-1){
            S[i][j+1] += S[i][j];
        }
    }
    rep(j, n){
        for(int i=n-1; i>0; i--){
            S[i-1][j] += S[i][j];
        }
    }

    vector<int> res(q);
    rep(i, q){
        int p, q; cin >> p >> q; p--, q--;
        res[i] = S[p][q]; 
    }
    for(auto r: res) cout << r << ln;
}
