#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
template <class T>
bool get_max(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
bool get_min(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
const int maxn = 100000 + 5;
vector<int> adj[maxn], tree[maxn];
int n, m, q, ans[maxn], low[maxn], dfn[maxn], Time;
int st[maxn];
set<pair<int, int> > bridge;
bool check[maxn];
struct Q {
  int node, id;
  Q() {}
  Q(int _node, int _id) : node(_node), id(_id) {}
};
vector<Q> query[maxn];
void dfs(int u, int fa) {
  dfn[u] = low[u] = ++Time;
  for (int i = 0; i < (int)adj[u].size(); i++) {
    int v = adj[u][i];
    if (!dfn[v]) {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] > dfn[u]) {
        bridge.insert(make_pair(u, v));
        bridge.insert(make_pair(v, u));
      }
    } else if (v != fa) {
      low[u] = min(low[u], dfn[v]);
    }
  }
}
void floodfill(int u) {
  dfn[u] = Time;
  for (int i = 0; i < (int)adj[u].size(); i++) {
    int v = adj[u][i];
    if (!dfn[v]) {
      if (!bridge.count(make_pair(u, v))) {
        floodfill(v);
      }
    }
  }
}
int find(int x) {
  if (x == st[x]) return x;
  return st[x] = find(st[x]);
}
void solve(int u, int dep) {
  dfn[u] = dep;
  st[u] = u;
  for (int i = 0; i < (int)tree[u].size(); i++) {
    int v = tree[u][i];
    if (!dfn[v]) {
      solve(v, dep + 1);
      st[v] = u;
    }
  }
  check[u] = true;
  for (int i = 0; i < (int)query[u].size(); i++) {
    int v = query[u][i].node;
    int id = query[u][i].id;
    if (check[v]) {
      int lca = find(v);
      ans[id] = dfn[v] - dfn[lca] + dfn[u] - dfn[lca];
    }
  }
}
int main() {
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 1; i <= n; i++) {
      adj[i].clear();
      tree[i].clear();
      query[i].clear();
    }
    for (int i = 1; i <= m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    bridge.clear();
    Time = 0;
    dfs(1, 0);
    memset(dfn, 0, sizeof(dfn));
    Time = 0;
    for (int i = 1; i <= n; i++) {
      if (!dfn[i]) {
        ++Time;
        floodfill(i);
      }
    }
    for (int i = 1; i <= n; i++) {
      int u = i;
      for (int j = 0; j < (int)adj[i].size(); j++) {
        int v = adj[i][j];
        if (dfn[u] != dfn[v]) {
          tree[dfn[u]].push_back(dfn[v]);
        }
      }
    }
    scanf("%d", &q);
    for (int i = 1; i <= q; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      query[dfn[u]].push_back(Q(dfn[v], i));
      query[dfn[v]].push_back(Q(dfn[u], i));
    }
    memset(dfn, 0, sizeof(dfn));
    memset(check, false, sizeof(check));
    solve(1, 1);
    for (int i = 1; i <= q; i++) {
      printf("%d\n", ans[i]);
    }
  }
  return 0;
}
