#include <bits/stdc++.h>
using namespace std;
int N, M, K;
int ss[100010], ls[100010];
int as[100010], bs[100010];
int pago[100010];
int padres[100010];
int find(int x) {
  if (padres[x] == x) return x;
  padres[x] = find(padres[x]);
  return padres[x];
}
void join(int x, int y) { padres[find(y)] = find(x); }
void cc(int no) {
  for (int i = 0; i < N; ++i) {
    padres[i] = i;
  }
  for (int i = 0; i < M; ++i) {
    if (i == no) continue;
    join(as[i], bs[i]);
  }
}
int main() {
  memset(pago, 0, sizeof pago);
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", as + i, bs + i);
    as[i]--;
    bs[i]--;
  }
  scanf("%d", &K);
  for (int i = 0; i < K; ++i) {
    scanf("%d %d", ss + i, ls + i);
    ss[i]--;
    ls[i]--;
  }
  for (int i = 0; i < M; ++i) {
    cc(i);
    for (int j = 0; j < K; ++j) {
      if (find(ss[j]) != find(ls[j])) pago[j]++;
    }
  }
  for (int i = 0; i < K; ++i) {
    printf("%d\n", pago[i]);
  }
  return 0;
}
