#include <bits/stdc++.h>
int n, m;
std::vector<std::pair<int, int> > r;
int ss[2020][2020], rnk[2020][2020];
int getKey(int i, int v) {
  if (v == ss[i][v]) return v;
  return ss[i][v] = getKey(i, ss[i][v]);
}
void Union(int i, int a, int b) {
  a = getKey(i, a);
  b = getKey(i, b);
  if (a != b) {
    if (rnk[i][a] < rnk[i][b]) std::swap(a, b);
    ss[i][b] = a;
    if (rnk[i][a] == rnk[i][b]) ++rnk[i][a];
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a;
    --b;
    r.push_back(std::pair<int, int>(a, b));
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      ss[i][j] = j;
      rnk[i][j] = 0;
    }
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j)
      if (i != j) Union(i, r[j].first, r[j].second);
  }
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u;
    --v;
    int cnt = 0;
    for (int j = 0; j < m; ++j)
      if (getKey(j, u) != getKey(j, v)) ++cnt;
    printf("%d\n", cnt);
  }
  return 0;
}
