#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
const double pi = 3.14159265358979323;
const double eps = 1e-8;
int n, m, root;
int eh[200010], tot, belong[200010], bcc, dfn[200010], low[200010], Dindex;
int s[200010], top;
int visit[200010];
struct Edge {
  int v, next;
} et[200010];
void init() {
  tot = 0;
  memset(eh, -1, sizeof(eh));
}
void addedge(int u, int v) {
  Edge e = {v, eh[u]};
  et[tot] = e;
  eh[u] = tot++;
}
void dfs(int u, int pre) {
  dfn[u] = low[u] = ++Dindex, visit[u] = 1;
  s[++top] = u;
  int tot = 0;
  for (int i = eh[u]; i != -1; i = et[i].next) {
    int v = et[i].v;
    if (visit[v] == 1 && v != pre) low[u] = min(low[u], dfn[v]);
    if (visit[v] == 0) {
      dfs(v, u);
      tot++, low[u] = min(low[u], low[v]);
      if (low[v] > dfn[u]) {
        bcc++;
        while (1) {
          belong[s[top]] = bcc;
          if (s[top--] == v) break;
        }
      }
    }
  }
  visit[u] = 2;
}
void tarjan() {
  top = bcc = Dindex = 0;
  bcc++;
  memset(visit, 0, sizeof(visit));
  for (root = 1; root <= n; root++)
    if (!visit[root]) dfs(root, -1);
  for (int i = (1); i < (n + 1); i++)
    if (belong[i] == 0) belong[i] = 1;
}
vector<int> g[200010];
pair<int, int> e[200010];
void rebuild() {
  g[0].push_back(1);
  g[1].push_back(0);
  for (int i = (0); i < (m); i++) {
    int u = e[i].first, v = e[i].second;
    if (belong[u] != belong[v]) {
      g[belong[u]].push_back(belong[v]);
      g[belong[v]].push_back(belong[u]);
    }
  }
}
bool vis[200010];
int R[200010];
int p[200010 * 2];
int dis[200010];
int dep[2 * 200010];
int dp[20][2 * 200010];
int num;
void dfs2(int u, int depth) {
  vis[u] = 1;
  p[++num] = u;
  dep[num] = depth;
  for (int i = (0); i < (g[u].size()); i++) {
    int v = g[u][i];
    if (!vis[v]) {
      dis[v] = dis[u] + (u == 0 ? 0 : 1);
      dfs2(v, depth + 1);
      p[++num] = u;
      dep[num] = depth;
    }
  }
}
void init_rmq() {
  int i, j;
  for (i = 1; i <= num; i++) {
    if (R[p[i]] == -1) {
      R[p[i]] = i;
    }
  }
  for (i = 1; i <= num; i++) {
    dp[0][i] = i;
  }
  int t = (int)(log(num * 1.0) / log(2.0));
  for (i = 1; i <= t; i++) {
    for (j = 1; j + (1 << (i - 1)) <= num; j++) {
      int a = dp[i - 1][j], b = dp[i - 1][j + (1 << (i - 1))];
      if (dep[a] <= dep[b]) {
        dp[i][j] = a;
      } else
        dp[i][j] = b;
    }
  }
}
int rmq(int u, int v) {
  if (R[u] >= R[v]) swap(u, v);
  int s = R[u], t = R[v];
  int k = (int)(log((t - s + 1) * 1.0) / log(2.0));
  int a = dp[k][s], b = dp[k][t - (1 << k) + 1];
  if (dep[a] <= dep[b])
    return p[a];
  else
    return p[b];
}
int main() {
  init();
  int u, v;
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (m); i++) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
    addedge(v, u);
    e[i] = make_pair(u, v);
  }
  tarjan();
  rebuild();
  memset(R, -1, sizeof(R));
  memset(vis, false, sizeof(vis));
  num = 0;
  dis[0] = dep[0] = 0;
  dfs2(0, 0);
  init_rmq();
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &u, &v);
    int fat = rmq(belong[u], belong[v]);
    printf("%d\n", dis[belong[u]] + dis[belong[v]] - 2 * dis[fat]);
  }
  return 0;
}
