#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 4;
struct edge {
  int u, v;
};
int n, m, k;
edge ed[M];
int dsu[M];
vector<edge> bri;
vector<int> adj1[M];
int vis[M];
int low[M], ini[M], cont;
vector<edge> adj2[M];
int dis[M];
int up[M][17];
int fin[M];
int find(int a) { return (a == dsu[a] ? a : dsu[a] = find(dsu[a])); }
void dfs1(int u, int p) {
  vis[u] = 1;
  low[u] = ini[u] = cont++;
  for (int v : adj1[u]) {
    if (v == p)
      continue;
    else if (vis[v])
      low[u] = min(low[u], ini[v]);
    else {
      dfs1(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] > ini[u]) bri.push_back({u, v});
    }
  }
}
void dfs2(int u, int p) {
  ini[u] = cont++;
  up[u][0] = p;
  for (int i = 1; i < 17; i++) up[u][i] = up[up[u][i - 1]][i - 1];
  for (edge v : adj2[u])
    if (v.u != p) {
      dis[v.u] = dis[u] + v.v;
      dfs2(v.u, u);
    }
  fin[u] = cont++;
}
bool isa(int u, int v) { return (ini[u] <= ini[v] && fin[v] <= fin[u]); }
int lca(int u, int v) {
  if (isa(u, v)) return u;
  if (isa(v, u)) return v;
  for (int i = 16; i >= 0; i--)
    if (!isa(up[u][i], v)) u = up[u][i];
  return up[u][0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj1[a].push_back(b);
    adj1[b].push_back(a);
    ed[i] = {a, b};
  }
  for (int i = 1; i <= n; i++) dsu[i] = i;
  dfs1(1, 1);
  for (edge e : bri) {
    dsu[find(e.u)] = find(e.v);
    adj2[e.u].push_back({e.v, 1});
    adj2[e.v].push_back({e.u, 1});
  }
  for (int i = 0; i < m; i++) {
    edge e = ed[i];
    if (find(e.u) != find(e.v)) {
      dsu[find(e.u)] = find(e.v);
      adj2[e.u].push_back({e.v, 0});
      adj2[e.v].push_back({e.u, 0});
    }
  }
  cont = 0;
  dfs2(1, 1);
  cin >> k;
  while (k--) {
    int a, b;
    cin >> a >> b;
    int u = lca(a, b);
    cout << dis[a] + dis[b] - 2 * dis[u] << "\n";
  }
  return 0;
}
