#include <bits/stdc++.h>
using namespace std;
const int lim = 100005;
int n, m, a, b;
int pre[lim];
int low[lim];
int idk[lim];
int kto[lim];
int scc = 1, prel = 1;
vector<int> g[lim];
vector<int> g2[lim];
vector<pair<int, int> > temp;
int sk[lim][17];
int dp[lim];
int n2;
int fin(int x) {
  if (idk[x] != x) {
    idk[x] = fin(idk[x]);
  }
  return idk[x];
}
int lca(int a1, int b1) {
  int ret, help = 1;
  if (dp[a1] < dp[b1]) swap(a1, b1);
  ret = dp[a1] - dp[b1];
  for (int i = 0; i < 17; i++) {
    if (ret & help) {
      a1 = sk[a1][i];
    }
    help <<= 1;
  }
  if (a1 == b1) return ret;
  for (int i = 16; i >= 0; i--) {
    if (sk[a1][i] != sk[b1][i]) {
      ret += (1 << (i + 1));
      a1 = sk[a1][i];
      b1 = sk[b1][i];
    }
  }
  return ret + 2;
}
void dfs2(int x, int par) {
  sk[x][0] = par;
  dp[x] = dp[par] + 1;
  for (int i = 0; i < g2[x].size(); i++) {
    if (g2[x][i] != par) dfs2(g2[x][i], x);
  }
}
void grafuj() {
  int a1, b1;
  while (!temp.empty()) {
    a1 = temp.back().first;
    b1 = temp.back().second;
    temp.pop_back();
    a1 = kto[a1];
    b1 = kto[b1];
    n2 = max(n2, max(a1, b1));
    g2[a1].push_back(b1);
    g2[b1].push_back(a1);
  }
}
void dfs(int x, int par) {
  pre[x] = prel;
  prel++;
  low[x] = pre[x];
  idk[x] = par;
  for (int i = 0; i < g[x].size(); i++) {
    if (!pre[g[x][i]]) {
      dfs(g[x][i], x);
      if (low[x] > low[g[x][i]]) low[x] = low[g[x][i]];
    } else {
      if (g[x][i] != par && low[x] > pre[g[x][i]]) low[x] = pre[g[x][i]];
    }
  }
  if (low[x] == pre[x]) {
    temp.push_back({x, par});
    idk[x] = x;
    kto[x] = scc;
    scc++;
  }
}
int k;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 1);
  for (int i = 1; i <= n; i++) kto[i] = kto[fin(i)];
  grafuj();
  dfs2(1, 1);
  for (int i = 1; i < 17; i++) {
    for (int j = 1; j <= n2; j++) sk[j][i] = sk[sk[j][i - 1]][i - 1];
  }
  cin >> k;
  while (k--) {
    cin >> a >> b;
    cout << lca(kto[a], kto[b]) << "\n";
  }
  return 0;
}
