#include <bits/stdc++.h>
using namespace std;
int n, m, k, curId, id[100005], high[100005], numComp, comp[100005];
vector<int> e[100005], ce[100005];
stack<int> path;
bool vis[100005];
int level[100005], parent[100005][32];
void dfs(int pu, int u) {
  id[u] = curId++;
  high[u] = id[u];
  vis[u] = true;
  int v;
  path.push(u);
  for (int i = 0; i < e[u].size(); i++) {
    v = e[u][i];
    if (v == pu) continue;
    if (!vis[v]) {
      dfs(u, v);
      high[u] = min(high[u], high[v]);
    } else {
      high[u] = min(high[u], id[v]);
    }
  }
  if (high[u] == id[u]) {
    do {
      v = path.top();
      path.pop();
      comp[v] = numComp;
    } while (v != u);
    numComp++;
  }
}
void dfs2(int u) {
  vis[u] = true;
  int v;
  for (int i = 1; i < 30; i++) {
    v = parent[u][i - 1];
    if (v != -1) {
      v = parent[v][i - 1];
      if (v != -1) parent[u][i] = v;
    }
  }
  for (int i = 0; i < ce[u].size(); i++) {
    v = ce[u][i];
    if (!vis[v]) {
      level[v] = level[u] + 1;
      parent[v][0] = u;
      dfs2(v);
    }
  }
}
int find(int u, int dis) {
  for (int i = 30; i >= 0; i--) {
    if (dis & (1 << i)) {
      u = parent[u][i];
      dis ^= (1 << i);
    }
  }
  return u;
}
int lca(int u, int v) {
  if (level[u] < level[v]) swap(u, v);
  u = find(u, level[u] - level[v]);
  if (u == v) return u;
  for (int i = 30; i >= 0; i--) {
    if (parent[u][i] != -1 && parent[v][i] != -1) {
      if (parent[u][i] != parent[v][i]) {
        u = parent[u][i];
        v = parent[v][i];
      }
    }
  }
  return parent[u][0];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  curId = numComp = 0;
  memset(vis, false, sizeof(vis));
  dfs(-1, 0);
  for (int u = 0; u < n; u++) {
    for (int i = 0; i < e[u].size(); i++) {
      v = e[u][i];
      if (comp[u] != comp[v]) ce[comp[u]].push_back(comp[v]);
    }
  }
  memset(vis, false, sizeof(vis));
  for (int u = 0; u < numComp; u++)
    for (int i = 0; i < 30; i++) parent[u][i] = -1;
  level[0] = 0;
  dfs2(0);
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> u >> v;
    u--;
    v--;
    u = comp[u];
    v = comp[v];
    int w = lca(u, v);
    cout << (level[u] - level[w] + level[v] - level[w]) << endl;
  }
  return 0;
}
