#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
vector<pair<int, int> > g[110000];
vector<int> g2[110000];
int tt, tim, fup[110000], tin[110000], tout[110000], v1[110000], v2[110000],
    u[110000], us, c[110000], p[110000][20], d[110000];
bool b[110000];
void dfs(int v, int p = -1) {
  u[v] = true;
  tin[v] = fup[v] = tim++;
  for (int i = 0; i < (int)(g[v].size()); i++) {
    int to = g[v][i].first;
    if (to == p) continue;
    if (!u[to]) {
      dfs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tin[v]) b[g[v][i].second] = true;
    } else
      fup[v] = min(fup[v], tin[to]);
  }
}
void dfs2(int v, int col) {
  u[v] = us;
  c[v] = col;
  for (int i = 0; i < (int)(g[v].size()); i++) {
    int to = g[v][i].first;
    if (u[to] != us && !b[g[v][i].second]) dfs2(to, col);
  }
}
void dfs3(int v, int pr, int di) {
  d[v] = di;
  p[v][0] = pr;
  tin[v] = tt++;
  for (int i = 0; i < (int)(g2[v].size()); i++)
    if (g2[v][i] != pr) dfs3(g2[v][i], v, di + 1);
  tout[v] = tt++;
}
inline bool is_anc(int a, int b) {
  return tin[a] <= tin[b] && tout[b] <= tout[a];
}
int lca(int a, int b) {
  if (is_anc(a, b)) return a;
  if (is_anc(b, a)) return b;
  for (int i = 19; i >= 0; i--)
    while (!is_anc(p[a][i], b)) a = p[a][i];
  return p[a][0];
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)(m); i++) {
    scanf("%d%d", &v1[i], &v2[i]);
    v1[i]--;
    v2[i]--;
    g[v1[i]].push_back(make_pair(v2[i], i));
    g[v2[i]].push_back(make_pair(v1[i], i));
  }
  dfs(0);
  memset(u, 0, sizeof(u));
  us = 1;
  int cnt = 0;
  for (int i = 0; i < (int)(n); i++)
    if (u[i] != us) dfs2(i, cnt++);
  for (int i = 0; i < (int)(m); i++)
    if (b[i]) {
      g2[c[v1[i]]].push_back(c[v2[i]]);
      g2[c[v2[i]]].push_back(c[v1[i]]);
    }
  for (int i = 0; i < (int)(cnt); i++) {
    sort(g2[i].begin(), g2[i].end());
    g2[i].erase(unique(g2[i].begin(), g2[i].end()), g2[i].end());
  }
  dfs3(0, 0, 0);
  for (int i = 0; i < (int)(cnt); i++)
    for (int j = 1; j < 20; j++) p[i][j] = p[p[i][j - 1]][j - 1];
  int k;
  scanf("%d", &k);
  for (int i = 0; i < (int)(k); i++) {
    int v1, v2;
    scanf("%d%d", &v1, &v2);
    v1--;
    v2--;
    int ans = 0;
    if (c[v1] == c[v2])
      ans = 0;
    else {
      int l = lca(c[v1], c[v2]);
      ans = d[c[v1]] + d[c[v2]] - 2 * d[l];
    }
    printf("%d\n", ans);
  }
  return 0;
}
