#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
template <class T>
inline T sqr(T a) {
  return a * a;
}
vector<vector<int> > g;
vector<vector<int> > gd;
int n, m, timer = 0;
bool used[1 << 17] = {0}, incomp[1 << 17] = {0};
int tin[1 << 17], tout[1 << 17], fup[1 << 17], p[1 << 17][20],
    d[1 << 17] = {0}, leader[1 << 17] = {0};
vector<pair<int, int> > bridges;
void dfs_bridge(int x, int p) {
  used[x] = 1;
  tin[x] = fup[x] = timer++;
  for (int i = 0; i < (int)g[x].size(); ++i) {
    int to = g[x][i];
    if (to == p) continue;
    if (used[to]) {
      fup[x] = min(tin[to], fup[x]);
      continue;
    }
    dfs_bridge(to, x);
    fup[x] = min(fup[x], fup[to]);
    if (fup[to] <= tin[x]) continue;
    bridges.push_back(make_pair(x, to));
  }
}
void dfs_comp(int x, int comp) {
  incomp[x] = 1;
  leader[x] = comp;
  for (int i = 0; i < (int)g[x].size(); ++i) {
    int to = g[x][i];
    if (fup[to] > tin[x] || incomp[to]) continue;
    dfs_comp(to, comp);
  }
}
void dfs_lca(int x, int par, int r) {
  tin[x] = timer++;
  p[x][0] = par;
  d[x] = r;
  for (int i = 1; i < 20; ++i) p[x][i] = p[p[x][i - 1]][i - 1];
  for (int i = 0; i < (int)gd[x].size(); ++i) {
    int to = gd[x][i];
    if (to == par) continue;
    dfs_lca(to, x, r + 1);
  }
  tout[x] = timer++;
}
bool isAnc(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tin[v]; }
int LCA(int u, int v) {
  if (isAnc(u, v)) return u;
  if (isAnc(v, u)) return v;
  for (int i = 1; i < 20; ++i)
    if (isAnc(p[u][i], v)) return LCA(p[u][i - 1], v);
  return p[u][0];
}
int main() {
  scanf("%d%d", &n, &m);
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs_bridge(0, -1);
  int comp = 0;
  gd.resize(n);
  timer = 0;
  for (int i = (int)bridges.size() - 1; i >= 0; --i) {
    int u = bridges[i].first, v = bridges[i].second;
    if (!incomp[u]) dfs_comp(u, comp++);
    if (!incomp[v]) dfs_comp(v, comp++);
    gd[leader[u]].push_back(leader[v]);
    gd[leader[v]].push_back(leader[u]);
  }
  dfs_lca(0, 0, 0);
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    printf("%d\n",
           d[leader[u]] + d[leader[v]] - 2 * d[LCA(leader[u], leader[v])]);
  }
  return 0;
}
