#include <bits/stdc++.h>
template <class T>
inline void chkmax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class T>
inline void chkmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <class T>
inline void read(T &x) {
  char c;
  int f = 1;
  x = 0;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    f = -1;
  else
    x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= f;
}
static int outn;
static char out[(int)2e7];
template <class T>
inline void write(T x) {
  if (x < 0) out[outn++] = '-', x = -x;
  if (x) {
    static int tmpn;
    static char tmp[20];
    tmpn = 0;
    while (x) tmp[tmpn++] = x % 10 + '0', x /= 10;
    while (tmpn) out[outn++] = tmp[--tmpn];
  } else
    out[outn++] = '0';
}
const int N = 1e5, M = 2e5;
int n, m;
struct graph {
  int sz, head[N + 9], to[M + 9], ne[M + 9];
  graph() { sz = 1, memset(head, 0, sizeof head); }
  void addedge(int u, int v) {
    to[sz] = v, ne[sz] = head[u], head[u] = sz++;
    to[sz] = u, ne[sz] = head[v], head[v] = sz++;
  }
} g, h;
int dfn[N + 9], low[N + 9], tot;
int bel[N + 9], beln, st[N + 9], stn;
void dfs(int now, int fe) {
  dfn[now] = low[now] = ++tot, st[++stn] = now;
  for (int i = g.head[now], to; i; i = g.ne[i])
    if (!dfn[to = g.to[i]]) {
      dfs(to, i);
      chkmin(low[now], low[to]);
    } else if (i != ((((fe)-1) ^ 1) + 1))
      chkmin(low[now], dfn[to]);
  if (dfn[now] == low[now]) {
    ++beln;
    do bel[st[stn--]] = beln;
    while (st[stn + 1] != now);
  }
}
int dep[N + 9], f[20][N + 9];
void get(int now, int fa) {
  f[0][now] = fa, dep[now] = dep[fa] + 1;
  for (int i = h.head[now], to; i; i = h.ne[i])
    if ((to = h.to[i]) != fa) get(to, now);
}
void prelca() {
  for (int i = 1; i < 20; ++i)
    for (int j = 1; j <= beln; ++j) f[i][j] = f[i - 1][f[i - 1][j]];
}
int up(int x, int y) {
  int i = 0;
  while (y) {
    if (y & 1) x = f[i][x];
    i++, y >>= 1;
  }
  return x;
}
int getlca(int u, int v) {
  if (dep[u] < dep[v]) std::swap(u, v);
  if (dep[u] > dep[v]) u = up(u, dep[u] - dep[v]);
  while (u != v) {
    for (int i = 19; i >= 0; --i)
      if (f[i][u] != f[i][v]) u = f[i][u], v = f[i][v];
    if (f[0][u] == f[0][v]) u = v = f[0][u];
  }
  return u;
}
int dis(int x, int y) { return dep[x] + dep[y] - 2 * dep[getlca(x, y)]; }
int main() {
  read(n), read(m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    read(u), read(v);
    g.addedge(u, v);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; ++i)
    for (int j = g.head[i]; j; j = g.ne[j])
      if ((j & 1) && bel[i] != bel[g.to[j]]) h.addedge(bel[i], bel[g.to[j]]);
  get(1, 0), prelca();
  int k;
  read(k);
  while (k--) {
    int x, y;
    read(x), read(y);
    printf("%d\n", dis(bel[x], bel[y]));
  }
  return 0;
}
