#include <bits/stdc++.h>
using namespace std;
int parent[200 + 2];
struct Edge {
  int f, t;
} e[200 + 2];
int find(int n) {
  if (parent[n] == n) return n;
  return parent[n] = find(parent[n]);
}
bool isEqual(int x, int y) { return find(x) == find(y); }
void unite(int x, int y) { parent[find(x)] = parent[find(y)]; }
vector<pair<int, int> > v;
int main() {
  int n, m, f, t, Q;
  scanf("%d%d", &n, &m);
  v.clear();
  for (int i = 0; i < (int)(m); i++) {
    scanf("%d%d", &f, &t);
    v.push_back(make_pair(f, t));
  }
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &f, &t);
    int res = 0;
    for (int it = 0; it < (int)(int(v.size())); it++) {
      for (int i = 0; i < (int)(201); i++) parent[i] = i;
      for (int i = 0; i < (int)(int(v.size())); i++) {
        if (i != it) {
          unite(v[i].first, v[i].second);
        }
      }
      if (!isEqual(f, t)) res++;
    }
    printf("%d\n", res);
  }
  return 0;
}
