#include <bits/stdc++.h>
using namespace std;
vector<int> v[2501];
int one[2501], two[2501], a[2501], s[2501], f[2501], ans[2501], n, m, i, z, k,
    l;
bool mx[2501][2501], pole[2501];
void dfs(int nom) {
  int i;
  pole[nom] = true;
  a[nom] = l;
  for (i = 0; i < v[nom].size(); i++)
    if (mx[nom][v[nom][i]] && !pole[v[nom][i]]) dfs(v[nom][i]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> one[i] >> two[i];
    v[one[i]].push_back(two[i]);
    v[two[i]].push_back(one[i]);
    mx[one[i]][two[i]] = mx[two[i]][one[i]] = true;
  }
  cin >> k;
  for (i = 1; i <= k; i++) cin >> s[i] >> f[i];
  for (z = 1; z <= m; z++) {
    mx[one[z]][two[z]] = mx[two[z]][one[z]] = false;
    for (i = 1; i <= n; i++) pole[i] = false;
    l = 0;
    for (i = 1; i <= n; i++)
      if (!pole[i]) {
        l++;
        dfs(i);
      }
    for (i = 1; i <= k; i++)
      if (a[s[i]] != a[f[i]]) ans[i]++;
    mx[one[z]][two[z]] = mx[two[z]][one[z]] = true;
  }
  for (i = 1; i <= k; i++) cout << ans[i] << '\n';
  return 0;
}
