#include <bits/stdc++.h>
using namespace std;
int ans;
vector<bool> used;
int a;
int b;
int last;
vector<vector<int>> g;
bool good;
void dfs(int v) {
  used[v] = true;
  if (v == last) {
    good = true;
  }
  for (int i = 0; i < (int)g[v].size() && good == false; ++i) {
    if (!((v == a && g[v][i] == b) || (v == b && g[v][i] == a))) {
      if (!used[g[v][i]]) {
        dfs(g[v][i]);
      }
    }
  }
}
int main() {
  int n;
  int m;
  cin >> n >> m;
  g.resize(n + 1);
  used.resize(n + 1);
  vector<pair<int, int>> edges(m);
  for (int i = 0; i < m; ++i) {
    int x;
    int y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
    edges[i] = (make_pair(x, y));
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    ans = 0;
    int x;
    int y;
    cin >> x >> y;
    if (x == y) {
      cout << "0" << endl;
      continue;
    }
    last = y;
    for (int j = 0; j < (int)edges.size(); ++j) {
      for (int l = 0; l < (int)used.size(); l++) {
        used[l] = false;
      }
      a = edges[j].first;
      b = edges[j].second;
      good = false;
      dfs(x);
      if (!used[y]) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}
