#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, nxt;
} e[100005 << 1];
int n, m, tot, cnt, num;
int dfn[100005], fir[100005], col[100005], fa[100005][20], dep[100005];
vector<int> G[100005];
stack<pair<int, int> > E;
stack<int> st;
int read();
void add(int, int);
int dfs1(int, int);
void dfs2(int, int);
void make_graph();
int dist(int, int);
int lca(int, int);
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; ++i) add(read(), read());
  make_graph();
  int t = read();
  while (t--) {
    int u = read(), v = read();
    printf("%d\n", dist(col[u], col[v]));
  }
  return 0;
}
int read() {
  int x = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    ;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
  return x;
}
void add(int u, int v) {
  e[++cnt] = (edge){v, fir[u]};
  fir[u] = cnt;
  e[++cnt] = (edge){u, fir[v]};
  fir[v] = cnt;
  return;
}
void make_graph() {
  dfs1(1, 0);
  while (!E.empty()) {
    int u = col[E.top().first], v = col[E.top().second];
    E.pop();
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs2(1, 0);
  return;
}
int dfs1(int u, int f) {
  int lowu;
  lowu = dfn[u] = ++tot;
  st.push(u);
  for (int i = fir[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (!dfn[v]) {
      int tmp = dfs1(v, u);
      lowu = min(lowu, tmp);
      if (tmp > dfn[u]) E.push(make_pair(u, v));
    } else if (dfn[v] < dfn[u] && v != f)
      lowu = min(lowu, dfn[v]);
  }
  if (lowu == dfn[u]) {
    ++num;
    int now;
    do {
      now = st.top();
      st.pop();
      col[now] = num;
    } while (now != u);
  }
  return lowu;
}
void dfs2(int u, int f) {
  dep[u] = dep[f] + 1;
  fa[u][0] = f;
  for (int i = 1; i < 20; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  int sz = G[u].size();
  for (int i = 0; i < sz; ++i) {
    int v = G[u][i];
    if (v == f) continue;
    dfs2(v, u);
  }
  return;
}
int dist(int x, int y) {
  if (x == y)
    return 0;
  else
    return dep[x] + dep[y] - dep[lca(x, y)] * 2;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; ~i; --i)
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = 19; ~i; --i)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
