#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > e;
int n, m, K;
int father[1005];
int getFather(int v) {
  if (father[v] == v)
    return v;
  else {
    father[v] = getFather(father[v]);
    return father[v];
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    e.clear();
    for (int i = 0; i < m; ++i) {
      int a, b;
      scanf("%d%d", &a, &b);
      e.push_back(pair<int, int>(a, b));
    }
    scanf("%d", &K);
    while (K--) {
      int s, l;
      scanf("%d%d", &s, &l);
      int ans = 0;
      for (int i = 0; i < e.size(); ++i) {
        for (int j = 1; j <= n; ++j) father[j] = j;
        for (int j = 0; j < e.size(); ++j) {
          if (j == i) continue;
          int fx = getFather(e[j].first);
          int fy = getFather(e[j].second);
          if (fx != fy) father[fx] = fy;
        }
        int fx = getFather(s);
        int fy = getFather(l);
        if (fx != fy) ++ans;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
