#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 7, MAX_LOG = 20;
int n, m;
vector<int> adj[MAXN];
bool isPassed[MAXN];
int par[MAXN][MAX_LOG], cycleCnt[MAXN], h[MAXN];
void pre(int root) {
  isPassed[root] = true;
  for (auto nei : adj[root]) {
    if (!isPassed[nei]) {
      par[nei][0] = root;
      h[nei] = h[root] + 1;
      pre(nei);
      cycleCnt[root] = cycleCnt[root] + cycleCnt[nei];
    } else if (par[root][0] != nei and h[nei] < h[root]) {
      cycleCnt[nei]--;
      cycleCnt[root]++;
    }
  }
  return;
}
int nanCyCnt[MAXN][MAX_LOG];
void dfs(int root, int lstRt) {
  par[root][0] = lstRt;
  if (lstRt != -1 and cycleCnt[root] == 0) nanCyCnt[root][0] = 1;
  for (int i = 1; i < MAX_LOG and h[root] >= (1 << i) and
                  par[par[root][i - 1]][i - 1] != -1;
       ++i) {
    par[root][i] = par[par[root][i - 1]][i - 1];
    nanCyCnt[root][i] =
        nanCyCnt[root][i - 1] + nanCyCnt[par[root][i - 1]][i - 1];
  }
  isPassed[root] = true;
  for (auto nei : adj[root]) {
    if (!isPassed[nei]) {
      h[nei] = h[root] + 1;
      dfs(nei, root);
    }
  }
  return;
}
int lca(int v, int u) {
  int nancy = 0;
  if (h[v] > h[u]) swap(v, u);
  for (int i = 0; h[v] ^ h[u]; ++i) {
    if ((h[u] - h[v]) & (1 << i)) {
      nancy += nanCyCnt[u][i];
      u = par[u][i];
    }
  }
  if (v == u) return nancy;
  for (int i = MAX_LOG - 1; i >= 0; --i) {
    if (par[v][i] != par[u][i]) {
      nancy += (nanCyCnt[v][i] + nanCyCnt[u][i]);
      v = par[v][i], u = par[u][i];
    }
  }
  return nancy + nanCyCnt[v][0] + nanCyCnt[u][0];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(par, -1, sizeof par);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int v, u;
    cin >> v >> u, v--, u--;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  memset(isPassed, 0, sizeof isPassed);
  pre(0);
  memset(isPassed, 0, sizeof isPassed);
  memset(h, 0, sizeof h);
  dfs(0, -1);
  int mercsNum;
  cin >> mercsNum;
  while (mercsNum--) {
    int sh, wa;
    cin >> wa >> sh, wa--, sh--;
    cout << lca(wa, sh) << "\n";
  }
  return 0;
}
