#include <bits/stdc++.h>
using namespace std;
const long long mx = 1000 * 100 + 5;
vector<pair<long long, long long> > ad[mx];
vector<long long> adj[mx];
long long dp[mx], h[mx], cnt, cm[mx], l = 18, par[20][mx], n;
bool mark[mx], isc[mx], vis[mx];
map<long long, pair<long long, long long> > e;
void cutedge(long long v, long long ind) {
  dp[v] = h[v];
  mark[v] = true;
  for (long long i = 0; i < (long long)ad[v].size(); i++) {
    long long u = ad[v][i].first, j = ad[v][i].second;
    if (!mark[u]) {
      h[u] = h[v] + 1;
      cutedge(u, j);
      if (dp[u] > h[v])
        isc[j] = 1;
      else
        dp[v] = min(dp[v], dp[u]);
    } else if (j != ind)
      dp[v] = min(dp[v], h[u]);
  }
  return;
}
void dfslca(long long v, long long pr) {
  for (long long i = 1; i <= l; i++) par[i][v] = par[i - 1][par[i - 1][v]];
  for (auto u : adj[v]) {
    if (u != pr) {
      h[u] = h[v] + 1;
      par[0][u] = v;
      dfslca(u, v);
    }
  }
  return;
}
long long findpar(long long v, long long x) {
  for (long long i = l; i >= 0; i--)
    if (x & (1 << i)) v = par[i][v];
  return v;
}
long long lca(long long u, long long v) {
  if (h[u] > h[v]) swap(u, v);
  v = findpar(v, h[v] - h[u]);
  if (v == u) return u;
  for (long long i = l; i >= 0; i--)
    if (par[i][u] != par[i][v]) {
      u = par[i][u];
      v = par[i][v];
    }
  return par[0][u];
}
void dfs(long long v) {
  vis[v] = 1;
  cm[v] = cnt;
  for (auto u : ad[v]) {
    if (!vis[u.first] && !isc[u.second]) dfs(u.first);
  }
  return;
}
void dfs_all() {
  for (long long i = 0; i < n; i++)
    if (!vis[i]) {
      dfs(i);
      cnt++;
    }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long m, k, u, v;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> u >> v;
    u--, v--;
    ad[u].push_back({v, i});
    ad[v].push_back({u, i});
    e[i] = {u, v};
  }
  cutedge(0, -1);
  dfs_all();
  for (long long i = 0; i < m; i++)
    if (isc[i]) {
      adj[cm[e[i].first]].push_back(cm[e[i].second]);
      adj[cm[e[i].second]].push_back(cm[e[i].first]);
    }
  dfslca(0, 0);
  cin >> k;
  for (long long i = 0; i < k; i++) {
    cin >> u >> v;
    u--, v--;
    cout << h[cm[u]] + h[cm[v]] - 2 * h[lca(cm[u], cm[v])] << endl;
  }
  return 0;
}
