#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 5, MAXL = 18;
vector<int> adj[MAXN];
set<int> compAdj[MAXN];
int N, M, K, C = 0;
int compID[MAXN];
int currIter = 0;
stack<int> nodeStack;
int disc[MAXN], lowlink[MAXN];
void dfsComps(int n, int p) {
  if (false) cerr << "dfs " << n << " " << p << '\n';
  nodeStack.push(n);
  disc[n] = currIter;
  lowlink[n] = currIter++;
  for (int e : adj[n]) {
    if (e == p)
      continue;
    else if (disc[e] == -1) {
      dfsComps(e, n);
      lowlink[n] = min(lowlink[e], lowlink[n]);
      if (lowlink[e] > disc[n]) {
        while (nodeStack.top() != e) {
          compID[nodeStack.top()] = C;
          nodeStack.pop();
        }
        compID[nodeStack.top()] = C;
        nodeStack.pop();
        C++;
      }
    } else {
      lowlink[n] = min(disc[e], lowlink[n]);
    }
  }
}
int lcaArr[MAXL][MAXN], depth[MAXN];
void setupTree(int n, int p) {
  lcaArr[0][n] = p;
  depth[n] = depth[p] + 1;
  for (int e : compAdj[n]) {
    if (e == p) continue;
    setupTree(e, n);
  }
}
int countEdges(int a, int b) {
  if (depth[a] < depth[b]) swap(a, b);
  int toMove = depth[a] - depth[b];
  int ans = toMove;
  for (int i = MAXL - 1; i >= 0; i--) {
    if ((1 << i) <= toMove) {
      toMove -= 1 << i;
      a = lcaArr[i][a];
    }
  }
  if (a == b) return ans;
  for (int i = MAXL - 1; i >= 0; i--) {
    if (lcaArr[i][a] != lcaArr[i][b]) {
      ans += 1 << (i + 1);
      a = lcaArr[i][a];
      b = lcaArr[i][b];
    }
  }
  return ans + 2;
}
void solve() {
  cin >> N >> M;
  for (int i = (0); i < (M); i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = (0); i < (N); i++) {
    compID[i] = -1;
    disc[i] = -1;
  }
  dfsComps(0, 0);
  while (!nodeStack.empty()) {
    compID[nodeStack.top()] = C;
    nodeStack.pop();
  }
  C++;
  for (int n = (0); n < (N); n++) {
    assert(compID[n] != -1);
    for (int e : adj[n]) {
      if (compID[n] == compID[e]) continue;
      compAdj[compID[n]].insert(compID[e]);
      compAdj[compID[e]].insert(compID[n]);
    }
  }
  int treeEdges = 0;
  for (int n = (0); n < (C); n++) treeEdges += ((int)compAdj[n].size());
  assert(treeEdges / 2 == C - 1);
  setupTree(0, 0);
  for (int i = (1); i < (MAXL); i++) {
    for (int n = (0); n < (C); n++) {
      lcaArr[i][n] = lcaArr[i - 1][lcaArr[i - 1][n]];
    }
  }
  cin >> K;
  for (int i = (0); i < (K); i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    a = compID[a], b = compID[b];
    cout << countEdges(a, b) << '\n';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
