#include <bits/stdc++.h>
using namespace std;
int n, m, q, x, y, t, ed, ret;
int v[2005], w[2005], bridge[2005], l[2005], qd[2005 + 2005], qn[2005 + 2005];
void dfs(int x, int y) {
  v[x] = w[x] = ++t;
  for (int i = (l[x]); i; i = qn[i])
    if (!v[qd[i]]) {
      dfs(qd[i], x);
      w[x] = min(w[x], w[qd[i]]);
      if (w[qd[i]] > v[x]) bridge[i >> 1] = 1;
    } else if (qd[i] != y)
      w[x] = min(w[x], v[qd[i]]);
}
void bd(int x, int y) { qd[++ed] = y, qn[ed] = l[x], l[x] = ed; }
int path(int x, int y) {
  v[x] = 1;
  if (x == y) return 1;
  for (int i = (l[x]); i; i = qn[i])
    if (!v[qd[i]] && path(qd[i], y)) {
      ret += bridge[i >> 1];
      return 1;
    }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  ed = 1;
  while (m--) scanf("%d%d", &x, &y), bd(x, y), bd(y, x);
  t = 0;
  dfs(1, 0);
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &x, &y);
    memset(v, 0, sizeof(v));
    ret = 0;
    path(x, y);
    printf("%d\n", ret);
  }
}
