#include <bits/stdc++.h>
using namespace std;
int n, m, k, p, i, j, N;
vector<int> a[111111], tree[111111];
int used[111111];
int cnt, b[111111], c[111111], h[888888];
map<pair<int, int>, int> mp;
queue<int> q;
void dfs(int v, int p = -1) {
  used[v] = 1;
  b[v] = c[v] = cnt++;
  for (size_t i = 0; i < a[v].size(); ++i) {
    int to = a[v][i];
    if (to == p) continue;
    if (used[to])
      c[v] = min(c[v], b[to]);
    else {
      dfs(to, v);
      c[v] = min(c[v], c[to]);
      if (c[to] > b[v]) mp[make_pair(v, to)] = mp[make_pair(to, v)] = 1;
    }
  }
}
int find_min(int k, int p, int m = 1, int l = 1, int r = N) {
  if (l > p || r < k) return 1000000007;
  if (k <= l && r <= p) return h[m];
  return min(find_min(k, p, 2 * m, l, (l + r) / 2),
             find_min(k, p, 2 * m + 1, (l + r) / 2 + 1, r));
}
void find_components() {
  for (i = 0; i < n; i++) b[i] = i;
  for (i = 0; i < n; i++)
    if (b[i] == i) {
      q.push(i);
      while (!q.empty()) {
        k = q.front();
        q.pop();
        for (j = 0; j < a[k].size(); j++)
          if (mp.count(make_pair(k, a[k][j])) == 0 && b[a[k][j]] != i) {
            b[a[k][j]] = i;
            q.push(a[k][j]);
          }
      }
    }
}
void dfs2(int v, int height = 0, int p = -1) {
  h[cnt + N] = height;
  c[v] = cnt;
  cnt++;
  for (int i = 0; i < a[v].size(); ++i) {
    int to = a[v][i];
    if (to == p) continue;
    dfs2(a[v][i], height + 1, v);
    h[cnt + N] = height;
    cnt++;
  }
}
void construct_tree_lca() {
  for (i = 0; i < n; i++) a[i].clear();
  for (map<pair<int, int>, int>::iterator it = mp.begin(); it != mp.end();
       it++) {
    k = b[it->first.first];
    p = b[it->first.second];
    a[k].push_back(p);
  }
  for (i = 0; i < n; i++) used[i] = 0;
  for (N = 1; N < 2 * n; N *= 2)
    ;
  for (i = N + 1; i < 2 * N; i++) h[i] = 1000000007;
  cnt = 0;
  dfs2(0);
  for (i = N - 1; i > 0; i--) h[i] = min(h[2 * i], h[2 * i + 1]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &k, &p);
    k--;
    p--;
    a[k].push_back(p);
    a[p].push_back(k);
  }
  for (i = 0; i < n; i++) used[i] = 0;
  dfs(0);
  find_components();
  construct_tree_lca();
  scanf("%d", &i);
  while (i--) {
    scanf("%d%d", &k, &p);
    k = c[b[k - 1]];
    p = c[b[p - 1]];
    if (k > p) {
      j = k;
      k = p;
      p = j;
    }
    printf("%d\n", h[k + N] + h[p + N] - 2 * find_min(k + 1, p + 1));
  }
  return 0;
}
