#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
  if (fabs(d) < eps) return 0;
  return d > eps ? 1 : -1;
}
const int maxn = 210000;
struct edge {
  int u, v, next;
} a[420000];
int start[maxn], tot = 0;
int dfn[maxn], low[maxn], root, cut[maxn], n, m, stamp, pos, id[maxn], bcnt;
int v[maxn], in[maxn];
struct node {
  int u, v;
} br[maxn];
void init(int n) {
  memset(dfn, 0, sizeof(dfn[0]) * (n + 3));
  memset(low, 0, sizeof(low[0]) * (n + 3));
  memset(cut, 0, sizeof(cut[0]) * (n + 3));
  memset(start, -1, sizeof(start[0]) * (n + 3));
  memset(id, -1, sizeof(id[0]) * (n + 3));
  memset(in, 0, sizeof(in[0]) * (n + 3));
  for (int i = 1; i <= n + 3; i++) v[i] = i;
  bcnt = pos = tot = 0;
}
int f1(int u) { return u == v[u] ? u : v[u] = f1(v[u]); }
void ui(int x, int y) {
  int p = f1(x), q = f1(y);
  v[p] = q;
}
inline void addedge(int u, int v) {
  a[tot].u = u;
  a[tot].v = v;
  a[tot].next = start[u];
  start[u] = tot++;
}
void dfs(int u, int pa) {
  low[u] = dfn[u] = ++stamp;
  int td = 0;
  for (int i = start[u]; i != -1; i = a[i].next) {
    int j(a[i].v);
    if (!dfn[j]) {
      td++;
      dfs(j, u);
      low[u] = min(low[u], low[j]);
      if (low[j] <= dfn[u]) {
        ui(u, j);
      } else {
        br[pos].u = u;
        br[pos++].v = j;
      }
    } else {
      if (j != pa) {
        low[u] = min(low[u], dfn[j]);
      }
    }
  }
}
vector<int> g[maxn];
void bcc() {
  int i, j, k;
  for (i = 1; i <= n; i++) {
    int tmp = f1(i);
    if (id[tmp] == -1) {
      id[tmp] = ++bcnt;
    }
    id[i] = id[tmp];
  }
  for (i = 0; i < pos; i++) {
    g[id[br[i].u]].push_back(id[br[i].v]);
    g[id[br[i].v]].push_back(id[br[i].u]);
  }
}
int deep[maxn];
int f[maxn][19];
void dd(int x, int d, int fa) {
  deep[x] = d;
  int i;
  for (i = 1; i <= 18; i++) {
    if (f[x][i - 1] != -1) {
      f[x][i] = f[f[x][i - 1]][i - 1];
    }
  }
  for (__typeof(g[x].begin()) e = g[x].begin(); e != g[x].end(); ++e) {
    if (*e == fa) continue;
    f[*e][0] = x;
    dd(*e, d + 1, x);
  }
}
int LCA(int x, int y) {
  int i, j, k;
  if (deep[x] < deep[y]) swap(x, y);
  for (i = deep[x] - deep[y], j = 0; i; i >>= 1, j++) {
    if (i & 1) x = f[x][j];
  }
  i = 18 - 1;
  while (x != y) {
    for (; i && f[x][i] == f[y][i]; i--)
      ;
    x = f[x][i];
    y = f[y][i];
  }
  return x;
}
int main() {
  int i, j, k;
  scanf("%d%d", &n, &m);
  init(n);
  for (i = 0; i < m; i++) {
    int q, w;
    scanf("%d%d", &q, &w);
    addedge(q, w);
    addedge(w, q);
  }
  int cnt = 0;
  stamp = 0;
  root = 1;
  dfs(1, -1);
  bcc();
  dd(1, 0, -1);
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = id[x];
    y = id[y];
    int c = LCA(x, y);
    printf("%d\n", deep[x] + deep[y] - 2 * deep[c]);
  }
  return 0;
}
