#include <bits/stdc++.h>
using namespace std;
int Int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long Long() {
  long long x;
  scanf("%lld", &x);
  return x;
}
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ' ';
  err(++it, args...);
}
const int N = (int)2e5 + 5;
const int maxN = (int)1e6 + 6;
const long long Mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const long long Inf = (long long)1e18;
int team[N], par[N][20], low[N], in[N], ID[N], dep[N], Rank[N];
int tm, cur;
vector<vector<int>> g;
vector<pair<int, int>> brg;
void Set() {
  for (int i = 0; i < N; ++i) team[i] = i, Rank[i] = 1;
}
int Find(int s) { return s == team[s] ? s : team[s] = Find(team[s]); }
void merge(int u, int v) {
  u = Find(u), v = Find(v);
  if (Rank[u] > Rank[v])
    team[v] = u, Rank[u] += Rank[v];
  else
    team[u] = v, Rank[v] += Rank[u];
}
void bridge(int s, int p = 0) {
  low[s] = in[s] = ++tm;
  int cnt = 0;
  for (int i : g[s]) {
    if (i == p) continue;
    if (in[i])
      low[s] = min(low[s], in[i]);
    else {
      bridge(i, s);
      low[s] = min(low[s], low[i]);
      if (low[i] > in[s]) {
        brg.push_back({s, i});
      } else {
        merge(s, i);
      }
    }
  }
}
void dfs(int s, int p = 0) {
  par[s][0] = p;
  dep[s] = 1 + dep[p];
  for (int i = 1; i < 17; ++i) par[s][i] = par[par[s][i - 1]][i - 1];
  for (int i : g[s]) {
    if (i - p) dfs(i, s);
  }
}
int LCA(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  int d = dep[a] - dep[b];
  for (int i = 16; i >= 0; --i) {
    if (d & (1 << i)) a = par[a][i];
  }
  if (a == b) return a;
  for (int i = 16; i >= 0; --i) {
    if (par[a][i] != par[b][i]) a = par[a][i], b = par[b][i];
  }
  return par[a][0];
}
int D(int a, int b) { return dep[a] + dep[b] - 2 * dep[LCA(a, b)]; }
int main() {
  int test = 1, tc = 0;
  while (test--) {
    int n = Int(), m = Int();
    g.resize(n + 1);
    for (int i = 1; i <= m; ++i) {
      int x = Int(), y = Int();
      g[x].push_back(y);
      g[y].push_back(x);
    }
    Set();
    bridge(1);
    vector<int> used(n + 1, 0), Par(n + 1);
    int c = 0;
    for (int i = 1; i <= n; ++i) {
      Par[i] = Find(i);
      if (used[Par[i]]) continue;
      used[Par[i]] = 1;
      ID[Par[i]] = ++c;
    }
    g.clear();
    g.resize(c + 2);
    for (auto i : brg) {
      int u = Par[i.first], v = Par[i.second];
      g[ID[u]].push_back(ID[v]);
      g[ID[v]].push_back(ID[u]);
    }
    dfs(1);
    int q = Int();
    while (q--) {
      int l = Int(), r = Int();
      if (Par[l] == Par[r])
        puts("0");
      else {
        int u = ID[Par[l]], v = ID[Par[r]];
        printf("%d\n", D(u, v));
      }
    }
  }
  return 0;
}
