#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2005;
const int inf = (int)1e9 + 7;
vector<vector<int> > g;
int mark[MaxN], br[MaxN][MaxN], st[MaxN], fi[MaxN], n, m, q[MaxN], h, t,
    d[MaxN], pr[MaxN], cnt;
void dfs(int v, int p) {
  int i;
  mark[v] = 1;
  for (i = 0; i < m; i++) {
    if (i == p) continue;
    if (st[i] == v) {
      if (mark[fi[i]] == 0) dfs(fi[i], p);
    }
    if (fi[i] == v) {
      if (mark[st[i]] == 0) dfs(st[i], p);
    }
  }
}
void rec(int v) {
  if (v == -1) {
    return;
  }
  if (br[v][pr[v]]) cnt++;
  rec(pr[v]);
}
int main() {
  int i, j, a, b, ii, v, k;
  for (i = 0; i < MaxN; i++) {
    for (j = 0; j < MaxN; j++) {
      br[i][j] = 0;
    }
  }
  g.resize(MaxN);
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> st[i] >> fi[i];
    g[st[i]].push_back(fi[i]);
    g[fi[i]].push_back(st[i]);
  }
  for (i = 0; i < m; i++) {
    for (j = 1; j <= n; j++) {
      mark[j] = 0;
    }
    dfs(1, i);
    int flag = 0;
    for (j = 1; j <= n; j++) {
      if (mark[j] == 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      br[st[i]][fi[i]] = 1;
      br[fi[i]][st[i]] = 1;
    }
  }
  cin >> k;
  for (ii = 0; ii < k; ii++) {
    for (i = 0; i < MaxN; i++) {
      d[i] = inf;
      pr[i] = -1;
    }
    cin >> a >> b;
    h = 0;
    t = 1;
    q[h] = a;
    d[a] = 0;
    while (h < t) {
      v = q[h];
      h++;
      for (i = 0; i < g[v].size(); i++) {
        if (d[g[v][i]] > d[v] + 1) {
          d[g[v][i]] = d[v] + 1;
          pr[g[v][i]] = v;
          q[t] = g[v][i];
          t++;
        }
      }
    }
    cnt = 0;
    rec(b);
    cout << cnt << endl;
  }
}
