#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1001 * 101, MOD = 1e9 + 7;
vector<int> a[MAXN], g[MAXN];
int t[MAXN] = {}, col[MAXN] = {}, mark[MAXN] = {}, t2[MAXN] = {};
set<pair<int, int> > bads;
int pre_dfs(int u, int p, int k) {
  t2[u] = k;
  int x = k;
  for (auto v : a[u]) {
    if (v == p) continue;
    if (t2[v]) {
      x = min(x, t2[v]);
      continue;
    }
    x = min(x, pre_dfs(v, u, k + 1));
  }
  if (x == k && p) {
    bads.insert({p, u});
    bads.insert({u, p});
  }
  return x;
}
void dfs(int u, int c) {
  col[u] = c;
  for (auto v : a[u]) {
    if (col[v] || bads.count({u, v})) continue;
    dfs(v, c);
  }
}
int par[MAXN][20] = {};
void DFS(int u, int p = 0) {
  par[u][0] = p;
  for (int i = 1; i < 20; i++) par[u][i] = par[par[u][i - 1]][i - 1];
  for (auto v : g[u]) {
    if (p != v) {
      t[v] = t[u] + 1;
      DFS(v, u);
    }
  }
}
int ipar(int x, int y) {
  for (int i = 0; i < 20; i++)
    if (y & (1 << i)) x = par[x][i];
  return x;
}
int lca(int x, int y) {
  if (x == y) return 0;
  if (t[x] > t[y]) swap(x, y);
  int u = x, v = y;
  y = ipar(y, t[y] - t[x]);
  if (x == y) return t[v] - t[u];
  int ans = 0;
  for (int i = 19; i > -1; i--) {
    if (par[x][i] != par[y][i] && par[x][i] && par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  }
  return t[v] + t[u] - 2 * t[x] + 2;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int x, y;
  while (m--) {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  x = 1;
  pre_dfs(1, 0, 1);
  for (int i = 1; i <= n; i++)
    if (!col[i]) dfs(i, x++);
  for (auto u : bads) g[col[u.first]].push_back(col[u.second]);
  t[1] = 0;
  DFS(1, 0);
  int q;
  cin >> q;
  while (q--) {
    cin >> x >> y;
    cout << lca(col[x], col[y]) << '\n';
  }
}
