#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5, lg = 19;
int n, m, par[lg][MAXN], h[MAXN], mnh[MAXN], cnt[lg][MAXN], q;
vector<int> adj[MAXN];
bool visit[MAXN], cut[MAXN];
void dfs(int v) {
  visit[v] = true;
  for (int i = 0; i < (int)adj[v].size(); i++) {
    int u = adj[v][i];
    if (!visit[u]) {
      h[u] = h[v] + 1;
      par[0][u] = v;
      dfs(u);
      mnh[v] = min(mnh[v], mnh[u]);
      if (mnh[u] > h[v]) {
        cut[u] = true;
        cnt[0][u]++;
      }
    } else if (u != par[0][v])
      mnh[v] = min(mnh[v], h[u]);
  }
  return;
}
void strt() {
  for (int i = 0; i < n; i++) mnh[i] = INT_MAX;
  dfs(0);
  for (int k = 1; k < lg; k++)
    for (int i = 0; i < n; i++) {
      par[k][i] = par[k - 1][par[k - 1][i]];
      cnt[k][i] = cnt[k - 1][i] + cnt[k - 1][par[k - 1][i]];
    }
  return;
}
pair<int, int> findpar(int x, int v) {
  int cntt = 0;
  for (int i = 0; i < lg; i++)
    if ((x >> i) & 1) {
      cntt += cnt[i][v];
      v = par[i][v];
    }
  return {v, cntt};
}
void findlca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  pair<int, int> p = findpar(h[u] - h[v], u);
  u = p.first;
  int ans = p.second;
  if (u == v) {
    cout << ans << endl;
    return;
  }
  for (int i = lg - 1; i >= 0; i--) {
    if (par[i][u] != par[i][v]) {
      ans += cnt[i][u];
      ans += cnt[i][v];
      u = par[i][u], v = par[i][v];
    }
  }
  ans += cnt[0][u], ans += cnt[0][v];
  cout << ans << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  strt();
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    findlca(u, v);
  }
  return 0;
}
