#include <bits/stdc++.h>
using namespace std;
int low[100005], disc[100005], parent[100005], ctr = 0;
int T[100005], L[100005], P[100005][30];
bool visited[100005];
vector<int> adjList[100005];
vector<int> adjList2[100005];
set<pair<int, int> > bridge;
set<pair<int, int> >::iterator it;
int pos[100005];
int n, m, a, b;
int sccCounter = 0;
stack<int> Stack;
int ancestor;
int k, s, l;
void bridgeUtil(int u) {
  visited[u] = true;
  disc[u] = low[u] = ++ctr;
  for (int i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if (!visited[v]) {
      parent[v] = u;
      bridgeUtil(v);
      low[u] = min(low[u], low[v]);
      if (low[v] > disc[u])
        if (u < v)
          bridge.insert(make_pair(u, v));
        else
          bridge.insert(make_pair(v, u));
    } else if (v != parent[u])
      low[u] = min(low[u], disc[v]);
  }
}
bool getBridge(int u, int v) {
  if (u < v)
    it = bridge.find(make_pair(u, v));
  else
    it = bridge.find(make_pair(v, u));
  if (it != bridge.end()) return true;
  return false;
}
void dfs1(int v) {
  visited[v] = true;
  for (int i = 0; i < adjList[v].size(); i++) {
    if (!visited[adjList[v][i]] && !getBridge(v, adjList[v][i]))
      dfs1(adjList[v][i]);
  }
  Stack.push(v);
}
void dfs2(int v) {
  pos[v] = sccCounter;
  visited[v] = true;
  for (int i = 0; i < adjList[v].size(); i++) {
    if (!visited[adjList[v][i]] && !getBridge(v, adjList[v][i]))
      dfs2(adjList[v][i]);
  }
}
void shrink_scc() {
  int u, v;
  for (int i = 1; i <= n; i++) adjList2[i].clear();
  for (int i = 1; i <= n; i++) {
    u = i;
    for (int j = 0; j < adjList[i].size(); j++) {
      v = adjList[i][j];
      if (pos[u] != pos[v]) adjList2[pos[u]].push_back(pos[v]);
    }
  }
}
void dfs(int v) {
  visited[v] = true;
  for (int i = 0; i < adjList2[v].size(); i++) {
    if (!visited[adjList2[v][i]]) {
      L[adjList2[v][i]] = L[v] + 1;
      T[adjList2[v][i]] = v;
      dfs(adjList2[v][i]);
    }
  }
}
int find_lca(int p, int q) {
  int tmp, log, i;
  if (L[p] < L[q]) tmp = p, p = q, q = tmp;
  for (log = 1; 1 << log <= L[p]; log++)
    ;
  log--;
  for (i = log; i >= 0; i--)
    if (L[p] - (1 << i) >= L[q]) p = P[p][i];
  if (p == q) return p;
  for (i = log; i >= 0; i--)
    if (P[p][i] != -1 && P[p][i] != P[q][i]) p = P[p][i], q = P[q][i];
  return T[p];
}
int main() {
  for (int i = 0; i < 100005; i++) adjList[i].clear();
  memset(low, -1, sizeof(low));
  memset(disc, -1, sizeof(disc));
  memset(parent, -1, sizeof(parent));
  memset(visited, false, sizeof(visited));
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    adjList[a].push_back(b);
    adjList[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    if (!visited[i]) bridgeUtil(i);
  while (!Stack.empty()) Stack.pop();
  memset(visited, false, sizeof(visited));
  for (int i = 1; i <= n; i++)
    if (!visited[i]) dfs1(i);
  memset(visited, false, sizeof(visited));
  while (!Stack.empty()) {
    int v = Stack.top();
    Stack.pop();
    if (!visited[v]) {
      dfs2(v);
      sccCounter++;
    }
  }
  shrink_scc();
  memset(visited, false, sizeof(visited));
  memset(T, 0, sizeof(T));
  memset(P, -1, sizeof(P));
  memset(L, -1, sizeof(-1));
  L[0] = 0;
  dfs(0);
  for (int i = 0; i < sccCounter; i++) P[i][0] = T[i];
  for (int j = 1; 1 << j < sccCounter; j++) {
    for (int i = 0; i < sccCounter; i++)
      if (P[i][j - 1] != -1) P[i][j] = P[P[i][j - 1]][j - 1];
  }
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &s, &l);
    ancestor = find_lca(pos[s], pos[l]);
    printf("%d\n", L[pos[s]] + L[pos[l]] - 2 * L[ancestor]);
  }
  return 0;
}
