#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
int xx[111111], yy[222222], pp[222222];
int was[111111], tt[111111], ff[111111], kk = 0, timer = 0, k;
int wasE[111111], most[111111], id[111111], d[111111], pr[111111][20],
    reald[111111];
void Dfs(int x, int pr) {
  was[x] = true;
  ff[x] = tt[x] = ++timer;
  for (int i = xx[x], y; i; i = pp[i])
    if (i != pr) {
      y = yy[i];
      if (was[y]) {
        ff[x] = min(ff[x], tt[y]);
      } else {
        Dfs(y, ((i - 1) ^ 1) + 1);
        if (ff[y] > tt[x]) {
          most[i] = true;
        }
        wasE[i] = true;
        ff[x] = min(ff[x], ff[y]);
      }
    }
}
void Mark(int x, int mar) {
  was[x] = true;
  id[x] = mar;
  for (int i = xx[x]; i; i = pp[i])
    if (wasE[i] && !most[i]) {
      Mark(yy[i], mar);
    }
}
void D(int x, int dd, int ppr) {
  was[x] = true;
  d[x] = dd;
  reald[x] = reald[ppr] + 1;
  pr[x][0] = ppr;
  for (int i = 1; i < 20; i++) pr[x][i] = pr[pr[x][i - 1]][i - 1];
  for (int i = xx[x]; i; i = pp[i])
    if (wasE[i]) {
      D(yy[i], dd + most[i], x);
    }
}
int Lca(int x, int y) {
  for (int i = 19; i >= 0; i--)
    if (reald[pr[x][i]] >= reald[y]) x = pr[x][i];
  for (int i = 19; i >= 0; i--)
    if (reald[pr[y][i]] >= reald[x]) y = pr[y][i];
  if (x == y) return x;
  for (int i = 19; i >= 0; i--)
    if (pr[y][i] != pr[x][i]) {
      x = pr[x][i];
      y = pr[y][i];
    }
  return pr[x][0];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    yy[++kk] = y, pp[kk] = xx[x], xx[x] = kk;
    yy[++kk] = x, pp[kk] = xx[y], xx[y] = kk;
  }
  for (int i = 1; i <= n; i++)
    if (!was[i]) Dfs(i, -1);
  memset(was, 0, sizeof(was));
  for (int i = 1; i <= n; i++) id[i] = i;
  for (int i = 1; i <= n; i++)
    if (!was[i]) Mark(i, i);
  memset(was, 0, sizeof(was));
  for (int i = 1; i <= n; i++)
    if (!was[i]) D(i, 0, 0);
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &x, &y);
    int t = Lca(x, y);
    printf("%d\n", d[x] - d[t] + d[y] - d[t]);
  }
  return 0;
}
