#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > gstart;
vector<vector<int> > gupd;
vector<vector<int> > g;
vector<vector<int> > up;
bool used[102400];
int tin[102400];
int tout[102400];
int fup[102400];
int comp[102400];
int len[102400];
int timer;
int n, m, k, l;
int N;
set<pair<int, int> > bridges;
void dfs(int v, int p = -1) {
  used[v] = true;
  tin[v] = fup[v] = timer++;
  for (int i = 0; i < gstart[v].size(); i++) {
    int to = gstart[v][i];
    if (to == p) continue;
    if (used[to])
      fup[v] = min(fup[v], tin[to]);
    else {
      dfs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tin[v]) {
        bridges.insert(make_pair(to, v));
        bridges.insert(make_pair(v, to));
      }
    }
  }
}
void find_bridges() {
  timer = 0;
  for (int i = 0; i < n; ++i) used[i] = false;
  for (int i = 0; i < n; ++i)
    if (!used[i]) dfs(i, -1);
}
void delete_bridges() {
  gupd.resize(gstart.size());
  for (int i = 0; i < gupd.size(); i++)
    for (int j = 0; j < gstart[i].size(); j++)
      if (bridges.empty() ||
          bridges.find(make_pair(i, gstart[i][j])) == bridges.end())
        gupd[i].push_back(gstart[i][j]);
}
void find_comp(int v, int c) {
  comp[v] = c;
  used[v] = true;
  for (int i = 0; i < gupd[v].size(); i++) {
    int next = gupd[v][i];
    if (!used[next]) find_comp(next, c);
  }
}
void find_all_comps() {
  int c = 0;
  memset(used, 0, sizeof(used));
  for (int i = 0; i < n; i++)
    if (!used[i]) {
      find_comp(i, c);
      ++c;
    }
  N = c;
}
void dfs_lca(int v, int p = 0) {
  tin[v] = ++timer;
  up[v][0] = p;
  for (int i = 1; i <= l; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to != p) dfs_lca(to, v);
  }
  tout[v] = ++timer;
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = l; i >= 0; --i)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
void find_len(int v, int c) {
  used[v] = true;
  len[v] = c;
  for (int i = 0; i < g[v].size(); i++) {
    int next = g[v][i];
    if (!used[next]) find_len(next, c + 1);
  }
}
int main() {
  cin >> n >> m;
  gstart.resize(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x;
    --y;
    gstart[x].push_back(y);
    gstart[y].push_back(x);
  }
  find_bridges();
  delete_bridges();
  memset(used, 0, sizeof used);
  find_all_comps();
  g.resize(N);
  for (set<pair<int, int> >::iterator it = bridges.begin(); it != bridges.end();
       ++it) {
    g[comp[it->first]].push_back(comp[it->second]);
    g[comp[it->second]].push_back(comp[it->first]);
  }
  for (int i = 0; i < g.size(); i++) {
    sort(g[i].begin(), g[i].end());
    vector<int>::iterator it = unique(g[i].begin(), g[i].end());
    g[i].resize(it - g[i].begin());
  }
  n = N;
  memset(tin, 0, sizeof tin);
  memset(tout, 0, sizeof tout);
  timer = 0;
  up.resize(n);
  l = 1;
  while ((1 << l) <= n) ++l;
  for (int i = 0; i < n; ++i) up[i].resize(l + 1);
  dfs_lca(0);
  memset(used, 0, sizeof used);
  find_len(0, 0);
  cin >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    a = comp[a];
    b = comp[b];
    int res = len[a] + len[b] - 2 * len[lca(a, b)];
    cout << res << endl;
  }
}
