#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000 + 10;
vector<vector<int>> g;
vector<int> mn, tin;
vector<bool> used;
set<pair<int, int>> bridges;
int timer = 0;
void find_bridges(int v, int p = -1) {
  tin[v] = mn[v] = ++timer;
  used[v] = true;
  for (auto to : g[v]) {
    if (to == p) {
      continue;
    }
    if (used[to]) {
      mn[v] = min(mn[v], tin[to]);
    } else {
      find_bridges(to, v);
      mn[v] = min(mn[v], mn[to]);
      if (tin[v] < mn[to]) {
        bridges.insert({min(v, to), max(v, to)});
      }
    }
  }
}
vector<int> component;
int cnt = 0;
void dfs(int v) {
  used[v] = true;
  component[v] = cnt;
  for (int to : g[v]) {
    if (used[to]) continue;
    if (bridges.find({min(v, to), max(v, to)}) == bridges.end()) dfs(to);
  }
}
vector<vector<int>> up;
vector<int> tout;
void mst(int v, vector<vector<int>>& tree, int p = 0) {
  tin[v] = ++timer;
  up[v][0] = p;
  for (int i = 1; i < 18; ++i) {
    up[v][i] = up[up[v][i - 1]][i - 1];
  }
  for (int to : tree[v]) {
    if (to != p) {
      mst(to, tree, v);
    }
  }
  tout[v] = ++timer;
}
bool upper(int u, int v) { return tin[u] <= tin[v] && tout[v] <= tout[u]; }
vector<int> degs;
int lca(int u, int v) {
  bool vu = upper(v, u);
  int ans = 0;
  for (int i = 17; i >= 0; --i) {
    if (!upper(up[u][i], v)) {
      ans += degs[i];
      u = up[u][i];
    }
  }
  if (!upper(u, v)) {
    u = up[u][0];
    ++ans;
  }
  if (vu) {
    return ans;
  }
  for (int i = 17; i >= 0; --i) {
    if (!upper(up[v][i], u)) {
      ans += degs[i];
      v = up[v][i];
    }
  }
  if (!upper(v, u)) {
    v = up[v][0];
    ++ans;
  }
  return ans;
}
int main() {
  cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  cout.setf(std::ios_base::fixed);
  int n, m;
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  mn.assign(n + 1, INF);
  tin.resize(n + 1);
  used.assign(n + 1, false);
  find_bridges(1);
  used.assign(n + 1, false);
  component.assign(n + 1, -1);
  for (int i = 1; i <= n; ++i) {
    if (!used[i]) {
      dfs(i);
      ++cnt;
    }
  }
  vector<vector<int>> tree(cnt);
  for (auto [u, v] : bridges) {
    int du = component[u];
    int dv = component[v];
    tree[du].push_back(dv);
    tree[dv].push_back(du);
  }
  up.resize(cnt, vector<int>(18, 0));
  tin.assign(cnt, 0);
  tout.assign(cnt, 0);
  timer = 0;
  mst(0, tree);
  degs.resize(18);
  int base = 1;
  for (int i = 0; i < 18; ++i) {
    degs[i] = base;
    base *= 2;
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; ++i) {
    int s, l;
    cin >> s >> l;
    int ds = component[s];
    int dl = component[l];
    cout << lca(ds, dl) << "\n";
  }
}
