#include <bits/stdc++.h>
using namespace std;
const int maxn = 100050;
int n, m, k;
pair<int, int> buf[maxn];
pair<int, int> q[maxn];
int p[maxn];
int ans[maxn] = {};
int fd(int x) { return p[x] == x ? x : p[x] = fd(p[x]); }
void un(int a, int b) { p[fd(a)] = fd(b); }
int main(void) {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < (m); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    buf[i] = make_pair(a, b);
  }
  cin >> k;
  for (int i = 0; i < (k); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    q[i] = make_pair(a, b);
  }
  for (int c = 0; c < (m); ++c) {
    for (int i = 0; i < (n); ++i) p[i] = i;
    for (int i = 0; i < (m); ++i)
      if (i != c) un(buf[i].first, buf[i].second);
    for (int i = 0; i < (k); ++i)
      if (fd(q[i].first) != fd(q[i].second)) ++ans[i];
  }
  for (int i = 0; i < (k); ++i) cout << ans[i] << endl;
  return 0;
}
