#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int num = 1;
struct node {
  int to;
  int next;
} road[400010];
int head[200010];
int low[100010], dfn[100010], cut[200010], tot = 0;
int cnt = 0, vis[100010], belong[100010];
int pre[200010][20], deep[200010];
void build(int from, int to) {
  road[++num].next = head[from];
  road[num].to = to;
  head[from] = num;
}
void tarjan(int x, int in_edge) {
  low[x] = dfn[x] = ++tot;
  for (int i = head[x]; i; i = road[i].next) {
    int y = road[i].to;
    if (!dfn[y]) {
      tarjan(y, i);
      low[x] = min(low[x], low[y]);
      if (dfn[x] < low[y]) {
        cut[i] = cut[i ^ 1] = 1;
      }
    } else if (i != (in_edge ^ 1))
      low[x] = min(low[x], dfn[y]);
  }
}
void dfs(int x) {
  vis[x] = 1;
  belong[x] = cnt;
  for (int i = head[x]; i; i = road[i].next) {
    if (cut[i]) continue;
    int y = road[i].to;
    if (vis[y]) continue;
    dfs(y);
  }
}
void dfs2(int x, int fa) {
  pre[x][0] = fa;
  deep[x] = deep[fa] + 1;
  for (int i = 1; i <= 18; i++) {
    pre[x][i] = pre[pre[x][i - 1]][i - 1];
  }
  for (int i = head[x]; i; i = road[i].next) {
    int y = road[i].to;
    if (y == fa) continue;
    dfs2(y, x);
  }
}
int lca(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  int k = deep[x] - deep[y];
  for (int i = 0; i <= 18; i++) {
    if ((k >> i) & 1) x = pre[x][i];
  }
  if (x == y) return x;
  for (int i = 18; i >= 0; i--) {
    if (pre[x][i] != pre[y][i]) {
      x = pre[x][i];
      y = pre[y][i];
    }
  }
  return pre[x][0];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    build(a, b);
    build(b, a);
  }
  for (int i = 1; i <= n; i++) {
    if (!dfn[i]) tarjan(i, 0);
  }
  cnt = n;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cnt++;
      dfs(i);
    }
  }
  for (int x = 1; x <= n; x++) {
    for (int i = head[x]; i; i = road[i].next) {
      int y = road[i].to;
      if (belong[x] == belong[y]) continue;
      build(belong[x], belong[y]);
    }
  }
  dfs2(n + 1, 0);
  scanf("%d", &k);
  while (k--) {
    int s, l;
    scanf("%d%d", &s, &l);
    printf("%d\n", deep[belong[s]] + deep[belong[l]] -
                       2 * deep[lca(belong[s], belong[l])]);
  }
  return 0;
}
