#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
vector<vector<int> > g;
const int MAXN = 100000;
bool used[MAXN];
int timer, tin[MAXN], fup[MAXN];
int n;
map<pair<int, int>, bool> A;
void dfs(int v, int p = -1) {
  used[v] = true;
  tin[v] = fup[v] = timer++;
  for (size_t i = 0; i < g[v].size(); ++i) {
    int to = g[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]) A[make_pair(to, v)] = A[make_pair(v, to)] = true;
    }
  }
}
void find_bridges() {
  timer = 0;
  for (int i = 0; i < n; ++i) used[i] = false;
  for (int i = 0; i < n; ++i)
    if (!used[i]) dfs(i);
}
vector<int> path;
void bfs(int s, int end) {
  queue<int> q;
  q.push(s);
  memset(used, 0, 100000);
  vector<int> d(n), p(n);
  used[s] = true;
  p[s] = -1;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (size_t i = 0; i < g[v].size(); ++i) {
      int to = g[v][i];
      if (!used[to]) {
        used[to] = true;
        q.push(to);
        d[to] = d[v] + 1;
        p[to] = v;
      }
    }
  }
  for (int v = end; v != -1; v = p[v]) path.push_back(v);
}
int main() {
  int t, m;
  cin >> n >> t;
  g.assign(n, vector<int>());
  for (int i = 0; i < t; i++) {
    int u, v;
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  cin >> m;
  find_bridges();
  for (int i = 0; i < m; i++) {
    path.assign(0, 0);
    int u, v, ans = 0;
    cin >> u >> v;
    u--;
    v--;
    bfs(u, v);
    for (int j = 0; j < path.size(); j++) {
      if (j < path.size() - 1) {
        if (A.find(make_pair(path[j], path[j + 1])) != A.end()) ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
