#include <bits/stdc++.h>
using namespace std;
const int N = 100012, M = 200012, H = 20;
struct edge {
  int u, v;
  edge *next;
} e[M], *P = e, *point[N], e2[M], *R = e2, *point2[N];
inline void add_edge(int a, int b) {
  P->u = a;
  P->v = b;
  P->next = point[a];
  point[a] = P++;
}
inline void add_edge2(int a, int b) {
  R->u = a;
  R->v = b;
  R->next = point2[a];
  point2[a] = R++;
}
int n, m, tot, tim, low[N], rea[N], fa[N], Z[N], top = 0, root, f[N][H], d[N],
                                                 Q[N];
bool v[N];
void dfs(int p, int now) {
  low[now] = rea[now] = tim++;
  v[now] = true;
  Z[++top] = now;
  for (edge *j = point[now]; j; j = j->next)
    if (j->v != p) {
      if (!v[j->v]) dfs(now, j->v);
      low[now] = min(low[now], low[j->v]);
    }
  if (low[now] == rea[now]) {
    ++tot;
    while (Z[top + 1] != now) fa[Z[top]] = tot, --top;
  }
}
void bfs() {
  int h, t, x;
  f[root][0] = 0;
  d[root] = 1;
  for (Q[h = t = 1] = root; h <= t; ++h)
    for (edge *j = point2[x = Q[h]]; j; j = j->next)
      if (j->v != f[x][0]) {
        f[j->v][0] = x, d[j->v] = d[x] + 1;
        Q[++t] = j->v;
      }
}
inline int lca(int a, int b) {
  if (d[a] < d[b]) swap(a, b);
  for (int i = H - 1; i >= 0; --i)
    if (d[f[a][i]] >= d[b]) a = f[a][i];
  if (a == b) return a;
  for (int i = H - 1; i >= 0; --i)
    if (f[a][i] != f[b][i]) a = f[a][i], b = f[b][i];
  return f[a][0];
}
int main() {
  scanf("%d%d", &n, &m);
  int a, b;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a, &b);
    add_edge(a, b);
    add_edge(b, a);
  }
  for (int i = 1; i <= n; ++i)
    if (!v[i]) dfs(-1, i);
  for (int i = 1; i <= n; ++i)
    for (edge *j = point[i]; j; j = j->next)
      if (fa[j->u] != fa[j->v]) add_edge2(fa[j->u], fa[j->v]);
  root = 1;
  bfs();
  for (int j = 1; j < H; ++j)
    for (int i = 1; i <= tot; ++i) f[i][j] = f[f[i][j - 1]][j - 1];
  int k;
  scanf("%d", &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d%d", &a, &b);
    a = fa[a];
    b = fa[b];
    printf("%d\n", d[a] + d[b] - 2 * d[lca(a, b)]);
  }
}
