#include <bits/stdc++.h>
using namespace std;
vector<int> G1[100100], G0[100100];
int lvl[100100], par[100100][21], SCCno, dfs_num[100100], dfs_low[100100],
    compo[100100], dfsCnt;
bitset<100100> vis;
set<pair<int, int> > taken;
vector<int> SCC;
void tarjanSCC(int u, int p = -1) {
  SCC.push_back(u);
  vis[u] = 1;
  dfs_num[u] = dfs_low[u] = ++dfsCnt;
  for (auto v : G0[u]) {
    if (v == p) continue;
    if (dfs_num[v] == 0) {
      tarjanSCC(v, u);
    }
    if (vis[v]) dfs_low[u] = min(dfs_low[u], dfs_low[v]);
  }
  if (dfs_num[u] == dfs_low[u]) {
    SCCno++;
    while (not SCC.empty()) {
      int v = SCC.back();
      SCC.pop_back();
      vis[v] = 0;
      compo[v] = SCCno;
      if (u == v) break;
    }
  }
}
void buildTree(int V) {
  for (int u = 1; u <= V; ++u) {
    int uu = compo[u];
    for (auto v : G0[u]) {
      int vv = compo[v];
      if (uu != vv and taken.count({uu, vv}) == 0) {
        taken.insert({uu, vv}), taken.insert({vv, uu});
        G1[uu].push_back(vv);
        G1[vv].push_back(uu);
      }
    }
  }
}
void dfs(int u, int p = -1, int l = 1) {
  par[u][0] = p;
  lvl[u] = l;
  for (auto v : G1[u])
    if (v != p) dfs(v, u, l + 1);
}
void LCAinit(int V) {
  memset(par, -1, sizeof par);
  dfs(1);
  for (int p = 1; (1 << p) <= V; ++p)
    for (int u = 1; u <= V; ++u)
      if (par[u][p - 1] != -1) par[u][p] = par[par[u][p - 1]][p - 1];
}
int LCA(int u, int v) {
  if (lvl[u] < lvl[v]) swap(u, v);
  for (int p = 20; p >= 0; --p)
    if (lvl[u] - (1 << p) >= lvl[v]) u = par[u][p];
  if (u == v) return u;
  for (int p = 20; p >= 0; --p)
    if (par[u][p] != -1 and par[u][p] != par[v][p])
      u = par[u][p], v = par[v][p];
  return par[u][0];
}
int solve(int u, int v) {
  u = compo[u], v = compo[v];
  if (u == v) return 0;
  return lvl[u] + lvl[v] - 2 * lvl[LCA(u, v)];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, u, v, w, q;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    G0[u].push_back(v);
    G0[v].push_back(u);
  }
  tarjanSCC(1);
  buildTree(n);
  LCAinit(n);
  cin >> q;
  while (q--) {
    cin >> u >> v;
    cout << solve(u, v) << "\n";
  }
  return 0;
}
