#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 7;
const long long maxe = 1e6 + 7;
const long long INF = 1e9 + 7;
const double PI = acos(-1);
int dx[4] = {0, 0, 1, -1};
int dy[4] = {-1, 1, 0, 0};
int n, m;
int q;
struct edge {
  int to, next, ok;
} ee[maxn << 1];
int fa[maxn];
int vis[maxn];
int tol = 0;
int head[maxn << 1];
int lca[maxn][25];
int h[maxn];
int logn = 20;
void init() {
  tol = 0;
  memset(head, 0xff, sizeof(head));
}
void adde(int a, int b) {
  ee[tol].to = b, ee[tol].next = head[a], ee[tol].ok = 0, head[a] = tol++;
  ee[tol].to = a, ee[tol].next = head[b], ee[tol].ok = 0, head[b] = tol++;
}
int bnt = 0;
int cnt = 0;
int low[maxn];
int dfn[maxn];
stack<int> s;
int ins[maxn];
void dfs(int u, int pre) {
  low[u] = dfn[u] = cnt++;
  vis[u] = 1;
  ins[u] = 1;
  s.push(u);
  for (int i = head[u]; i >= 0; i = ee[i].next) {
    int z = ee[i].to;
    if (z == pre) continue;
    if (!vis[z]) {
      ee[i].ok = 1;
      ee[i ^ 1].ok = 1;
      dfs(z, u);
      low[u] = min(low[u], low[z]);
    } else if (ins[z] == 1) {
      low[u] = min(low[u], dfn[z]);
    }
  }
  if (dfn[u] == low[u]) {
    bnt++;
    while (!s.empty()) {
      int z = s.top();
      s.pop();
      ins[z] = 0;
      fa[z] = bnt;
      if (z == u) break;
    }
  }
}
void tarjan() {
  memset(vis, 0, sizeof(vis));
  while (!s.empty()) s.pop();
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i, 0);
    }
  }
}
void df(int u) {
  vis[u] = 1;
  int z = fa[u];
  for (int i = 1; i <= logn; i++) {
    lca[z][i] = lca[lca[z][i - 1]][i - 1];
  }
  for (int i = head[u]; i >= 0; i = ee[i].next) {
    if (!vis[ee[i].to]) {
      int zz = fa[ee[i].to];
      if (z != zz) {
        h[zz] = h[z] + 1;
        lca[zz][0] = z;
      }
      df(ee[i].to);
    }
  }
}
int Lca(int a, int b) {
  if (h[a] < h[b]) swap(a, b);
  for (int i = 0; i < logn; i++) {
    if (((h[a] - h[b]) >> i) & 1) a = lca[a][i];
  }
  if (a == b) return a;
  for (int i = logn - 1; i >= 0; i--) {
    if (lca[a][i] != lca[b][i]) {
      a = lca[a][i];
      b = lca[b][i];
    }
  }
  return lca[a][0];
}
int main() {
  cin >> n >> m;
  init();
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adde(a, b);
  }
  tarjan();
  memset(vis, 0, sizeof(vis));
  memset(lca, 0, sizeof(lca));
  h[fa[1]] = 1;
  df(1);
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", h[fa[a]] + h[fa[b]] - 2 * h[Lca(fa[a], fa[b])]);
  }
  return 0;
}
