#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000 * 100 + 5, LOG = 20;
bool mrk[maxn];
long long cut[LOG + 5][maxn], pr[LOG + 5][maxn], h[maxn];
vector<long long> aj[maxn];
long long find_ans(long long v, long long x) {
  long long ans = 0;
  for (long long i = LOG; i >= 0; i--) {
    if ((1 << i) <= x) {
      x -= (1 << i);
      ans += cut[i][v];
      v = pr[i][v];
    }
  }
  return ans;
}
long long find_pr(long long v, long long x) {
  for (long long i = LOG; i >= 0; i--) {
    if ((1 << i) <= x) {
      x -= (1 << i);
      v = pr[i][v];
    }
  }
  return v;
}
long long lca(long long u, long long v) {
  if (h[u] > h[v]) swap(u, v);
  v = find_pr(v, h[v] - h[u]);
  if (v == u) return v;
  for (long long i = LOG; i >= 0; i--) {
    if (pr[i][v] != pr[i][u]) {
      u = pr[i][u];
      v = pr[i][v];
    }
  }
  return pr[0][v];
}
long long pre(long long v) {
  mrk[v] = true;
  long long mn = h[v];
  for (long long i = 0; i < (long long)(aj[v]).size(); i++) {
    long long u = aj[v][i];
    if (!mrk[u]) {
      h[u] = h[v] + 1;
      pr[0][u] = v;
      (mn) = min((mn), (pre(u)));
    } else if (u != pr[0][v])
      (mn) = min((mn), (h[u]));
  }
  if (mn == h[v] and v != 0) cut[0][v] = 1;
  return mn;
}
int32_t main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    aj[u].push_back(v);
    aj[v].push_back(u);
  }
  pre(0);
  for (long long i = 1; i < LOG; i++) {
    for (long long j = 0; j < n; j++) {
      long long p = pr[i - 1][j];
      pr[i][j] = pr[i - 1][p];
      cut[i][j] = cut[i - 1][j];
      if (p != j) cut[i][j] += cut[i - 1][p];
    }
  }
  long long k;
  cin >> k;
  while (k--) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    long long a = lca(u, v);
    cout << find_ans(u, h[u] - h[a]) + find_ans(v, h[v] - h[a]) << ' ';
  }
  return false;
}
