#include <bits/stdc++.h>
int n, m, k;
std::vector<int> edg[100010];
int dfn[100010], low[100010];
std::vector<int> sta;
int bel[100010];
int nv;
std::vector<int> v1[100010];
std::vector<int> e1[100010];
void BCC(int now, int fa, int dep) {
  sta.push_back(now);
  low[now] = dfn[now] = dep;
  for (int i = 0; i < edg[now].size(); ++i) {
    int ne = edg[now][i];
    if (ne == fa) continue;
    if (dfn[ne] == 0) {
      BCC(ne, now, dep + 1);
      low[now] = std::min(low[ne], low[now]);
    } else
      low[now] = std::min(low[now], dfn[ne]);
  }
  if (low[now] != dfn[now]) return;
  ++nv;
  while (1) {
    int t = sta.back();
    sta.pop_back();
    v1[nv].push_back(t);
    bel[t] = nv;
    if (t == now) break;
  }
}
void BCC1() {
  int tem[100010];
  for (int i = 0; i <= n; ++i) tem[i] = -1;
  for (int a = 1; a <= nv; ++a) {
    tem[a] = a;
    for (int i = 0; i < v1[a].size(); ++i) {
      int now = v1[a][i];
      for (int j = 0; j < edg[now].size(); ++j) {
        int ne = edg[now][j];
        int b = bel[ne];
        if (tem[b] == a) continue;
        e1[a].push_back(b);
        tem[b] = a;
      }
    }
  }
}
int dou[20][100010];
int d1[100010];
void DFS(int now, int fa, int dep) {
  dou[0][now] = fa;
  for (int i = 1;; ++i) {
    int ne = dou[i - 1][now];
    if (ne == 0) break;
    dou[i][now] = dou[i - 1][ne];
  }
  d1[now] = dep;
  for (int i = 0; i < e1[now].size(); ++i) {
    int ne = e1[now][i];
    if (ne == fa) continue;
    DFS(ne, now, dep + 1);
  }
}
int go(int now, int d) {
  int p = now;
  while (1) {
    if (d1[p] == d) return p;
    for (int i = 1;; ++i) {
      int t = dou[i][p];
      if (d1[t] < d) {
        p = dou[i - 1][p];
        break;
      }
    }
  }
}
int chk(int mi, int st, int ed) { return go(st, mi) == go(ed, mi); }
int QUERY(int st, int ed) {
  int le = 1, ri = std::min(d1[st], d1[ed]);
  while (le < ri) {
    int mi = (le + ri + 1 >> 1);
    int val = chk(mi, st, ed);
    if (val == 1) le = mi;
    if (val == 0) ri = mi - 1;
  }
  int lca = go(st, le);
  return (-d1[lca] + d1[st]) + (-d1[lca] + d1[ed]);
}
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0, a, b; i < m; ++i) {
    scanf("%d%d", &a, &b);
    edg[a].push_back(b);
    edg[b].push_back(a);
  }
  BCC(1, 0, 1);
  BCC1();
  DFS(1, 0, 1);
  scanf("%d", &k);
  for (int count = 0, st, ed; count < k; ++count) {
    scanf("%d%d", &st, &ed);
    printf("%d\n", QUERY(bel[st], bel[ed]));
  }
  return 0;
}
