#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v1, v2;
} arr[2005];
struct shop {
  int w, s;
} A[2005];
int visit[2005], True;
int res[2005], dlt;
vector<int> v[2005];
void dfs(int u) {
  visit[u] = True;
  for (int i = 0; i < v[u].size(); ++i) {
    if (visit[v[u][i]]) continue;
    if (u == arr[dlt].v1 && v[u][i] == arr[dlt].v2) continue;
    if (u == arr[dlt].v2 && v[u][i] == arr[dlt].v1) continue;
    dfs(v[u][i]);
  }
}
int main() {
  int n, m, i, a, b, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; ++i) {
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
    arr[i].v1 = a, arr[i].v2 = b;
  }
  scanf("%d", &k);
  for (i = 1; i <= k; ++i) scanf("%d%d", &A[i].w, &A[i].s);
  for (dlt = 1; dlt <= m; ++dlt) {
    memset(visit, 0, sizeof visit);
    True = 0;
    for (i = 1; i <= n; ++i) {
      if (visit[i]) continue;
      ++True;
      dfs(i);
    }
    for (i = 1; i <= k; ++i) {
      if (visit[A[i].w] != visit[A[i].s]) ++res[i];
    }
  }
  for (i = 1; i <= k; ++i) printf("%d\n", res[i]);
  return 0;
}
