#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct node {
  int id, next;
  node() {}
  node(int a, int b) {
    id = a;
    next = b;
  }
};
struct Brige {
  int x, y;
} brige[maxn];
vector<int> v[maxn], g[maxn];
vector<node> q[maxn];
int dfn[maxn], low[maxn];
int f[maxn], belong[maxn];
bool visit[maxn];
int n, m, k, cnt, t, bge;
void init() {
  for (int i = 1; i <= n; i++) {
    v[i].clear();
    g[i].clear();
  }
}
int find(int x) {
  if (x != f[x]) f[x] = find(f[x]);
  return f[x];
}
void merge(int a, int b) {
  int x = find(a), y = find(b);
  if (x == y) return;
  f[y] = x;
}
void tarjan(int u, int father) {
  visit[u] = true;
  cnt++;
  dfn[u] = low[u] = cnt;
  for (int i = 0; i < (int)v[u].size(); i++) {
    int x = v[u][i];
    if (!visit[x]) {
      tarjan(x, u);
      low[u] = min(low[u], low[x]);
      if (low[x] > dfn[u]) {
        bge++;
        brige[bge].x = u;
        brige[bge].y = x;
      }
      if (low[x] <= dfn[u]) merge(x, u);
    } else if (x != father)
      low[u] = min(low[u], dfn[x]);
  }
}
void rebuild() {
  t = 0;
  memset(belong, -1, sizeof(belong));
  for (int i = 1; i <= n; i++) {
    int x = find(i);
    if (belong[x] == -1) {
      t++;
      belong[x] = t;
    }
    belong[i] = belong[x];
  }
  for (int i = 1; i <= bge; i++) {
    int a = brige[i].x, b = brige[i].y;
    g[belong[a]].push_back(belong[b]);
    g[belong[b]].push_back(belong[a]);
  }
}
void solve() {
  memset(visit, false, sizeof(visit));
  cnt = 0;
  bge = 0;
  for (int i = 1; i <= n; i++) f[i] = i;
  tarjan(1, 0);
  rebuild();
}
bool Solve[maxn], check[maxn];
int ans[maxn], d[maxn];
void lca(int u) {
  visit[u] = true;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int x = g[u][i];
    if (!visit[x]) {
      d[x] = d[u] + 1;
      lca(x);
      f[x] = u;
    }
  }
  check[u] = true;
  for (int i = 0; i < (int)q[u].size(); i++) {
    int x = q[u][i].next;
    if (check[x] == true && Solve[q[u][i].id] == false) {
      int ansestor = find(x);
      ans[q[u][i].id] = d[u] + d[x] - 2 * d[ansestor];
      Solve[q[u][i].id] = true;
    }
  }
}
int main() {
  int a, b;
  while (scanf("%d%d", &n, &m) != EOF) {
    init();
    while (m--) {
      scanf("%d%d", &a, &b);
      v[a].push_back(b);
      v[b].push_back(a);
    }
    solve();
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
      scanf("%d%d", &a, &b);
      a = belong[a], b = belong[b];
      q[a].push_back(node(i, b));
      q[b].push_back(node(i, a));
    }
    memset(visit, false, sizeof(visit));
    memset(Solve, false, sizeof(Solve));
    memset(check, false, sizeof(check));
    for (int i = 1; i <= t; i++) f[i] = i;
    d[1] = 0;
    lca(1);
    for (int i = 1; i <= k; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
