#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int pr[100001][18];
int x[100001], y[100001];
vector<int> g[100001];
int tin[100001], tout[100001];
bool z[100001];
int fup[100001];
int tt;
set<pair<int, int> > M;
int k[100001];
int dist[100001];
int id[100001];
void dfs(int v, int p = -1) {
  z[v] = true;
  tin[v] = fup[v] = tt++;
  for (int i = 0; i <= int((g[v]).size()) - 1; ++i) {
    int to = g[v][i];
    if (to == p) continue;
    if (z[to])
      fup[v] = min(fup[v], tin[to]);
    else {
      dfs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tin[v]) {
        int x, y;
        x = min(to, v);
        y = max(to, v);
        M.insert(make_pair(x, y));
      }
    }
  }
  return;
}
int f(int x) {
  if (x == k[x]) return x;
  return k[x] = f(k[x]);
}
void dfs_lca(int v) {
  tin[v] = ++tt;
  z[v] = false;
  for (int i = 0; i <= int((g[v]).size()) - 1; ++i) {
    int vv = g[v][i];
    if (z[vv]) {
      dist[vv] = dist[v] + 1;
      pr[vv][0] = v;
      for (int j = 1; j <= 17; ++j) pr[vv][j] = pr[pr[vv][j - 1]][j - 1];
      dfs_lca(vv);
    }
  }
  tout[v] = ++tt;
  return;
}
bool ok(int x, int y) { return tin[x] <= tin[y] && tout[x] >= tout[y]; }
int lca(int x, int y) {
  if (ok(x, y)) return x;
  if (ok(y, x)) return y;
  for (int st = 17; st >= 0; --st)
    if (pr[x][st] && !ok(pr[x][st], y)) x = pr[x][st];
  return pr[x][0];
}
int Dist(int x, int y) { return dist[x] + dist[y] - 2 * dist[lca(x, y)]; }
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) g[i].clear();
  for (int i = 1; i <= m; ++i) {
    cin >> x[i] >> y[i];
    if (x[i] == y[i]) continue;
    g[x[i]].push_back(y[i]);
    g[y[i]].push_back(x[i]);
  }
  tt = 0;
  memset(z, false, sizeof(z));
  dfs(1);
  for (int i = 1; i <= n; ++i) k[i] = i;
  for (int i = 1; i <= m; ++i) {
    if (x[i] > y[i]) swap(x[i], y[i]);
    if (x[i] == y[i]) continue;
    if (M.find(make_pair(x[i], y[i])) != M.end()) continue;
    int k1 = f(x[i]), k2 = f(y[i]);
    if (k1 != k2) {
      if (rand() & 1)
        k[k1] = k2;
      else
        k[k2] = k1;
    }
  }
  int nn = 0;
  for (int i = 1; i <= n; ++i)
    if (f(i) == i) {
      id[i] = ++nn;
    }
  for (int i = 1; i <= nn; ++i) g[i].clear();
  for (int i = 1; i <= m; ++i) {
    if (x[i] == y[i]) continue;
    if (f(x[i]) == f(y[i])) continue;
    int k1 = id[f(x[i])], k2 = id[f(y[i])];
    g[k1].push_back(k2);
    g[k2].push_back(k1);
  }
  memset(z, true, sizeof(z));
  memset(pr, 0, sizeof(pr));
  dist[1] = 0;
  tt = 0;
  dfs_lca(1);
  int k;
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    int x, y;
    cin >> x >> y;
    int k1 = id[f(x)], k2 = id[f(y)];
    cout << Dist(k1, k2) << endl;
  }
  return 0;
}
