#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5, LG = 20;
pair<int, int> par[MAXN][LG];
vector<int> adj[MAXN];
int h[MAXN], r[MAXN];
bool mark[MAXN];
vector<int> vc;
int n, m, k;
void input();
void dfs(int);
pair<int, int> k_par(int, int);
int lca(int, int);
void solve();
void output();
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  input();
  solve();
  output();
  return 0;
}
void input() {
  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);
  }
}
void dfs(int u) {
  mark[u] = true;
  vc.push_back(u);
  for (auto v : adj[u])
    if (v != par[u][0].first) {
      if (!mark[v]) {
        h[v] = h[u] + 1;
        par[v][0].first = u;
        dfs(v);
        r[u] = min(r[u], r[v]);
      } else
        r[u] = min(r[u], h[v]);
    }
  par[u][0].second = (r[u] < h[u]) ? 0 : 1;
}
pair<int, int> k_par(int u, int k) {
  int cnt = 0;
  for (int i = 0; i < LG; i++)
    if (k >> i & 1) {
      cnt += par[u][i].second;
      u = par[u][i].first;
    }
  return make_pair(u, cnt);
}
int lca(int u, int v) {
  int res = 0;
  if (h[u] < h[v]) swap(u, v);
  pair<int, int> x = k_par(u, h[u] - h[v]);
  u = x.first;
  res += x.second;
  if (u == v) return res;
  for (int i = LG - 1; i >= 0; i--)
    if (par[u][i].first != par[v][i].first) {
      res += par[u][i].second + par[v][i].second;
      u = par[u][i].first;
      v = par[v][i].first;
    }
  return res + par[u][0].second + par[v][0].second;
}
void solve() {
  memset(r, 63, sizeof r);
  dfs(0);
  for (auto i : vc)
    for (int j = 1; j < LG; j++) {
      par[i][j].first = par[par[i][j - 1].first][j - 1].first;
      par[i][j].second =
          par[i][j - 1].second + par[par[i][j - 1].first][j - 1].second;
    }
}
void output() {
  cin >> k;
  while (k--) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    cout << lca(u, v) << "\n";
  }
}
