#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> adj;
vector<vector<long long>> tree;
long long id;
long long SCC_Count;
vector<long long> dfs_num, dfs_low, on_stack, comp;
stack<long long> stk;
void tarjan(long long u, long long p) {
  dfs_num[u] = dfs_low[u] = ++id;
  stk.push(u);
  on_stack[u] = 1;
  for (auto v : adj[u]) {
    if (!dfs_num[v]) {
      tarjan(v, u);
      dfs_low[u] = min(dfs_low[u], dfs_low[v]);
    } else if (v != p && on_stack[v]) {
      dfs_low[u] = min(dfs_low[u], dfs_low[v]);
    }
  }
  if (dfs_num[u] == dfs_low[u]) {
    long long v;
    do {
      v = stk.top();
      stk.pop();
      on_stack[v] = 0;
      comp[v] = SCC_Count;
    } while (u != v);
    SCC_Count++;
  }
}
struct LCA {
  long long n, logn;
  vector<long long> lev;
  vector<vector<long long>> par;
  vector<vector<long long>>& adj;
  LCA(long long root, vector<vector<long long>>& adj)
      : n(adj.size()), logn((31 ^ __builtin_clz(n))), adj(adj) {
    lev.resize(n);
    par.resize(n, vector<long long>(logn + 1, -1));
    dfs(root, root, 0);
  }
  void dfs(long long u, long long p, long long d) {
    lev[u] = d;
    par[u][0] = p;
    for (long long j = 1; 1 << j < n; j++)
      if (par[u][j - 1] != -1) par[u][j] = par[par[u][j - 1]][j - 1];
    for (auto v : adj[u])
      if (v && !lev[v]) dfs(v, u, d + 1);
  }
  long long get(long long u, long long v) {
    if (lev[u] < lev[v]) swap(u, v);
    long long lg = logn;
    long long diff = lev[u] - lev[v];
    for (long long i = lg; i >= 0; i--)
      if (diff & 1 << i) u = par[u][i];
    if (u == v) return u;
    for (long long i = lg; i >= 0; i--)
      if (par[u][i] != -1 && par[u][i] != par[v][i])
        u = par[u][i], v = par[v][i];
    return par[u][0];
  }
};
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  long long m;
  cin >> m;
  adj.resize(n);
  dfs_num.resize(n);
  dfs_low.resize(n);
  on_stack.resize(n);
  comp.resize(n);
  for (long long i = 0; i < m; i++) {
    long long u;
    cin >> u;
    u--;
    long long v;
    cin >> v;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  tarjan(0, 0);
  tree.resize(SCC_Count);
  for (long long u = 0; u < n; u++) {
    for (auto v : adj[u]) {
      long long a = comp[u];
      long long b = comp[v];
      if (a != b) {
        tree[b].push_back(a);
        tree[a].push_back(b);
      }
    }
  }
  LCA lca(0, tree);
  long long k;
  cin >> k;
  for (long long i = 0; i < k; i++) {
    long long u;
    cin >> u;
    u--;
    long long v;
    cin >> v;
    v--;
    u = comp[u];
    v = comp[v];
    long long w = lca.get(u, v);
    cout << lca.lev[u] + lca.lev[v] - 2 * lca.lev[w] << endl;
  }
}
