#include <bits/stdc++.h>
using namespace std;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int col[100005];
graph g;
bool color(int x){
  bool ok = true;
  for(auto nx:g[x]){
    if(col[nx]!=-1) {
      if(col[nx]==col[x]) ok = false;
      else continue;
    }
    else {
      col[nx] = 1-col[x];
      if(!color(nx)) ok = false;
    }
  }
  return ok;
}

int main() {
  ll N,M;
  cin>>N>>M;
  g.resize(N);
  rep(i,100005) col[i] = -1;
  col[0]=0;
  rep(i,M){
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  bool can = color(0);
  if(!can) cout<<N*(N-1)/2-M<<endl;
  else{
    ll cnt0 = 0,cnt1 = 0;
    rep(i,N) {
      if(col[i]==0) cnt0++;
      if(col[i]==1) cnt1++;
    }
    cout<<cnt0*cnt1-M<<endl;
  }
}
#include <bits/stdc++.h>
//#include <ext/numeric>


using namespace std;
//using namespace __gnu_cxx;


int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
//    freopen("fence.out", "w", stdout);
#endif

    int n;
    cin >> n;
    vector<int> arr(n);
    for (int &x : arr)
        cin >> x;
    int l;
    cin >> l;

    int log = ceil(log2(n));
    vector<vector<int>> par(n, vector<int>(log + 1));
    auto build = [&]() {
        int j = n - 1;
        for (int i = n - 1; ~i; --i) {
            while (arr[j] - arr[i] > l)
                --j;
            par[i][0] = j;
        }
    };
    build();



    for (int v = n - 1; ~v; --v) {
        for (int p = 1; p <= log; ++p)
            par[v][p] = par[par[v][p - 1]][p - 1];
    }


    int q;
    cin >> q;
    while(q--) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        if (u > v)
            swap(u, v);
        int ans = 0;
        for (int p = log; ~p; --p) {
            if (par[u][p] < v) {
                ans += (1 << p);
                u = par[u][p];
            }
        }
        cout << ans + 1 << '\n';
    }


    return 0;
}