#include <bits/stdc++.h>
using namespace std;
int color[100001], a[100001], b[100001], s, t, k, n, m, timer, tin[100001],
    tout[100001], fup[100001], d[100001], l, maxcolor, up[100001][20];
vector<int> g[100001], f[100001], g2[100001];
bool used[100001];
void dfs(int v, int p = 0) {
  used[v] = 1;
  tin[v] = fup[v] = ++timer;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to == p) continue;
    if (used[to])
      fup[v] = min(fup[v], tin[to]);
    else {
      dfs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tin[v]) {
        f[v][i] = 1;
        for (int j = 0; j < g[to].size(); ++j)
          if (g[to][j] == v) {
            f[to][j] = 1;
            break;
          }
      }
    }
  }
}
void dfs2(int v, int clr) {
  color[v] = clr;
  used[v] = 1;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (!used[to]) {
      if (f[v][i])
        ++maxcolor, dfs2(to, maxcolor);
      else
        dfs2(to, clr);
    }
  }
}
void calc(int v, int p = 0) {
  used[v] = 1;
  tin[v] = ++timer;
  up[v][0] = p;
  for (int i = 1; i <= l; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (int i = 0; i < g2[v].size(); ++i) {
    int to = g2[v][i];
    if (!used[to]) {
      d[to] = d[v] + 1;
      calc(to, v);
    }
  }
  tout[v] = ++timer;
}
bool upper(int a, int b) { return (tin[a] <= tin[b] && tout[a] >= tout[b]); }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = l; i >= 0; --i)
    if (up[a][i] > 0 && !upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
int main() {
  scanf("%d%d", &n, &m);
  l = 0;
  while ((1 << l) < n) ++l;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    g[a[i]].push_back(b[i]);
    f[a[i]].push_back(0);
    g[b[i]].push_back(a[i]);
    f[b[i]].push_back(0);
  }
  for (int i = 1; i <= n; ++i)
    if (!used[i]) dfs(i);
  maxcolor = 0;
  for (int i = 1; i <= n; ++i) used[i] = 0;
  for (int i = 1; i <= n; ++i)
    if (!color[i]) {
      ++maxcolor;
      dfs2(i, maxcolor);
    }
  for (int i = 1; i <= n; ++i) used[i] = 0;
  for (int i = 1; i <= m; ++i)
    if (color[a[i]] != color[b[i]]) {
      g2[color[a[i]]].push_back(color[b[i]]);
      g2[color[b[i]]].push_back(color[a[i]]);
    }
  timer = 0;
  calc(1);
  scanf("%d", &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d%d", &s, &t);
    printf("%d\n", d[color[s]] + d[color[t]] - 2 * d[lca(color[s], color[t])]);
  }
}
