#include <bits/stdc++.h>
using namespace std;
const int maxl = 1000 * 100 + 5;
const int maxlg = 21;
vector<pair<int, int> > adj[maxl];
int n, m, k;
int par[maxlg][maxl], depth[maxl];
bool marked[maxl];
bool mark[maxl];
int dis[maxl];
int dfs(int index) {
  marked[index] = true;
  int res = depth[index];
  for (int i = 0; i < adj[index].size(); i++) {
    int node = adj[index][i].first, edge = adj[index][i].second;
    if (marked[node] && node != par[0][index]) res = min(res, depth[node]);
    if (!marked[node]) {
      depth[node] = depth[index] + 1;
      dis[node] = dis[index] + !mark[edge];
      par[0][node] = index;
      int tmp = dfs(node);
      mark[edge] = (tmp <= depth[index]);
      res = min(res, tmp);
    }
  }
  return res;
}
inline int getpar(int index, int k) {
  for (int i = maxlg - 1; i >= 0; i--)
    if ((k & (1 << i))) index = par[i][index];
  return index;
}
int lca(int a, int b) {
  if (depth[a] > depth[b]) swap(a, b);
  b = getpar(b, depth[b] - depth[a]);
  if (a == b) return a;
  for (int i = maxlg - 1; i >= 0; i--)
    if (par[i][a] != par[i][b]) {
      a = par[i][a];
      b = par[i][b];
    }
  return par[0][a];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    adj[a].push_back(make_pair(b, i));
    adj[b].push_back(make_pair(a, i));
  }
  dfs(0);
  for (int j = 1; j < maxlg; j++)
    for (int i = 0; i < n; i++) par[j][i] = par[j - 1][par[j - 1][i]];
  memset(marked, 0, sizeof marked);
  dfs(0);
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    int s, l;
    scanf("%d %d", &s, &l);
    s--;
    l--;
    int x = lca(s, l);
    printf("%d\n", dis[s] + dis[l] - dis[x] * 2);
  }
}
