#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > neib;
vector<int> colors;
int color;
pair<int, int> close;
void dfs(int u) {
  if (colors[u] != 0) return;
  colors[u] = color;
  for (int i = 0; i < neib[u].size(); ++i) {
    int v = neib[u][i];
    if ((u == close.first && v == close.second) ||
        (u == close.second && v == close.first))
      continue;
    dfs(v);
  }
}
int main() {
  int n, m, u, v, k;
  cin >> n >> m;
  colors.resize(n);
  neib.resize(n);
  vector<pair<int, int> > edges;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    --u;
    --v;
    edges.push_back(make_pair(u, v));
    neib[u].push_back(v);
    neib[v].push_back(u);
  }
  cin >> k;
  vector<int> s(k), l(k), d(k);
  for (int i = 0; i < k; ++i) {
    cin >> s[i] >> l[i];
    --s[i];
    --l[i];
  }
  for (int i = 0; i < m; ++i) {
    close = edges[i];
    color = 0;
    for (int u = 0; u < n; ++u) colors[u] = 0;
    for (int u = 0; u < n; ++u)
      if (colors[u] == 0) {
        color++;
        dfs(u);
      }
    for (int j = 0; j < k; ++j)
      if (colors[s[j]] != colors[l[j]]) ++d[j];
  }
  for (int i = 0; i < k; ++i) cout << d[i] << endl;
  return 0;
}
