#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000009;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 100001;
const int MAXM = 0;
int n, m, v, u, i, j, k;
vector<int> G[MAXN];
vector<int> G2[MAXN];
int in[MAXN], ll[MAXN];
bool fix[MAXN];
int c[MAXN];
int D[MAXN];
set<int> X[MAXN];
int t = 1;
int l;
vector<vector<int> > g;
vector<int> tin, tout;
int timer;
vector<vector<int> > up;
void dfs(int v, int p = -1) {
  in[v] = ll[v] = t++;
  int u;
  for (int i = 0; i < G[v].size(); i++) {
    u = G[v][i];
    if (u == p) continue;
    if (in[u])
      ll[v] = min(ll[v], in[u]);
    else {
      dfs(u, v);
      ll[v] = min(ll[v], ll[u]);
      if (ll[u] > in[v]) {
        X[v].insert(u);
        X[u].insert(v);
      }
    }
  }
}
void dfs2(int v, int t) {
  c[v] = t;
  fix[v] = true;
  for (int i = 0; i < G2[v].size(); i++)
    if (!fix[G2[v][i]]) dfs2(G2[v][i], t);
}
void dfsLCA(int v, int d, int p = 0) {
  tin[v] = ++timer;
  up[v][0] = p;
  D[v] = d;
  for (int i = 1; i <= l; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (size_t i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to != p) dfsLCA(to, d + 1, v);
  }
  tout[v] = ++timer;
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = l; i >= 0; --i)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
int dist(int v, int u) { return D[v] + D[u] - 2 * D[lca(v, u)]; }
int main() {
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    scanf("%d%d", &v, &u);
    u--;
    v--;
    G[v].push_back(u);
    G[u].push_back(v);
  }
  dfs(0);
  for (i = 0; i < n; i++)
    for (j = 0; j < G[i].size(); j++) {
      v = i;
      u = G[v][j];
      if (X[v].find(u) == X[v].end()) {
        G2[v].push_back(u);
      }
    }
  t = 0;
  for (i = 0; i < n; i++)
    if (!fix[i]) dfs2(i, t++);
  set<int>::iterator it;
  tin.resize(n), tout.resize(n), up.resize(n);
  g.resize(t);
  for (i = 0; i < n; i++)
    for (it = X[i].begin(); it != X[i].end(); it++) {
      v = c[i];
      u = c[*it];
      g[v].push_back(u);
      g[u].push_back(v);
    }
  n = t;
  l = 1;
  while ((1 << l) <= n) ++l;
  for (int i = 0; i < n; ++i) up[i].resize(l + 1);
  dfsLCA(0, 0);
  int T;
  cin >> T;
  while (T--) {
    scanf("%d%d", &v, &u);
    v--;
    u--;
    if (c[v] == c[u]) {
      cout << 0 << endl;
      continue;
    }
    printf("%d\n", dist(c[v], c[u]));
  }
  return 0;
}
