#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 3, LG = 17 + 3;
int n, m, k, timer, low[N], tin[N], h[N];
vector<int> vc, adj[N];
pair<int, int> par[N][LG];
bool mark[N];
void input() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[--u].push_back(--v);
    adj[v].push_back(u);
  }
}
void dfs(int v, int p = -1) {
  vc.push_back(v);
  mark[v] = true;
  low[v] = tin[v] = timer++;
  for (auto to : adj[v]) {
    if (to == p) continue;
    if (mark[to])
      low[v] = min(low[v], tin[to]);
    else {
      dfs(to, v);
      par[to][0].first = v;
      low[v] = min(low[v], low[to]);
      par[to][0].second = (low[to] > tin[v] ? 1 : 0);
    }
  }
}
void g() {
  for (auto v : vc) {
    h[v] = h[par[v][0].first] + 1;
    for (int i = 0; i + 1 < LG; i++) {
      par[v][i + 1].first = par[par[v][i].first][i].first;
      par[v][i + 1].second = par[par[v][i].first][i].second + par[v][i].second;
    }
  }
}
void solve() {
  memset(tin, -1, sizeof tin);
  memset(low, -1, sizeof low);
  dfs(0);
  g();
}
pair<int, int> k_par(int v, int k) {
  int res = 0;
  for (int i = 0; i < LG; i++)
    if (k >> i & 1) {
      res += par[v][i].second;
      v = par[v][i].first;
    }
  return {v, res};
}
int LCA(int u, int v) {
  if (h[u] > h[v]) swap(u, v);
  pair<int, int> x = k_par(v, h[v] - h[u]);
  v = x.first;
  if (v == u) return x.second;
  for (int i = LG - 1; i >= 0; i--)
    if (par[u][i].first != par[v][i].first) {
      x.second += par[u][i].second + par[v][i].second;
      u = par[u][i].first;
      v = par[v][i].first;
    }
  return x.second + par[u][0].second + par[v][0].second;
}
void output() {
  cin >> k;
  while (k--) {
    int u, v;
    cin >> u >> v;
    cout << LCA(--u, --v) << endl;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  input(), solve(), output();
  return 0;
}
