#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 3, lg = 20;
int n, m, k, par[maxn][lg], sum[maxn][lg], h[maxn], is[maxn];
vector<int> g[maxn];
bool visited[maxn];
int get_sum(int v, int dis) {
  int s = 0;
  for (int i = 0; i < lg; i++) {
    if (dis & (1 << i)) {
      s += sum[v][i];
      v = par[v][i];
    }
  }
  return s;
}
int lca(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  for (int i = lg - 1; i >= 0; i--)
    if (h[v] - (1 << i) >= h[u]) v = par[v][i];
  if (v == u) return v;
  for (int i = lg - 1; i >= 0; i--) {
    if (par[v][i] != par[u][i]) {
      v = par[v][i];
      u = par[u][i];
    }
  }
  return par[v][0];
}
int dfs(int v, int parent) {
  visited[v] = true;
  par[v][0] = parent;
  for (int i = 1; i < lg and par[v][i - 1] != -1; i++)
    par[v][i] = par[par[v][i - 1]][i - 1];
  int top = h[v];
  for (int u : g[v]) {
    if (!visited[u]) {
      h[u] = h[v] + 1;
      top = min(top, dfs(u, v));
    } else if (u != parent)
      top = min(top, h[u]);
  }
  if (top == h[v] and v != 1) is[v] = 1;
  return top;
}
void dfs2(int v, int dis) {
  visited[v] = true;
  if (par[v][dis - 1] != -1)
    sum[v][dis] = sum[v][dis - 1] + sum[par[v][dis - 1]][dis - 1];
  for (int u : g[v])
    if (!visited[u]) dfs2(u, dis);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) fill_n(par[i], lg, -1);
  dfs(1, -1);
  for (int i = 1; i <= n; i++) sum[i][0] = is[i];
  for (int i = 1; i < lg; i++) {
    fill_n(visited, n + 1, false);
    dfs2(1, i);
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    int lc = lca(u, v);
    int s1 = get_sum(v, h[v] - h[lc]);
    int s2 = get_sum(u, h[u] - h[lc]);
    cout << s1 + s2 << '\n';
  }
}
