#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

const int MAX_N=10000;
vector<VI> g1(MAX_N);
vector<VI> g2(MAX_N);
VI flag(MAX_N);
int fcnt = 0;
int gcnt = 0;
vector<bool>vis(MAX_N, false);
VI group(MAX_N);

void dfs(int v) {
	vis[v] = true;
	for (int w : g1[v]) {
		if (!vis[w])dfs(w);
	}
	flag[fcnt] = v;
	//cout << fcnt << " " << v << endl;
	fcnt++;
}

void rdfs(int v) {
	vis[v] = false;
	group[v] = gcnt;
	//cout << v << " " << gcnt << endl;
	for (int w : g2[v]) {
		if (vis[w])rdfs(w);
	}
}


signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		g1[a].push_back(b);
		g2[b].push_back(a);
	}
	REP(i, N) {
		if (!vis[i])dfs(i);
	}
	//REP(i, N)cout << flag[i] << endl;

	for (int i = N - 1; i >= 0; i--) {
		if (vis[flag[i]]) {
			//cout << i << endl;
			rdfs(flag[i]);
			gcnt++;
		}
	}
	//REP(i, N)cout << group[i] << endl;

	int Q;
	cin >> Q;
	REP(i, Q) {
		int a, b;
		cin >> a >> b;
		cout << (group[a] == group[b]) << endl;
	}
	return 0;
}



#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 vtpl(x,y,z) vector<tuple<x,y,z>>
#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<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 

int main(){
    ll n;cin >> n;
    vl a(n);rep(i,n)cin >> a[i];
    ll l;cin >> l;
    vvl v(21,vl(n));
    rep(i,n){
        auto itr=upper_bound(all(a),a[i]+l);
        itr--;
        v[0][i]=itr-a.begin();
        if(i==n-1)v[0][i]=inf;
    }
    rep(j,20){
        rep(i,n){
            if(v[j][i]==inf)v[j+1][i]=inf;
            else v[j+1][i]=v[j][v[j][i]];
        }
    }
    /*rep(j,20){
        rep(i,n){
            cout << v[j][i] <<" ";
        }
        cout << endl;
    }*/
    //exit(0);
    ll q;cin >> q;
    while(q--){
        ll a,b;cin >> a >> b;a--;b--;
        if(a>b)swap(a,b);
        ll ng=0,ok=100000;
        while(abs(ok-ng)>1){
            ll mid=(ok+ng)/2;
            ll t=a;
            rep(i,20){
                if(t==inf)break;
                if(mid&(1<<i)){
                    t=v[i][t];
                }
            }
            if(t>=b)ok=mid;
            else ng=mid;
        }
        cout << ok <<endl;
    }
}