#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<int> adj[100000];
int cur;
int p[100000], low[100000], ord[100000], w[100000];
void dfs(int u, int prev) {
  p[u] = prev;
  low[u] = ord[u] = cur++;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == prev) continue;
    if (ord[v] == -1) {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
    } else {
      low[u] = min(low[u], ord[v]);
    }
  }
  w[u] = (low[u] == ord[u]) ? 1 : 0;
}
int cnt[100000], depth[100000];
const int MAXD = 20;
int anc[100000][MAXD];
void dfs(int u, int prev, int c, int d) {
  cnt[u] = c;
  depth[u] = d;
  anc[u][0] = prev;
  for (int i = 1; i < MAXD; i++) {
    int next = anc[u][i - 1];
    if (next == -1)
      anc[u][i] = -1;
    else
      anc[u][i] = anc[next][i - 1];
  }
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (p[v] == u) dfs(v, u, c + w[v], d + 1);
  }
}
int get_lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  int diff = depth[u] - depth[v];
  for (int i = MAXD - 1; i >= 0; i--)
    if (diff & (1 << i)) u = anc[u][i];
  if (u == v) return u;
  for (int i = MAXD - 1; i >= 0; i--) {
    int nu = anc[u][i], nv = anc[v][i];
    if (nu != nv) u = nu, v = nv;
  }
  return anc[u][0];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].push_back(b), adj[b].push_back(a);
  }
  for (int i = 0; i < n; i++) ord[i] = -1;
  dfs(0, -1);
  dfs(0, -1, 0, 0);
  cin >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    int l = get_lca(a, b);
    cout << (cnt[a] + cnt[b] - 2 * cnt[l]) << endl;
  }
}
