#include <bits/stdc++.h>
using namespace std;
int N, M, Q, disc[100005], low[100005], trw, grp[100005], ata[100005][20], root,
    depth[100005];
vector<int> yol[100005], yol2[100005];
int findlow(int x) {
  if (grp[x] == x) return x;
  return grp[x] = findlow(grp[x]);
}
void f(int cur, int pr) {
  disc[cur] = low[cur] = ++trw;
  for (int i = 0; i < yol[cur].size(); i++) {
    if (yol[cur][i] == pr) continue;
    int c = yol[cur][i];
    if (disc[c]) {
      if (disc[c] < low[cur]) low[cur] = disc[c], grp[cur] = grp[c];
    } else {
      f(c, cur);
      if (low[c] < low[cur]) low[cur] = low[c], grp[cur] = grp[c];
    }
  }
}
void tree(int cur, int pr) {
  for (int i = 0; i < yol2[cur].size(); i++)
    if (yol2[cur][i] != pr) {
      depth[yol2[cur][i]] = depth[cur] + 1;
      ata[yol2[cur][i]][0] = cur;
      tree(yol2[cur][i], cur);
    }
}
int lca(int a, int b) {
  if (depth[a] < depth[b]) swap(a, b);
  for (int i = 17; i >= 0; i--)
    if (depth[a] - (1 << i) >= depth[b]) a = ata[a][i];
  if (a == b) return a;
  for (int i = 17; i >= 0; i--)
    if (ata[a][i] != ata[b][i]) a = ata[a][i], b = ata[b][i];
  return ata[a][0];
}
int main() {
  int a, b;
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    scanf("%d %d", &a, &b);
    yol[a].push_back(b);
    yol[b].push_back(a);
  }
  for (int i = 1; i <= N; i++) grp[i] = i;
  f(1, 0);
  for (int i = 1; i <= N; i++) grp[i] = findlow(i);
  for (int i = 1; i <= N; i++)
    for (int j = 0; j < yol[i].size(); j++)
      if (grp[i] != grp[yol[i][j]]) yol2[grp[i]].push_back(grp[yol[i][j]]);
  root = grp[1];
  depth[root] = 1;
  depth[0] = 0;
  tree(root, 0);
  for (int k = 1; k <= 17; k++)
    for (int i = 1; i <= N; i++) ata[i][k] = ata[ata[i][k - 1]][k - 1];
  cin >> Q;
  while (Q--) {
    scanf("%d %d", &a, &b);
    a = grp[a], b = grp[b];
    printf("%d\n", depth[a] + depth[b] - 2 * depth[lca(a, b)]);
  }
  return 0;
}
