#include <bits/stdc++.h>
using namespace std;
vector<int> adj[(int)1e6];
int pai[(int)1e6], n, m, st[(int)1e6], ed[(int)1e6], T = 0, ft[(int)1e6];
bool vis[(int)1e6];
int pp[(int)1e6], peso[(int)1e6];
int fd(int x) { return pp[x] == x ? x : pp[x] = fd(pp[x]); }
void join(int u, int v) {
  u = fd(u), v = fd(v);
  if (peso[u] < peso[v]) swap(u, v);
  pp[v] = u, peso[u] += peso[v];
}
set<pair<int, int> > s;
void dfs(int x) {
  st[x] = ft[x] = ++T;
  vis[x] = true;
  for (auto p : adj[x]) {
    if (p == pai[x]) continue;
    if (vis[p]) {
      ft[x] = min(ft[x], st[p]);
    } else {
      pai[p] = x;
      dfs(p);
      ft[x] = min(ft[x], ft[p]);
      if (ft[p] > st[x]) {
        s.insert(pair<int, int>(min(x, p), max(x, p)));
      }
    }
  }
}
set<pair<int, int> > w;
vector<pair<int, int> > ad[(int)1e6];
int sparse[22][200000], lca[22][200000];
void solve(int i, int j, int k) {
  lca[0][i] = j;
  sparse[0][i] = k;
  st[i] = ++T;
  for (int w = 1; w < 22; w++) {
    if (lca[w - 1][i] != -1) {
      lca[w][i] = lca[w - 1][lca[w - 1][i]];
      sparse[w][i] = sparse[w - 1][i] + sparse[w - 1][lca[w - 1][i]];
    }
  }
  for (auto p : ad[i]) {
    if (p.first == j) continue;
    solve(p.first, i, p.second);
  }
  ed[i] = T;
}
bool inside(int a, int b) { return (st[a] <= st[b] && ed[a] >= ed[b]); }
int32_t main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 22; j++) lca[j][i] = -1, sparse[j][i] = 0;
  }
  for (int i = 0; i < n; i++) {
    pp[i] = i, peso[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
    w.insert(pair<int, int>(min(x, y), max(x, y)));
  }
  pai[0] = -1;
  dfs(0);
  for (auto p : s) {
    ad[p.first].push_back(pair<int, int>(p.second, 1));
    ad[p.second].push_back(pair<int, int>(p.first, 1));
    join(p.first, p.second);
  }
  for (auto p : w) {
    if (fd(p.first) != fd(p.second)) {
      join(p.first, p.second);
      ad[p.first].push_back(pair<int, int>(p.second, 0));
      ad[p.second].push_back(pair<int, int>(p.first, 0));
    }
  }
  T = 0;
  solve(0, -1, 0);
  int K;
  scanf("%d", &K);
  while (K--) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    int U = 0;
    for (int j = 21; j >= 0; j--) {
      if (lca[j][a] != -1 && !inside(lca[j][a], b)) {
        U += sparse[j][a];
        a = lca[j][a];
      }
    }
    for (int j = 21; j >= 0; j--) {
      if (lca[j][b] != -1 && !inside(lca[j][b], a)) {
        U += sparse[j][b];
        b = lca[j][b];
      }
    }
    if (a == b) {
      printf("%d\n", U);
      continue;
    } else {
      if (inside(a, b)) {
        U += sparse[0][b];
      } else if (inside(b, a))
        U += sparse[0][a];
      else {
        U += sparse[0][b] + sparse[0][a];
      }
    }
    printf("%d\n", U);
  }
}
