#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, maxlg = 18, inf = 1e9 + 10;
vector<int> adj[maxn];
bool mark[maxn], mark2[maxn];
int dp[maxn], h[maxn];
int par[maxlg][maxn], cost[maxlg][maxn];
void dfs1(int v) {
  mark[v] = true;
  dp[v] = inf;
  for (int u : adj[v]) {
    if (!mark[u]) {
      par[0][u] = v;
      h[u] = h[v] + 1;
      dfs1(u);
      if (dp[u] >= h[u]) {
        cost[0][u] = 1;
      }
      dp[v] = min(dp[u], dp[v]);
    } else if (u != par[0][v])
      dp[v] = min(h[u], dp[v]);
  }
}
void dfs2(int v) {
  mark2[v] = true;
  for (int i = 1; i < maxlg; i++) {
    par[i][v] = par[i - 1][par[i - 1][v]];
    cost[i][v] = cost[i - 1][v] + cost[i - 1][par[i - 1][v]];
  }
  for (int u : adj[v])
    if (!mark2[u]) dfs2(u);
}
int lca(int u, int v) {
  int r = 0;
  if (h[u] > h[v]) swap(u, v);
  for (int d = h[v] - h[u]; d; d -= d & -d) {
    int c = __builtin_ctz(d);
    r += cost[c][v];
    v = par[c][v];
  }
  if (u == v) return r;
  for (int i = maxlg - 1; ~i; i--)
    if (par[i][u] != par[i][v]) {
      r += cost[i][u];
      u = par[i][u];
      r += cost[i][v];
      v = par[i][v];
    }
  r += cost[0][u];
  r += cost[0][v];
  return r;
}
int main() {
  int n, m, k;
  cin >> n >> m;
  for (int i = 0, u, v; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    adj[v].push_back(u);
    adj[u].push_back(v);
  }
  dfs1(0);
  dfs2(0);
  cin >> k;
  for (int i = 0, u, v; i < k; i++) {
    cin >> u >> v;
    u--;
    v--;
    cout << lca(u, v) << '\n';
  }
  return 0;
}
