#include <bits/stdc++.h>
using namespace std;
int n, m, k, a, b, counter, idx, dfs_num[100005], dfs_low[100005],
    dfs_parent[100005], component[100005], SpT[200005][20], E[200005],
    H[200005], L[200005];
set<pair<int, int>> bridges;
vector<vector<int>> adjList, tree;
void findBridges(int u) {
  dfs_low[u] = dfs_num[u] = counter++;
  for (int i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if (!dfs_num[v]) {
      dfs_parent[v] = u;
      findBridges(v);
      if (dfs_low[v] > dfs_num[u]) {
        bridges.insert(make_pair(min(u, v), max(u, v)));
      }
      dfs_low[u] = min(dfs_low[u], dfs_low[v]);
    } else if (v != dfs_parent[u]) {
      dfs_low[u] = min(dfs_low[u], dfs_num[v]);
    }
  }
}
void makeTree(int u) {
  dfs_num[u] = 1;
  component[u] = counter;
  for (int i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if (!dfs_num[v]) {
      pair<int, int> edge = make_pair(min(u, v), max(u, v));
      if (!bridges.count(edge)) {
        makeTree(v);
      }
    }
  }
}
void dfs(int u, int depth, int p) {
  H[u] = idx;
  E[idx] = u;
  L[idx++] = depth;
  for (int i = 0; i < tree[u].size(); i++) {
    int v = tree[u][i];
    if (v != p) {
      dfs(v, depth + 1, u);
      E[idx] = u;
      L[idx++] = depth;
    }
  }
}
void build() {
  for (int i = 0; i < idx; i++) {
    SpT[i][0] = i;
  }
  for (int j = 1; (1 << j) <= idx; j++) {
    for (int i = 0; i + (1 << j) - 1 < idx; i++) {
      if (L[SpT[i][j - 1]] < L[SpT[i + (1 << (j - 1))][j - 1]]) {
        SpT[i][j] = SpT[i][j - 1];
      } else {
        SpT[i][j] = SpT[i + (1 << (j - 1))][j - 1];
      }
    }
  }
}
int query(int i, int j) {
  if (H[i] > H[j]) {
    swap(i, j);
  }
  int k = log2(H[j] - H[i] + 1), q;
  if (L[SpT[H[i]][k]] <= L[SpT[H[j] - (1 << k) + 1][k]]) {
    q = SpT[H[i]][k];
  } else {
    q = SpT[H[j] - (1 << k) + 1][k];
  }
  int LCA = E[q];
  return abs(L[H[i]] - L[H[LCA]]) + abs(L[H[j]] - L[H[LCA]]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  adjList.resize(n);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    adjList[a].push_back(b);
    adjList[b].push_back(a);
  }
  counter = 1;
  findBridges(0);
  for (int i = 0; i < n; i++) {
    dfs_num[i] = 0;
  }
  counter = 0;
  for (int i = 0; i < n; i++) {
    if (!dfs_num[i]) {
      makeTree(i);
      counter++;
    }
  }
  tree.resize(counter);
  for (auto it = bridges.begin(); it != bridges.end(); it++) {
    pair<int, int> edges = *it;
    tree[component[edges.first]].push_back(component[edges.second]);
    tree[component[edges.second]].push_back(component[edges.first]);
  }
  dfs(0, 0, -1);
  build();
  cin >> k;
  while (k--) {
    cin >> a >> b;
    cout << query(component[a - 1], component[b - 1]) << '\n';
  }
  return 0;
}
