#include <bits/stdc++.h>
using namespace std;
struct rebro {
  int v, nom;
};
vector<vector<rebro> > g;
int ver[100003];
int fer[100003];
bool most[100003];
bool flag[100003];
int tim;
void dfs(int x, int pre) {
  int i;
  flag[x] = true;
  fer[x] = ver[x] = tim;
  tim++;
  for (i = 0; i < g[x].size(); i++) {
    if (pre == g[x][i].v) continue;
    if (!flag[g[x][i].v]) {
      dfs(g[x][i].v, x);
      fer[x] = min(fer[x], fer[g[x][i].v]);
      if (fer[g[x][i].v] > ver[x]) most[g[x][i].nom] = true;
    } else
      fer[x] = min(fer[x], ver[g[x][i].v]);
  }
}
int color[100003];
int coun;
int n, m, k;
void dfs2(int x) {
  int i;
  flag[x] = true;
  color[x] = coun;
  for (i = 0; i < g[x].size(); i++)
    if (!flag[g[x][i].v] && !most[g[x][i].nom]) dfs2(g[x][i].v);
}
vector<vector<int> > q;
int xx[100003], yy[100003];
int h[100003];
void dfs3(int x, int y) {
  flag[x] = true;
  h[x] = y;
  int i;
  for (i = 0; i < q[x].size(); i++)
    if (!flag[q[x][i]]) dfs3(q[x][i], y + 1);
}
int pred[100003];
int size[100003];
int findset(int v) {
  if (pred[v] == v) return v;
  return pred[v] = findset(pred[v]);
}
void uniset(int a, int b, int pre) {
  int x = findset(a);
  int y = findset(b);
  if (x != y) {
    if (size[x] >= size[y]) {
      size[x] += size[y];
      pred[y] = pre;
    } else {
      size[y] += size[x];
      pred[y] = pred[x] = pre;
    }
  }
}
vector<vector<rebro> > qq;
int ans[100003];
void dfs4(int x) {
  pred[x] = x;
  size[x] = 1;
  flag[x] = true;
  int i;
  for (i = 0; i < q[x].size(); i++)
    if (!flag[q[x][i]]) {
      dfs4(q[x][i]);
      uniset(x, q[x][i], x);
    }
  for (i = 0; i < qq[x].size(); i++)
    if (flag[qq[x][i].v]) ans[qq[x][i].nom] = pred[findset(qq[x][i].v)];
}
int main() {
  scanf("%d %d", &n, &m);
  int i;
  g.resize(n);
  rebro a;
  int x, y;
  for (i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    x--;
    y--;
    xx[i] = x;
    yy[i] = y;
    a.nom = i;
    a.v = y;
    g[x].push_back(a);
    a.v = x;
    g[y].push_back(a);
  }
  dfs(0, 0);
  for (i = 0; i < n; i++) flag[i] = false;
  for (i = 0; i < n; i++) {
    if (!flag[i]) {
      color[i] = coun;
      dfs2(i);
      coun++;
    }
  }
  q.resize(coun);
  for (i = 0; i < m; i++)
    if (most[i]) {
      q[color[xx[i]]].push_back(color[yy[i]]);
      q[color[yy[i]]].push_back(color[xx[i]]);
    }
  for (i = 0; i < coun; i++) flag[i] = false;
  dfs3(0, 0);
  qq.resize(coun);
  scanf("%d", &k);
  for (i = 0; i < k; i++) {
    scanf("%d %d", &x, &y);
    x--;
    y--;
    x = color[x];
    y = color[y];
    a.v = y;
    a.nom = i;
    xx[i] = x;
    yy[i] = y;
    qq[x].push_back(a);
    a.v = x;
    qq[y].push_back(a);
  }
  for (i = 0; i < coun; i++) flag[i] = false;
  dfs4(0);
  for (i = 0; i < k; i++) printf("%d\n", h[xx[i]] + h[yy[i]] - 2 * h[ans[i]]);
  return 0;
}
