#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long INF_LL = 1000000000000000000LL;
const int h = 100011, T = 20;
int n, m, k;
vector<int> r[h];
int t[h], mn[h], c[h];
int tt;
bool us[h];
void dfs(int v, int pr) {
  us[v] = true;
  t[v] = mn[v] = tt++;
  c[v] = v;
  for (int i(0), _b(int((r[v]).size())); i < _b; ++i) {
    int u = r[v][i];
    if (!us[u]) dfs(u, v);
    if (u != pr && mn[u] < mn[v]) {
      mn[v] = mn[u];
      c[v] = c[u];
    }
  }
}
vector<int> g[h];
int l[h], p[h][T];
void dfsp(int v, int pr) {
  l[v] = pr == -1 ? 0 : l[pr] + 1;
  p[v][0] = pr;
  for (int i(0), _b(T - 1); i < _b; ++i) {
    if (p[v][i] == -1) break;
    p[v][i + 1] = p[p[v][i]][i];
  }
  for (int i(0), _b(int((g[v]).size())); i < _b; ++i)
    if (g[v][i] != pr) dfsp(g[v][i], v);
}
int main() {
  scanf("%d%d", &n, &m);
  int a, b;
  for (int i(0), _b(m); i < _b; ++i) {
    scanf("%d%d", &a, &b);
    --a;
    --b;
    r[a].push_back(b);
    r[b].push_back(a);
  }
  memset(us, 0, sizeof us);
  tt = 0;
  dfs(0, -1);
  for (int v(0), _b(n); v < _b; ++v) {
    int u = v;
    vector<int> l;
    while (c[u] != u) {
      l.push_back(u);
      u = c[u];
    }
    for (int i(0), _b(int((l).size())); i < _b; ++i) c[l[i]] = u;
  }
  for (int v(0), _b(n); v < _b; ++v)
    for (int i(0), _b(int((r[v]).size())); i < _b; ++i) {
      int u = r[v][i];
      if (c[u] != c[v]) g[c[v]].push_back(c[u]);
    }
  for (int v(0), _b(n); v < _b; ++v) {
    sort((g[v]).begin(), (g[v]).end());
    g[v].resize(unique((g[v]).begin(), (g[v]).end()) - g[v].begin());
  }
  memset(p, -1, sizeof p);
  dfsp(0, -1);
  scanf("%d", &k);
  for (int kk(0), _b(k); kk < _b; ++kk) {
    scanf("%d%d", &a, &b);
    a = c[a - 1];
    b = c[b - 1];
    int res = 0;
    if (l[a] < l[b]) swap(a, b);
    for (int i(T - 1), _b(0); i >= _b; --i)
      if (l[a] - (1 << i) >= l[b]) {
        a = p[a][i];
        res += 1 << i;
      }
    for (int i(T - 1), _b(0); i >= _b; --i) {
      if (p[a][i] != p[b][i]) {
        a = p[a][i];
        b = p[b][i];
        res += 1 << (i + 1);
      }
    }
    if (a != b) res += 2;
    printf("%d\n", res);
  }
  return 0;
}
