#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, LOG = 20;
int n, m, u, v, k, parent, h[N], comp[N], minimum[N], upper[N][LOG];
bool mark[N], shear[N];
vector<pair<int, int> > nei[N];
vector<int> tree_nei[N];
void find_shear(int v, int par) {
  mark[v] = true;
  minimum[v] = h[v];
  for (pair<int, int> p : nei[v]) {
    int u = p.first;
    if (u == par) continue;
    if (!mark[u]) {
      h[u] = h[v] + 1;
      find_shear(u, v);
    }
    if (minimum[u] > h[v]) shear[p.second] = true;
    minimum[v] = min(minimum[v], minimum[u]);
  }
}
void dfs(int v) {
  mark[v] = true;
  comp[v] = parent;
  for (pair<int, int> p : nei[v]) {
    if (!mark[p.first] && !shear[p.second]) dfs(p.first);
    if (shear[p.second]) tree_nei[parent].push_back(p.first);
  }
}
void tree_dfs(int v, int par) {
  for (int i = 1; i < LOG; i++) upper[v][i] = upper[upper[v][i - 1]][i - 1];
  for (int u : tree_nei[v]) {
    u = comp[u];
    if (u != par) {
      h[u] = h[v] + 1;
      upper[u][0] = v;
      tree_dfs(u, v);
    }
  }
}
int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  for (int i = LOG - 1; i >= 0; i--)
    if (h[u] - (1LL << i) >= h[v]) u = upper[u][i];
  if (u == v) return u;
  for (int i = LOG - 1; i >= 0; i--)
    if (upper[u][i] != upper[v][i]) {
      v = upper[v][i];
      u = upper[u][i];
    }
  return upper[u][0];
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    nei[--u].push_back(pair<int, int>(--v, i));
    nei[v].push_back(pair<int, int>(u, i));
  }
  find_shear(0, 0);
  memset(mark, false, sizeof mark);
  for (int i = 0; i < n; i++)
    if (!mark[i]) {
      dfs(i);
      parent++;
    }
  tree_dfs(0, 0);
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> u >> v;
    cout << h[comp[--u]] + h[comp[--v]] - 2 * h[lca(comp[u], comp[v])] << '\n';
  }
  return 0;
}
