#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mo = 1000000007;
inline int IN() {
  char ch;
  (ch = getchar());
  int f = 0, x = 0;
  for (; ((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    ;
  if (ch == '-') f = 1, (ch = getchar());
  for (; !((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    x = x * 10 + ch - '0';
  return (f) ? (-x) : (x);
}
int Pow(int x, int y, int p) {
  int A = 1;
  for (; y; y >>= 1, x = (long long)x * x % p)
    if (y & 1) A = (long long)A * x % p;
  return A;
}
vector<int> e[N];
vector<int> w[N];
int n, m, fa[N], dfn[N], dep[N], low[N], tim, dis[N];
int Fa[20][N];
void tarjan(int x) {
  dfn[x] = low[x] = ++tim;
  for (__typeof(*e[x].begin()) v : e[x]) {
    if (v == fa[x]) continue;
    if (dfn[v])
      low[x] = min(low[x], dfn[v]);
    else
      fa[v] = x, tarjan(v), low[x] = min(low[x], low[v]);
  }
  int i = -1;
  for (__typeof(*e[x].begin()) v : e[x]) {
    ++i;
    if (v == fa[x]) continue;
    if (low[v] > dfn[x]) w[x][i] = 1;
  }
}
void redfs(int x) {
  int z = -1;
  for (__typeof(*e[x].begin()) v : e[x]) {
    ++z;
    if (v == fa[x]) continue;
    if (fa[v] != x) continue;
    dep[v] = dep[x] + w[x][z];
    dis[v] = dis[x] + 1;
    Fa[0][v] = x;
    for (int i = (int)1; i <= (int)18; i++) Fa[i][v] = Fa[i - 1][Fa[i - 1][v]];
    redfs(v);
  }
}
int lca(int x, int y) {
  if (dis[x] < dis[y]) swap(x, y);
  for (int i = (int)18; i >= (int)0; i--)
    if (dis[Fa[i][x]] >= dis[y]) x = Fa[i][x];
  for (int i = (int)18; i >= (int)0; i--)
    if (Fa[i][x] ^ Fa[i][y]) x = Fa[i][x], y = Fa[i][y];
  return (x == y) ? x : Fa[0][x];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)1; i <= (int)m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
    w[u].push_back(0);
    w[v].push_back(0);
  }
  tarjan(1);
  redfs(dis[1] = 1);
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", dep[x] + dep[y] - 2 * dep[lca(x, y)]);
  }
  return 0;
}
