#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 1e9;
const int mod = 1e9 + 7;
int dsu[maxn];
bool mark[maxn];
int h[maxn];
int dp[maxn];
vector<int> edge[maxn];
vector<int> e[maxn];
int get(int a) {
  if (dsu[a] < 0) return a;
  return dsu[a] = get(dsu[a]);
}
void merg(int a, int b) {
  int p1 = get(a), p2 = get(b);
  if (dsu[p1] > dsu[p2]) swap(p1, p2);
  dsu[p1] += dsu[p2];
  dsu[p2] = p1;
}
void dfs(int v) {
  mark[v] = true;
  dp[v] = inf;
  for (int u : edge[v]) {
    if (mark[u]) {
      if (h[u] < h[v] - 1) dp[v] = min(dp[v], h[u]);
      continue;
    }
    h[u] = h[v] + 1;
    dfs(u);
    dp[v] = min(dp[v], dp[u]);
    if (dp[u] <= h[v]) merg(u, v);
  }
}
int par[maxn][20];
void lca_pre(int v) {
  mark[v] = true;
  for (int i = 1; i < 20; i++) par[v][i] = par[par[v][i - 1]][i - 1];
  for (int u : e[v]) {
    if (!mark[u]) {
      h[u] = h[v] + 1;
      par[u][0] = v;
      lca_pre(u);
    }
  }
}
int lca(int v, int u) {
  if (h[v] > h[u]) swap(v, u);
  int dh = h[u] - h[v];
  for (int i = 0; i < 20; i++)
    if (dh & (1 << i)) u = par[u][i];
  if (u == v) return v;
  for (int i = 19; i >= 0; i--)
    if (par[v][i] != par[u][i]) {
      v = par[v][i];
      u = par[u][i];
    }
  return par[v][0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) dsu[i] = -1;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    edge[v].push_back(u);
    edge[u].push_back(v);
  }
  dfs(0);
  for (int v = 0; v < n; v++)
    for (int u : edge[v]) {
      int p1 = get(v), p2 = get(u);
      if (p1 != p2) e[p1].push_back(p2);
    }
  memset(mark, 0, sizeof(mark));
  memset(h, 0, sizeof(h));
  par[get(0)][0] = get(0);
  lca_pre(get(0));
  int q;
  cin >> q;
  while (q--) {
    int v, u;
    cin >> v >> u;
    v--;
    u--;
    int p = lca(get(v), get(u));
    cout << h[get(v)] + h[get(u)] - 2 * h[p] << '\n';
  }
}
