#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g(100001);
vector<bool> used(100001);
vector<int> t_in(100001);
vector<int> low(100001);
map<pair<int, int>, bool> edges;
set<pair<int, int> > used1;
vector<int> leader(100001);
vector<vector<int> > G(100001);
int timer = 0;
void dfs(int v, int e = -1) {
  used[v] = true;
  t_in[v] = low[v] = timer++;
  for (auto to : g[v]) {
    if (to == e) continue;
    if (used[to]) {
      low[v] = min(low[v], low[to]);
      continue;
    }
    dfs(to, v);
    low[v] = min(low[v], low[to]);
    if (low[to] > t_in[v]) edges[{v, to}] = edges[{to, v}] = true;
  }
}
void DFS(int v, int start) {
  used[v] = true;
  for (auto to : g[v]) {
    if (!used[to] && edges[{v, to}] == false) DFS(to, start);
  }
  leader[v] = start;
}
vector<int> depth(100001, 0);
int a[100001][21];
void filla() {
  for (int i = 1; i <= 100000; i++) {
    for (int j = 0; j <= 20; j++) a[i][j] = -1;
  }
}
void ddfs(int v, int e = -1) {
  a[v][0] = e;
  for (auto to : G[v]) {
    if (to != e) depth[to] = depth[v] + 1, ddfs(to, v);
  }
}
void prepare(int n) {
  ddfs(leader[1]);
  for (int j = 1; j <= 20; j++) {
    for (int i = 1; i <= n; i++) {
      if (a[i][j - 1] != -1) a[i][j] = a[a[i][j - 1]][j - 1];
    }
  }
}
int lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  int k = depth[u] - depth[v];
  while (k) {
    int t = log2(k);
    u = a[u][t];
    k -= (1 << t);
  }
  if (u == v) return v;
  for (int j = 20; j >= 0; j--) {
    if (a[u][j] != a[v][j]) {
      u = a[u][j];
      v = a[v][j];
    }
  }
  return a[u][0];
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    edges[{u, v}] = edges[{v, u}] = false;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  fill(used.begin(), used.end(), false);
  for (int i = 1; i <= n; i++) {
    if (!used[i]) DFS(i, i);
  }
  for (int v = 1; v <= n; v++) {
    for (auto to : g[v]) {
      int x = leader[v], y = leader[to];
      if (x != y)
        if (used1.find({y, x}) == used1.end() &&
            used1.find({x, y}) == used1.end() && edges[{to, v}] == true)
          G[x].push_back(y), G[y].push_back(x), used1.insert({x, y}),
              used1.insert({y, x});
    }
  }
  filla();
  prepare(n);
  int k;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    int u, v;
    cin >> u >> v;
    int x = leader[u];
    int y = leader[v];
    int z = lca(x, y);
    cout << depth[x] + depth[y] - 2 * depth[z] << "\n";
  }
}
int main() { solve(); }
