#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int maxm = 100005;
typedef int arr[maxn];
arr head, dfn, low, col, st;
int top, depth, color, tot, cnt;
pair<int, int> e[maxm * 2], bridge[maxn];
int euler[maxn * 2], d[maxn * 2][30], pos;
void add(int x, int y) {
  e[tot] = make_pair(head[x], y);
  head[x] = tot++;
}
void tarjan(int u, int f) {
  dfn[u] = low[u] = ++depth;
  st[++top] = u;
  for (int i = head[u]; i != -1; i = e[i].first) {
    int v = e[i].second;
    if (v == f) continue;
    if (!dfn[v]) {
      tarjan(v, u);
      low[u] = min(low[v], low[u]);
    } else
      low[u] = min(low[u], dfn[v]);
    if (low[v] > dfn[u]) bridge[cnt++] = make_pair(u, v);
  }
  if (dfn[u] == low[u]) {
    int x;
    color++;
    do {
      col[x = st[top--]] = color;
    } while (x != u);
  }
}
void dfs(int u, int f) {
  euler[++pos] = u;
  low[u] = pos;
  for (int i = head[u]; i != -1; i = e[i].first) {
    int v = e[i].second;
    if (v == f) continue;
    dfn[v] = dfn[u] + 1;
    dfs(v, u);
    euler[++pos] = u;
  }
}
void RMQ_init() {
  for (int i = 1; i <= pos; i++) d[i][0] = i;
  for (int j = 1; (1 << j) <= pos; j++) {
    for (int i = 1; i + j - 1 <= pos; i++) {
      if (dfn[euler[d[i][j - 1]]] < dfn[euler[d[i + (1 << (j - 1))][j - 1]]]) {
        d[i][j] = d[i][j - 1];
      } else
        d[i][j] = d[i + (1 << (j - 1))][j - 1];
    }
  }
}
int RMQ(int L, int R) {
  int k = 0;
  if (L > R) swap(L, R);
  while ((1 << (k + 1)) <= R - L + 1) k++;
  return dfn[euler[d[L][k]]] < dfn[euler[d[R - (1 << k) + 1][k]]]
             ? d[L][k]
             : d[R - (1 << k) + 1][k];
}
int main() {
  for (int n, m; scanf("%d%d", &n, &m) != EOF;) {
    depth = color = tot = top = cnt = 0;
    for (int i = 1; i <= n; i++) {
      head[i] = -1, dfn[i] = 0;
    }
    for (int i = 1, x, y; i <= m; i++) {
      scanf("%d%d", &x, &y);
      add(x, y);
      add(y, x);
    }
    tarjan(1, -1);
    tot = 0;
    for (int i = 0; i <= color; i++) {
      head[i] = -1;
      dfn[i] = 0;
    }
    for (int i = 0; i < cnt; i++) {
      add(col[bridge[i].first], col[bridge[i].second]);
      add(col[bridge[i].second], col[bridge[i].first]);
    }
    pos = 0;
    dfn[1] = 0;
    dfs(1, 0);
    RMQ_init();
    int Q;
    scanf("%d", &Q);
    for (int i = 1, x, y; i <= Q; i++) {
      scanf("%d%d", &x, &y);
      int ance = RMQ(low[col[x]], low[col[y]]);
      ance = euler[ance];
      printf("%d\n", dfn[col[x]] + dfn[col[y]] - 2 * dfn[ance]);
    }
  }
  return 0;
}
