#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int timer = 0, number = 0;
int convert[N + 5];
vector<int> G[N + 5], newG[N + 5];
int P[N + 5][22], pr[N + 5];
bool vis[N + 5];
int low[N + 5], disc[N + 5], L[N + 5];
vector<pair<int, int> > normal, bridge;
inline int find(int r) { return (pr[r] == r ? r : pr[r] = find(pr[r])); }
void dfs(int node) {
  vis[node] = 1;
  disc[node] = low[node] = ++timer;
  for (int i : G[node]) {
    if (vis[i] == 0) {
      pr[i] = node;
      dfs(i);
      low[node] = min(low[node], low[i]);
      if (disc[node] < low[i]) {
        bridge.push_back(make_pair(node, i));
      } else {
        normal.push_back(make_pair(node, i));
      }
    } else if (pr[node] != i) {
      low[node] = min(low[node], disc[i]);
    }
  }
}
void dfs(int node, int pre, int dep) {
  P[node][0] = pre;
  L[node] = dep;
  for (int i : newG[node]) {
    if (i == pre) continue;
    dfs(i, node, dep + 1);
  }
}
void init() {
  for (int i = 0; i <= N; i++)
    for (int j = 1; j < 22; j++) P[i][j] = 1;
  for (int j = 1; (1 << j) <= N; j++) {
    for (int i = 0; i <= N; i++) {
      P[i][j] = P[P[i][j - 1]][j - 1];
    }
  }
}
int query(int p, int q) {
  if (L[p] < L[q]) swap(p, q);
  for (int i = 21; i >= 0; i--) {
    if (L[P[p][i]] >= L[q]) p = P[p][i];
  }
  if (p == q) return p;
  for (int i = 21; i >= 0; i--) {
    if (P[p][i] != P[q][i]) {
      p = P[p][i];
      q = P[q][i];
    }
  }
  return P[p][0];
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(1);
  for (int i = 1; i <= n; i++) pr[i] = i;
  for (int i = 0; i < normal.size(); i++) {
    int u = find(normal[i].first);
    int v = find(normal[i].second);
    if (u != v) {
      pr[u] = v;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (find(i) == i) {
      convert[i] = ++number;
    }
  }
  for (int i = 0; i < bridge.size(); i++) {
    int u = find(bridge[i].first);
    int v = find(bridge[i].second);
    u = convert[u];
    v = convert[v];
    newG[u].push_back(v);
    newG[v].push_back(u);
  }
  dfs(1, 1, 0);
  init();
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b;
    scanf("%d %d", &a, &b);
    a = convert[find(a)];
    b = convert[find(b)];
    int p = query(a, b);
    printf("%d\n", L[a] + L[b] - 2 * L[p]);
  }
}
