#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
vector<vector<int> > adj, tree;
int cnt, low[MAXN], pre[MAXN], visit[MAXN], deg[MAXN], degcnt;
stack<int> que;
void dfs(int u, int w) {
  int v;
  visit[u] = 1;
  que.push(u);
  low[u] = pre[u] = cnt++;
  int i, len = adj[u].size();
  for (i = 0; i < len; i++) {
    v = adj[u][i];
    if (v == w) continue;
    if (visit[v] == 0) {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
    } else if (visit[v] == 1)
      low[u] = min(low[u], pre[v]);
  }
  visit[u] = 2;
  if (pre[u] == low[u]) {
    while (!que.empty()) {
      int x = que.top();
      que.pop();
      if (x == u) {
        break;
      }
      low[x] = min(low[u], low[x]);
    }
  }
}
int fa[MAXN], fat[20][MAXN], lev[MAXN];
void fs(int u, int w, int l) {
  fa[u] = w;
  lev[u] = l;
  int v;
  int i, len = tree[u].size();
  for (i = 0; i < len; i++) {
    v = tree[u][i];
    if (v == w) continue;
    fs(v, u, l + 1);
  }
}
void gao() {
  int i, j;
  for (i = 0; i < cnt; i++) {
    fat[0][i] = fa[i];
  }
  for (i = 1; i < 20; i++) {
    for (j = 0; j < cnt; j++) {
      fat[i][j] = fat[i - 1][fat[i - 1][j]];
    }
  }
}
int gao2(int i, int n) {
  int ans = i;
  int t = 0;
  while (n) {
    if (n & 1) ans = fat[t][ans];
    n >>= 1;
    t++;
  }
  return ans;
}
int gao(int u, int v) {
  int x, y;
  int t = max(lev[u], lev[v]) - min(lev[u], lev[v]);
  x = gao2(u, 0);
  y = gao2(v, 0);
  if (lev[u] > lev[v])
    x = gao2(x, t);
  else
    y = gao2(y, t);
  int ans = t;
  int l = 0, r = cnt, m;
  while (l <= r) {
    m = (l + r) >> 1;
    if (gao2(x, m) == gao2(y, m))
      r = m - 1;
    else
      l = m + 1;
  }
  ans += 2 * l;
  return ans;
}
int main() {
  int i, j, u, v, n, m, len, ans;
  scanf("%d %d", &n, &m);
  adj.assign(n + 1, vector<int>());
  while (m--) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v), adj[v].push_back(u);
  }
  degcnt = cnt = 0, dfs(1, 1);
  tree.assign(n + 1, vector<int>());
  int tmp = 0;
  for (i = 1; i <= n; i++) {
    len = adj[i].size();
    for (j = 0; j < len; j++)
      if (low[i] != low[adj[i][j]])
        tree[low[i]].push_back(low[adj[i][j]]), tmp++;
  }
  while (!que.empty()) que.pop();
  fs(low[i], 0, 0);
  gao();
  int k;
  scanf("%d", &k);
  while (k--) {
    scanf("%d %d", &u, &v);
    printf("%d\n", gao(low[u], low[v]));
  }
  return 0;
}
