#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
struct node {
  int x, y, id, next;
} line[500005];
struct NODE {
  int y, w;
};
int Lnum, top[500005], _next[500005], dfn[500005], low[500005], DfsIndex,
    ans[500005], father[500005];
int tp[500005], tpnum;
bool used[500005], bridge[500005];
void addline(int x, int y, int id) {
  line[++Lnum].next = _next[x], _next[x] = Lnum;
  line[Lnum].x = x, line[Lnum].y = y, line[Lnum].id = id;
}
vector<NODE> T[500005];
void tarjan(int x, int id) {
  int y, k;
  dfn[x] = low[x] = ++DfsIndex;
  for (k = _next[x]; k; k = line[k].next)
    if (line[k].id != id) {
      y = line[k].y;
      if (!dfn[y]) {
        tarjan(y, line[k].id);
        low[x] = min(low[x], low[y]);
        if (dfn[x] < low[y]) bridge[line[k].id] = true;
      } else
        low[x] = min(low[x], dfn[y]);
    }
  return;
}
void dfs(int x) {
  int y, k;
  tp[x] = tpnum;
  for (k = _next[x]; k; k = line[k].next) {
    y = line[k].y;
    if (bridge[line[k].id] || tp[y]) continue;
    dfs(y);
  }
  return;
}
int getfather(int x) {
  if (x == father[x]) return x;
  return father[x] = getfather(father[x]);
}
void Tarjan_LCA(int x) {
  int y, k, m = T[x].size();
  NODE h;
  used[x] = true;
  father[x] = x;
  for (k = 0; k < m; k++) {
    h = T[x][k];
    if (!used[h.y]) continue;
    ans[h.w] = top[x] + top[h.y] - 2 * top[getfather(h.y)];
  }
  for (k = _next[x]; k; k = line[k].next) {
    y = line[k].y;
    if (used[y]) continue;
    top[y] = top[x] + 1;
    Tarjan_LCA(y);
    father[y] = x;
  }
  return;
}
int main() {
  int i, N, M, K;
  scanf("%d%d", &N, &M);
  memset(_next, 0, sizeof(_next));
  Lnum = 0;
  for (i = 1; i <= M; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    addline(x, y, i), addline(y, x, i);
  }
  memset(dfn, 0, sizeof(dfn));
  DfsIndex = 0;
  memset(bridge, false, sizeof(bridge));
  tarjan(1, -1);
  memset(tp, 0, sizeof(tp));
  tpnum = 0;
  for (i = 1; i <= N; i++)
    if (!tp[i]) {
      tpnum++;
      dfs(i);
    }
  int temp = Lnum;
  Lnum = 0;
  memset(_next, 0, sizeof(_next));
  for (i = 1; i <= temp; i++) {
    int x = tp[line[i].x], y = tp[line[i].y];
    if (x == y) continue;
    addline(x, y, 0);
  }
  scanf("%d", &K);
  for (i = 1; i <= N; i++) T[i].clear();
  for (i = 1; i <= K; i++) {
    int x, y;
    NODE h;
    scanf("%d%d", &x, &y);
    x = tp[x], y = tp[y];
    h.y = y, h.w = i;
    T[x].push_back(h);
    h.y = x;
    T[y].push_back(h);
  }
  memset(used, false, sizeof(used));
  top[1] = 1;
  Tarjan_LCA(1);
  for (i = 1; i <= K; i++) printf("%d\n", ans[i]);
  return 0;
}
