#include <bits/stdc++.h>
#pragma comment(linker, "/stack:128000000")
using namespace std;
const int INF = 1000000000;
const long long LINF = 4000000000000000000LL;
const double eps = 1e-9;
void prepare() {}
const int maxn = 100100;
struct Edge {
  int a, b, id, bridge;
};
vector<Edge> e, e2;
vector<int> g[maxn], g2[maxn];
int n, m, f;
int tin[maxn], tout[maxn], fup[maxn], timer;
int comp[maxn];
int up[maxn][20], dep[maxn];
void adde(int a, int b) {
  Edge t;
  t.a = a;
  t.b = b;
  t.id = ((int)(e).size());
  t.bridge = 0;
  e.push_back(t);
  g[t.a].push_back(t.id);
}
void read() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    adde(a, b);
    adde(b, a);
  }
}
void findBridges(int id, int p) {
  fup[id] = tin[id] = ++timer;
  for (int i = 0; i < ((int)(g[id]).size()); i++) {
    Edge &t = e[g[id][i]];
    if (t.b == p) continue;
    if (!tin[t.b]) {
      findBridges(t.b, id);
      fup[id] = min(fup[id], fup[t.b]);
      if (fup[t.b] > tin[id]) {
        t.bridge = 1;
        e[t.id ^ 1].bridge = 1;
      }
    } else
      fup[id] = min(fup[id], tin[t.b]);
  }
}
void findComponents(int id, int c) {
  if (comp[id] >= 0) return;
  comp[id] = c;
  for (int i = 0; i < ((int)(g[id]).size()); i++) {
    Edge &t = e[g[id][i]];
    if (!t.bridge) findComponents(t.b, c);
  }
}
void buildNewGraph(int newN) {
  e2 = e;
  e.clear();
  for (int i = 0; i < n; i++) {
    g2[i] = g[i];
    g[i].clear();
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < ((int)(g2[i]).size()); j++) {
      Edge &t = e2[g2[i][j]];
      if (comp[t.a] != comp[t.b]) {
        adde(comp[t.a], comp[t.b]);
        adde(comp[t.b], comp[t.a]);
      }
    }
  }
  e2.clear();
  for (int i = 0; i < n; i++) g2[i].clear();
  n = newN;
}
void preLCA(int id, int p, int curDep) {
  if (dep[id] > 0) return;
  tin[id] = ++timer;
  dep[id] = curDep;
  up[id][0] = p;
  for (int i = 1; i < 20; i++) up[id][i] = up[up[id][i - 1]][i - 1];
  for (int i = 0; i < ((int)(g[id]).size()); i++) {
    Edge &t = e[g[id][i]];
    if (t.b != p) preLCA(t.b, id, curDep + 1);
  }
  tout[id] = ++timer;
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int getLCA(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = 19; i >= 0; i--) {
    if (!upper(up[a][i], b)) a = up[a][i];
  }
  return up[a][0];
}
void gen() {
  n = 10000;
  f = 12;
  for (int j = 1; j < n; j++) {
    int p = rand() % j;
    adde(p, j);
    adde(j, p);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      int t;
      do {
        t = rand() % n;
      } while (t == i);
      adde(i, t);
      adde(t, i);
    }
  }
}
bool solve() {
  read();
  findBridges(0, -1);
  int cc = 0;
  memset((comp), -1, sizeof(comp));
  for (int i = 0; i < n; i++) {
    if (comp[i] < 0) findComponents(i, cc++);
  }
  buildNewGraph(cc);
  preLCA(comp[0], comp[0], 0);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    int v = getLCA(comp[a], comp[b]);
    printf("%d\n", dep[comp[a]] + dep[comp[b]] - dep[v] - dep[v]);
  }
  return false;
}
int main() {
  prepare();
  while (solve())
    ;
  return 0;
}
