#include <bits/stdc++.h>
using namespace std;
int n, m, k, tot, low[100005], dfn[100005], t1, f[20][100005 * 2], pos[100005],
    w[100005], z[100005];
vector<int> a[100005];
void tarjan(int i, int fa) {
  dfn[i] = low[i] = ++t1;
  for (__typeof((a[i]).begin()) p = (a[i]).begin(); p != (a[i]).end(); p++)
    if (*p != fa)
      if (dfn[*p])
        low[i] = min(low[i], dfn[*p]);
      else {
        tarjan(*p, i);
        low[i] = min(low[i], low[*p]);
      }
  if (low[i] == dfn[i]) w[i] = 1;
}
void dfs(int i, int d) {
  pos[i] = ++tot;
  f[0][tot] = d;
  for (__typeof((a[i]).begin()) p = (a[i]).begin(); p != (a[i]).end(); p++)
    if (!pos[*p]) {
      dfs(*p, d + w[*p]);
      f[0][++tot] = d;
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (m); i++) {
    int s, t;
    scanf("%d%d", &s, &t);
    a[s].push_back(t);
    a[t].push_back(s);
  }
  tarjan(1, 0);
  dfs(1, 1);
  for (int j = (1); j <= (18); j++)
    for (int i = (1); i <= (n * 2 - 1); i++)
      if (i + (1 << j) - 1 <= n * 2 - 1)
        f[j][i] = min(f[j - 1][i], f[j - 1][i + (1 << j - 1)]);
  scanf("%d", &m);
  for (int i = (1); i <= (m); i++) {
    int s, t, l;
    scanf("%d%d", &s, &t);
    s = pos[s];
    t = pos[t];
    if (s > t) swap(s, t);
    l = (int)trunc(log(t - s + 1) / log(2));
    printf("%d\n",
           f[0][s] + f[0][t] - 2 * min(f[l][s], f[l][t - (1 << l) + 1]));
  }
  return 0;
}
