#include <bits/stdc++.h>
int n, m, k;
int road[200010][2];
int ask[100010][2];
int ans[100010];
int flag[100010];
int map[2010][2010];
int i, j;
void dfs(int id, int key) {
  int i;
  for (i = 1; i <= n; i++) {
    if (map[id][i] == 1 && flag[i] != key) {
      flag[i] = key;
      dfs(i, key);
    }
  }
}
int main() {
  memset(ans, 0, sizeof(ans));
  memset(map, 0, sizeof(map));
  memset(flag, -1, sizeof(flag));
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &road[i][0], &road[i][1]);
    map[road[i][0]][road[i][1]] = 1;
    map[road[i][1]][road[i][0]] = 1;
    road[i + m][0] = road[i][1];
    road[i + m][1] = road[i][0];
  }
  scanf("%d", &k);
  for (i = 0; i < k; i++) {
    scanf("%d%d", &ask[i][0], &ask[i][1]);
  }
  for (i = 0; i < m; i++) {
    map[road[i][0]][road[i][1]] = 0;
    map[road[i][1]][road[i][0]] = 0;
    memset(flag, -1, sizeof(flag));
    for (j = 0; j < k; j++) {
      flag[ask[j][0]] = j;
      dfs(ask[j][0], j);
      if (flag[ask[j][1]] != j) ans[j]++;
    }
    map[road[i][0]][road[i][1]] = 1;
    map[road[i][1]][road[i][0]] = 1;
  }
  for (i = 0; i < k; i++) printf("%d\n", ans[i]);
  return 0;
}
