#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16000000")
vector<int> edges[100000];
int bridges[5000][5000] = {0};
bool used[100000] = {0};
int tin[100000], fup[100000];
int timer = 0;
void dfs(int v, int p = -1) {
  used[v] = true;
  tin[v] = fup[v] = timer++;
  for (int i = 0; i < edges[v].size(); i++) {
    int to = edges[v][i];
    if (to == p) continue;
    if (used[to])
      fup[v] = min(fup[v], tin[to]);
    else {
      dfs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tin[v]) bridges[to][v] = bridges[v][to] = 1;
    }
  }
}
int dfs2(int a, int b) {
  if (a == b) return 0;
  used[a] = true;
  for (int i = 0; i < edges[a].size(); i++) {
    int next = edges[a][i];
    int t;
    if (!used[next] && (t = dfs2(next, b)) != -1) {
      if (bridges[next][a]) t++;
      return t;
    }
  }
  return -1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int ai, bi;
    scanf("%d%d", &ai, &bi);
    ai--;
    bi--;
    edges[ai].push_back(bi);
    edges[bi].push_back(ai);
  }
  timer = 0;
  for (int i = 0; i < n; ++i) used[i] = false;
  for (int i = 0; i < n; ++i)
    if (!used[i]) dfs(i);
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    int ci, di;
    scanf("%d%d", &ci, &di);
    ci--;
    di--;
    for (int j = 0; j < n; j++) used[j] = 0;
    cout << dfs2(ci, di) << endl;
  }
}
