#include <bits/stdc++.h>
using namespace std;
int timer = 0;
vector<int> entr, low;
vector<vector<bool>> v;
vector<bool> vis;
vector<vector<int>> child;
vector<int> compo;
int ind = 0;
vector<vector<int>> adj;
vector<int> lca;
vector<int> city;
void makefalse() {
  for (int i = 0; i < vis.size(); i++) {
    vis[i] = false;
  }
}
void dfs(int g, int parent = -1) {
  vis[g] = true;
  timer++;
  entr[g] = timer;
  low[g] = timer;
  for (int i = 0; i < (int)(child[g].size()); i++) {
    int rd = child[g][i];
    if (rd == parent) continue;
    if (vis[rd])
      low[g] = min(low[g], entr[rd]);
    else {
      dfs(rd, g);
      low[g] = min(low[g], low[rd]);
      if (low[rd] > entr[g]) {
        v[rd][g] = true;
        v[g][rd] = true;
      }
    }
  }
}
void dfs2(int o) {
  vis[o] = true;
  compo[o] = ind;
  for (int i = 0; i < (int)(child[o].size()); i++) {
    if (!vis[child[o][i]] && !v[child[o][i]][o]) {
      dfs2(child[o][i]);
    }
  }
}
void dfs4(int f, int cnt) {
  vis[f] = true;
  lca.push_back(cnt);
  int l = (int)(lca.size()) - 1;
  city[f] = l;
  for (int s = 0; s < (int)(adj[f].size()); s++) {
    if (!vis[adj[f][s]]) {
      dfs4(adj[f][s], cnt + 1);
      lca.push_back(cnt);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  child.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    child[a].push_back(b);
    child[b].push_back(a);
  }
  v.resize(n + 1);
  for (int i = 0; i < n + 1; i++) {
    v[i].resize(n + 1);
  }
  entr.resize(n + 1);
  low.resize(n + 1);
  vis.resize(n + 1);
  compo.resize(n + 1);
  dfs(1);
  makefalse();
  for (int i = 1; i < n + 1; i++) {
    if (!vis[i]) {
      ind++;
      dfs2(i);
    }
  }
  adj.resize(ind + 1);
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < n + 1; j++) {
      if (v[i][j]) {
        adj[compo[i]].push_back(compo[j]);
        adj[compo[j]].push_back(compo[i]);
        v[j][i] = false;
      }
    }
  }
  vis.resize(ind + 1);
  makefalse();
  city.resize(ind + 1);
  dfs4(1, 1);
  int o = (int)(lca.size());
  int p = log2(o);
  int table[p + 1][o];
  for (int i = 0; i < p + 1; i++) {
    for (int j = 0; j < o - i; j++) {
      if (i == 0) {
        table[i][j] = lca[j];
      } else {
        int g = 1 << i;
        table[i][j] = min(table[i - 1][j], table[i - 1][j + (g / 2)]);
      }
    }
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int s, l;
    cin >> s >> l;
    int compo1 = compo[s];
    int compo2 = compo[l];
    int pos1 = city[compo1];
    int pos2 = city[compo2];
    int p1 = log2(max(pos1, pos2) - min(pos1, pos2) + 1);
    int pr = 1 << p1;
    int res =
        min(table[p1][min(pos1, pos2)], table[p1][max(pos1, pos2) - pr + 1]);
    cout << lca[min(pos1, pos2)] + lca[max(pos1, pos2)] - (2 * res) << "\n";
  }
}
