#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 123, MXLG = 20;
pair<int, int> mp(int x, int y) { return {min(x, y), max(x, y)}; }
vector<int> g[MAXN], adj[MAXN];
int n, m, kam[MAXN], dis[MAXN], root[MAXN], por, par[MAXN][MXLG], k;
bool mark[MAXN];
map<pair<int, int>, bool> ce;
void inp();
void dfs(int, int = -1);
void pre();
void mirge(int);
void gp(int, int = -1);
void solve();
int lca(int, int);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  inp();
  pre();
  solve();
  return 0;
}
void inp() {
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    g[--u].push_back(--v), g[v].push_back(u);
  }
}
void dfs(int v, int p) {
  kam[v] = dis[v] = ((~p) ? dis[p] + 1 : 0);
  mark[v] = true;
  for (int u : g[v]) {
    if (!mark[u]) {
      dfs(u, v);
      kam[v] = min(kam[v], kam[u]);
      if (kam[u] > dis[v]) ce[mp(u, v)] = true;
    } else if (u != p)
      kam[v] = min(kam[v], dis[u]);
  }
}
void pre() {
  dfs(0);
  memset(mark, 0, sizeof mark);
  for (int i = 0; i < n; i++)
    if (!mark[i]) mirge(i), por++;
  memset(dis, 0, sizeof dis);
  gp(0);
  for (int i = 1; i < MXLG; i++)
    for (int j = 0; j < por; j++) par[j][i] = par[par[j][i - 1]][i - 1];
}
void mirge(int v) {
  mark[v] = true;
  root[v] = por;
  for (int u : g[v])
    if (!ce[mp(u, v)] && !mark[u])
      mirge(u);
    else if (mark[u] && ce[mp(u, v)])
      adj[por].push_back(root[u]), adj[root[u]].push_back(por);
}
void gp(int v, int p) {
  dis[v] = ((~p) ? dis[p] + 1 : 0);
  par[v][0] = p;
  for (int u : adj[v])
    if (u != p) gp(u, v);
}
void solve() {
  cin >> k;
  int u, v;
  while (k--) {
    cin >> u >> v;
    --u, --v;
    cout << dis[root[u]] + dis[root[v]] - (dis[lca(root[u], root[v])] << 1)
         << '\n';
  }
}
int lca(int u, int v) {
  if (dis[v] < dis[u]) swap(u, v);
  for (int i = MXLG - 1; ~i; i--)
    if (dis[par[v][i]] >= dis[u]) v = par[v][i];
  if (v == u) return u;
  for (int i = MXLG - 1; ~i; i--)
    if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
  return par[v][0];
}
