#include <bits/stdc++.h>
using namespace std;
int n, m;
bool connected[2001][2001];
int dest;
bool visited[2001];
struct Road {
  int p1, p2;
} roads[2000];
bool dfs(int n1) {
  visited[n1] = true;
  if (n1 == dest) return true;
  for (int i = 1; i <= n; i++) {
    if (connected[n1][i] && !visited[i]) {
      if (dfs(i)) return true;
    }
  }
  return false;
}
bool canGo(int roadNo, int n1, int n2) {
  int p1 = roads[roadNo].p1, p2 = roads[roadNo].p2;
  bool result;
  dest = n2;
  connected[p1][p2] = false;
  connected[p2][p1] = false;
  memset(visited, 0, sizeof(visited));
  result = dfs(n1);
  connected[p1][p2] = true;
  connected[p2][p1] = true;
  return result;
}
int getResult(int n1, int n2) {
  int result = 0;
  for (int i = 0; i < m; i++) {
    if (!canGo(i, n1, n2)) {
      result++;
    }
  }
  return result;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int n1, n2;
    cin >> n1 >> n2;
    roads[i].p1 = n1;
    roads[i].p2 = n2;
    connected[n1][n2] = true;
    connected[n2][n1] = true;
  }
  int nMerchants;
  cin >> nMerchants;
  while (nMerchants--) {
    int n1, n2;
    cin >> n1 >> n2;
    cout << getResult(n1, n2) << endl;
  }
  return 0;
}
