#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)2e6 + 1;
int N, M, Q, t_in[MAXN], t_low[MAXN], timer, cnt;
vector<vector<int> > G(MAXN);
bool used[MAXN], ind = false;
map<pair<int, int>, int> bridges;
map<int, bool> vis;
void DFS(int v, int par) {
  used[v] = true;
  t_in[v] = t_low[v] = ++timer;
  for (int i = 0; i < G[v].size(); i++) {
    int to = G[v][i];
    if (to == par) {
      continue;
    }
    if (used[to]) {
      t_low[v] = min(t_low[v], t_in[to]);
    } else {
      DFS(to, v);
      t_low[v] = min(t_low[v], t_low[to]);
      if (t_low[to] > t_in[v]) {
        bridges[make_pair(v, to)] = 1;
        bridges[make_pair(to, v)] = 1;
      }
    }
  }
}
void GET_ME(int v, int where) {
  used[v] = true;
  if (v == where) {
    ind = true;
    return;
  }
  for (int i = 0; i < G[v].size(); i++) {
    int to = G[v][i];
    if (!used[to] && !ind) {
      GET_ME(to, where);
      if (ind) {
        cnt += bridges[make_pair(v, to)];
      }
    }
  }
}
int main() {
  scanf("%d %d", &N, &M);
  int v, u, cl;
  while (M--) {
    scanf("%d %d", &v, &u);
    G[v].push_back(u);
    G[u].push_back(v);
  }
  DFS(1, -1);
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d %d", &v, &u);
    cnt = 0;
    ind = false;
    memset(used, false, sizeof(used));
    GET_ME(v, u);
    cout << cnt << endl;
  }
  return 0;
}
