#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 10, lg = 20;
long long n, m, k, u, v, second, l, par[lg][MAXN], cm[MAXN], sz[MAXN], h[MAXN],
    dp[MAXN];
bool bo[MAXN];
vector<pair<long long, long long> > edge;
vector<long long> adj[MAXN];
long long Find(long long u) {
  if (u == cm[u]) return u;
  return cm[u] = Find(cm[u]);
}
void merge(long long u, long long v) {
  u = Find(u), v = Find(v);
  if (u == v) return;
  if (sz[v] < sz[u]) swap(u, v);
  sz[v] += sz[u], cm[u] = v;
  return;
}
void dfs(long long u, long long p) {
  bo[u] = true, dp[u] = h[u];
  for (auto v : adj[u])
    if (!bo[v]) {
      h[v] = h[u] + 1, dfs(v, u);
      if (dp[v] < h[v]) merge(u, v);
      dp[u] = min(dp[u], dp[v]);
    } else if (v != p)
      dp[u] = min(dp[u], h[v]);
  return;
}
void DFS(long long u) {
  bo[u] = true;
  for (long long i = 1; i < lg; i++)
    if (par[i - 1][u] != -1) par[i][u] = par[i - 1][par[i - 1][u]];
  for (auto v : adj[u])
    if (!bo[v]) par[0][v] = u, h[v] = h[u] + 1, DFS(v);
  return;
}
long long Find_lca(long long u, long long x) {
  for (long long i = 0; i < lg; i++)
    if (x & (1 << i)) u = par[i][u];
  return u;
}
long long LCA(long long u, long long v) {
  if (h[v] < h[u]) swap(v, u);
  long long x = h[v] - h[u];
  v = Find_lca(v, x);
  if (u == v) return v;
  for (long long i = lg - 1; i >= 0; i--)
    if (par[i][v] != par[i][u]) u = par[i][u], v = par[i][v];
  return par[0][u];
}
void dfs_all() {
  for (long long i = 0; i < n; i++)
    if (!bo[i]) DFS(i);
  return;
}
void input() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++)
    cin >> u >> v, u--, v--, adj[u].push_back(v), adj[v].push_back(u),
        edge.push_back(make_pair(u, v));
  return;
}
void query() {
  cin >> second >> l, second--, l--,
      second = Find(second), l = Find(l),
      cout << h[second] + h[l] - 2 * h[LCA(second, l)] << endl;
  return;
}
int32_t main() {
  input();
  for (long long i = 0; i < n; i++) cm[i] = i;
  dfs(0, -1);
  for (long long i = 0; i < n; i++) adj[i].clear();
  for (long long i = 0; i < m; i++)
    if ((u = Find(edge[i].first)) != (v = Find(edge[i].second)))
      adj[u].push_back(v), adj[v].push_back(u);
  memset(bo, false, sizeof bo), memset(h, 0, sizeof h), dfs_all(), cin >> k;
  while (k--) query();
  return 0;
}
