#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)1e5 + 10;
vector<int> g[maxn], gr[maxn];
int in[maxn], up[maxn], T, who[maxn], ID, dep[maxn], lf[maxn], rg[maxn],
    pr[maxn][33];
void dfs(int v, int p) {
  in[v] = up[v] = T++;
  for (int i = 0; i < (int)(g[v]).size(); i++) {
    int to = g[v][i];
    if (in[to]) {
      if (to != p) up[v] = min(up[v], in[to]);
    } else {
      dfs(to, v);
      up[v] = min(up[v], up[to]);
    }
  }
}
void make(int v, int id, int depth) {
  who[v] = id;
  bool here = false;
  if (!dep[id]) {
    dep[id] = depth;
    lf[id] = T++;
    here = true;
  }
  for (int i = 0; i < (int)(g[v]).size(); i++) {
    int to = g[v][i];
    if (who[to]) continue;
    if (up[to] > in[v]) {
      pr[ID][0] = id;
      for (int i = 1; i < 20; i++) pr[ID][i] = pr[pr[ID][i - 1]][i - 1];
      make(to, ID++, depth + 1);
    } else {
      make(to, id, depth);
    }
  }
  if (here) rg[id] = T++;
}
int upper(int a, int b) { return lf[a] <= lf[b] && rg[b] <= rg[a]; }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = 19; i >= 0; i--)
    if (pr[a][i] && !upper(pr[a][i], b)) a = pr[a][i];
  return pr[a][0];
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  T = 1;
  dfs(0, -1);
  T = 0;
  ID = 1;
  make(0, ID++, 1);
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &a, &b);
    --a;
    --b;
    a = who[a];
    b = who[b];
    int c = lca(a, b);
    printf("%d\n", dep[a] + dep[b] - 2 * dep[c]);
  }
  return 0;
}
