#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double eps = 1e-5;
const int maxN = 1e5;
const int maxL = 20;
const int inf = 1e9;
int n, m, k;
vector<pair<int, int> > G[maxN], G2[maxN];
bool vis[maxN];
bool cutE[maxN];
int h[maxN], sum[maxN], p[maxN][maxL];
int dep[maxN];
inline int dfs(int v, int d = 0, int par = -1) {
  vis[v] = 1;
  h[v] = d;
  int ret = inf;
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i].first == par) continue;
    if (vis[G[v][i].first]) {
      ret = min(ret, h[G[v][i].first]);
    } else {
      int t = dfs(G[v][i].first, d + 1, v);
      if (t > d) cutE[G[v][i].second] = 1;
      ret = min(ret, t);
    }
  }
  return ret;
}
inline void dfs2(int v) {
  vis[v] = 1;
  for (int i = 0; i < G[v].size(); i++) {
    if (!vis[G[v][i].first]) {
      G2[v].push_back(G[v][i]);
      G2[G[v][i].first].push_back(make_pair(v, G[v][i].second));
      dfs2(G[v][i].first);
    }
  }
}
inline void dfs3(int v = 0, int cnt = 0, int par = -1, int d = 0) {
  sum[v] = cnt;
  dep[v] = d;
  p[v][0] = par;
  for (int i = 0; i < G2[v].size(); i++) {
    if (G2[v][i].first != par) {
      int t = G2[v][i].second;
      dfs3(G2[v][i].first, cnt + cutE[t], v, d + 1);
    }
  }
}
inline int lca(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  for (int i = maxL - 1; i >= 0; i--)
    if (p[a][i] != -1 && dep[p[a][i]] >= dep[b]) a = p[a][i];
  if (a == b) return a;
  for (int i = maxL - 1; i >= 0; i--)
    if (p[a][i] != p[b][i]) a = p[a][i], b = p[b][i];
  return p[a][0];
}
inline void init() {
  memset(p, -1, sizeof p);
  scanf("%d%d", &n, &m);
  for (int i = 0, a, b; i < m; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    G[a].push_back(make_pair(b, i));
    G[b].push_back(make_pair(a, i));
  }
  dfs(0);
  memset(vis, 0, sizeof vis);
  dfs2(0);
  dfs3();
  for (int i = 1; i < maxL; i++)
    for (int j = 0; j < n; j++)
      p[j][i] = (p[j][i - 1] == -1) ? -1 : p[p[j][i - 1]][i - 1];
}
inline void solve() {
  scanf("%d", &k);
  int a, b;
  while (k--) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    int t = lca(a, b);
    printf("%d\n", sum[a] + sum[b] - 2 * sum[t]);
  }
}
int main() {
  init();
  solve();
  return 0;
}
