#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:300000000")
#pragma warning(disable : 4800)
using namespace std;
const double pi = 3.1415926535897932384626433832795;
template <class T>
T abs(const T &a) {
  return a >= 0 ? a : -a;
};
template <class T>
T sqr(const T &x) {
  return x * x;
}
int n, m, k;
vector<vector<int> > g;
vector<bool> visited;
vector<int> ans;
vector<pair<int, int> > traders;
pair<int, int> erased;
bool isErased(int x, int y) {
  return pair<int, int>(x, y) == erased || pair<int, int>(y, x) == erased;
}
void dfs(int k) {
  if (visited[k]) return;
  visited[k] = true;
  for (int i = 0; i < (int((g[k]).size())); i++) {
    int to = g[k][i];
    if (!isErased(k, to)) dfs(to);
  }
}
void work(int x, int y) {
  erased = pair<int, int>(x, y);
  visited.assign(n, false);
  dfs(x);
  for (int i = 0; i < (k); i++)
    if (visited[traders[i].first] && !visited[traders[i].second]) ans[i]++;
}
int main() {
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < (m); i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cin >> k;
  ans.resize(k);
  traders.resize(k);
  for (int i = 0; i < (k); i++) {
    cin >> traders[i].first >> traders[i].second;
    traders[i].first--;
    traders[i].second--;
  }
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (int((g[i]).size())); j++) work(i, g[i][j]);
  for (int i = 0; i < (k); i++) cout << ans[i] << endl;
}
