#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
vector<vector<int> > g(MAXN);
bool used[MAXN];
int timer, tin[MAXN], fup[MAXN], n, val[MAXN][MAXN];
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]) {
        val[v][to] = 1;
        val[to][v] = 1;
      }
    }
  }
}
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);
}
priority_queue<pair<int, int> > q;
int main() {
  int i, j, m, k, l, r, x[MAXN], y[MAXN], t, v, to, w, d[MAXN], u;
  scanf("%d%d", &n, &m);
  for (; m--;) {
    scanf("%d%d", &l, &r);
    l--;
    r--;
    g[l].push_back(r);
    g[r].push_back(l);
  }
  scanf("%d", &k);
  for (i = 1; i <= k; i++) {
    scanf("%d%d", &x[i], &y[i]);
    x[i]--;
    y[i]--;
  }
  find_bridges();
  for (i = 1; i <= k; i++) {
    for (j = 0; j < n; j++) {
      d[j] = 100000;
    }
    q.push(make_pair(0, x[i]));
    d[x[i]] = 0;
    while (!q.empty()) {
      v = -q.top().first;
      u = q.top().second;
      q.pop();
      for (j = 0; j < g[u].size(); j++) {
        to = g[u][j];
        if (d[to] > d[u] + val[u][to]) {
          d[to] = d[u] + val[u][to];
          q.push(make_pair(-d[to], to));
        }
      }
    }
    printf("%d\n", d[y[i]]);
  }
  return 0;
}
