#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005], nodes;
int timen, p[100005][22], root, d[100005], low[100005];
bool vis[100005];
int tot[100005][22];
int l[100005], n;
void dfs(int s, int lvl) {
  vis[s] = 1;
  l[s] = lvl;
  timen++;
  low[s] = d[s] = timen;
  for (int i = 0; i < v[s].size(); i++) {
    int w = v[s][i];
    if (p[s][0] == w) continue;
    if (vis[w])
      low[s] = min(low[s], d[w]);
    else {
      p[w][0] = s;
      dfs(w, lvl + 1);
      low[s] = min(low[s], low[w]);
      if (d[s] < low[w]) {
        tot[w][0]++;
      }
    }
  }
}
void gen_table() {
  memset(p, -1, sizeof(p));
  memset(l, -1, sizeof(l));
  dfs(1, 1);
  for (int j = 1; (1 << j) < n; j++)
    for (int i = 1; i < n + 1; i++)
      if (p[i][j - 1] != -1) {
        p[i][j] = p[p[i][j - 1]][j - 1];
        tot[i][j] = tot[p[i][j - 1]][j - 1] + tot[i][j - 1];
      }
}
int query(int uu, int vv) {
  if (l[uu] < l[vv]) swap(uu, vv);
  int hi = log2(l[uu]) + 2;
  int total = 0;
  for (int i = hi; i >= 0; i--)
    if (l[uu] - (1 << i) >= l[vv]) {
      total += tot[uu][i];
      uu = p[uu][i];
    }
  if (uu == vv) return total;
  for (int i = hi; i >= 0; i--)
    if (p[uu][i] != -1 && p[uu][i] != p[vv][i]) {
      total += tot[uu][i];
      uu = p[uu][i];
      total += tot[vv][i];
      vv = p[vv][i];
    }
  total += tot[uu][0] + tot[vv][0];
  return total;
}
void ini() {
  timen = 0;
  memset(v, NULL, sizeof(v));
  memset(vis, 0, sizeof(vis));
}
int main() {
  int t, a, b, m, q;
  ini();
  scanf("%d %d", &n, &m);
  while (m--) {
    scanf("%d %d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  gen_table();
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &a, &b);
    printf("%d\n", query(a, b));
  }
  return 0;
}
