#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
int t, n, m, low[N], num[N], cau[N], id = 0, depth[N], cha[19][N], LOG = 17;
int comp[N], cntLT = 0;
vector<pair<int, int> > g[N];
vector<int> G[N];
struct EDG {
  int u, v, id;
};
void dfs(int u, int p) {
  low[u] = num[u] = ++id;
  for (auto E : g[u]) {
    int v = E.first, e = E.second;
    if (v != p) {
      if (num[v])
        low[u] = min(low[u], num[v]);
      else {
        dfs(v, u);
        low[u] = min(low[u], low[v]);
        cau[e] |= (low[v] >= num[v]);
      }
    }
  }
}
void vungLT(int u) {
  comp[u] = cntLT;
  for (auto E : g[u])
    if (comp[E.first] == 0 && cau[E.second] == 0) vungLT(E.first);
}
void DFS(int u, int len) {
  depth[u] = len;
  for (auto v : G[u])
    if (depth[v] == 0) {
      cha[0][v] = u;
      DFS(v, len + 1);
    }
}
int lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  while (depth[u] > depth[v]) u = cha[(int)log2(depth[u] - depth[v])][u];
  int k = LOG;
  while (u != v) {
    if (cha[k][u] != cha[k][v] || k == 0) u = cha[k][u], v = cha[k][v];
    k -= (k > 0);
  }
  return u;
}
int dist(int u, int v) {
  int r = lca(u, v);
  return depth[u] + depth[v] - 2 * depth[r];
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  vector<EDG> edg;
  for (int i = 1, u, v; i <= m; i++) {
    cin >> u >> v;
    g[u].emplace_back(pair<int, int>(v, i));
    g[v].emplace_back(pair<int, int>(u, i));
    edg.emplace_back((EDG){u, v, i});
  }
  fill(num, num + N, 0);
  fill(cau, cau + N, 0);
  for (int u = 1; u <= n; u++)
    if (num[u] == 0) dfs(u, u);
  fill(comp, comp + N, 0);
  for (int i = 1; i <= n; i++)
    if (comp[i] == 0) {
      cntLT++;
      vungLT(i);
    }
  for (auto E : edg) {
    int u = E.u, v = E.v, e = E.id;
    if (cau[e] == 1 && comp[u] != comp[v]) {
      G[comp[u]].emplace_back(comp[v]);
      G[comp[v]].emplace_back(comp[u]);
    }
  }
  fill(depth, depth + N, 0);
  DFS(1, 1);
  cha[0][1] = 1;
  for (int k = 1; k <= LOG; k++)
    for (int i = 1; i <= cntLT; i++) cha[k][i] = cha[k - 1][cha[k - 1][i]];
  cin >> t;
  for (int i = 1, u, v; i <= t; i++) {
    cin >> u >> v;
    cout << dist(comp[u], comp[v]) << "\n";
  }
  return 0;
}
