#include <bits/stdc++.h>
const long double pi = 3.1415926535898;
const long long mod = 1e9 + 7;
using namespace std;
long long n, m;
vector<vector<long long>> v(100005);
long long in[100005], low[100005], vis[100005], art[100005];
long long tim = 0;
long long father[100005];
void dfs(long long x, long long par) {
  father[x] = par;
  vis[x] = 1;
  in[x] = low[x] = tim++;
  for (auto i : v[x]) {
    if (i == par) {
      continue;
    }
    if (vis[i]) {
      low[x] = min(low[i], low[x]);
    } else {
      dfs(i, x);
      low[x] = min(low[i], low[x]);
    }
  }
  if (low[x] >= in[x]) {
    art[x] = 1;
  }
}
long long p[100005][25];
long long d[100005], dep[100005];
long long tin[100005], tout[100005];
void form(long long x, long long par, long long h, long long hh) {
  dep[x] = hh;
  d[x] = h;
  p[x][0] = par;
  tin[x] = tim++;
  for (long long i = 1; i <= 20; i++) {
    long long xx = p[x][i - 1];
    p[x][i] = p[xx][i - 1];
  }
  for (auto i : v[x]) {
    if (father[i] == x) {
      form(i, x, h + art[i], hh + 1);
    }
  }
  tout[x] = tim++;
}
bool is_ancestor(long long u, long long v) {
  return tin[u] <= tin[v] && tout[u] >= tout[v];
}
long long lca(long long u, long long v) {
  if (is_ancestor(u, v)) return u;
  if (is_ancestor(v, u)) return v;
  for (long long i = 20; i >= 0; --i) {
    if (!is_ancestor(p[u][i], v)) u = p[u][i];
  }
  return p[u][0];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  long long x, y;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  memset(in, -1, sizeof(in));
  memset(low, -1, sizeof(low));
  dfs(1, 0);
  tim = 0;
  form(1LL, 0LL, 0LL, 0LL);
  for (long long i = 1; i <= n; i++) {
  }
  long long k;
  cin >> k;
  tin[0] = -1e18;
  tout[0] = 1e18;
  while (k--) {
    cin >> x >> y;
    long long lcaa = lca(x, y);
    cout << d[x] + d[y] - 2 * d[lcaa] << "\n";
  }
  return 0;
}
