#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> graf, sparseTable;
vector<int> lvl, height, first, low, postOrder;
vector<bool> odw, most;
int n, m, globId = 1;
void dfs(int x, int parent) {
  odw[x] = true;
  low[x] = postOrder[x] = globId++;
  for (vector<int>::iterator it = graf[x].begin(); it != graf[x].end(); it++) {
    if (!odw[*it]) {
      dfs(*it, x);
      low[x] = min(low[x], low[*it]);
    } else {
      if (*it != parent) {
        low[x] = min(low[x], postOrder[*it]);
      }
    }
  }
  if (parent != -1) {
    if (postOrder[x] == low[x]) most[x] = true;
  }
}
void lcaDfs(int x, int poziom) {
  odw[x] = true;
  first[x] = height.size();
  lvl[x] = poziom;
  height.push_back(poziom);
  for (vector<int>::iterator it = graf[x].begin(); it != graf[x].end(); it++) {
    if (!odw[*it]) {
      if (most[*it])
        lcaDfs(*it, poziom + 1);
      else
        lcaDfs(*it, poziom);
    }
    height.push_back(poziom);
  }
}
void preprocessLca() {
  sparseTable.resize(height.size(), vector<int>(25));
  for (int i = 0; i < sparseTable.size(); i++) sparseTable[i][0] = height[i];
  for (int j = 1; (1 << j) < height.size() - 1; j++) {
    for (int i = 0; (i + (1 << j) - 1) < height.size() - 1; i++) {
      sparseTable[i][j] =
          min(sparseTable[i][j - 1], sparseTable[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int lca(int a, int b) {
  a = first[a];
  b = first[b];
  if (a > b) swap(a, b);
  int len = b - a;
  int ln = log2(len);
  return min(sparseTable[a][ln], sparseTable[b - (1 << ln) + 1][ln]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  graf.resize(n + 1);
  odw.resize(n + 1);
  most.resize(n + 1);
  lvl.resize(n + 1);
  first.resize(n + 1);
  low.resize(n + 1);
  postOrder.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    graf[a].push_back(b);
    graf[b].push_back(a);
  }
  dfs(1, -1);
  odw.resize(0);
  odw.resize(n + 1);
  lcaDfs(1, 0);
  preprocessLca();
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    int j = lca(a, b);
    cout << lvl[a] + lvl[b] - 2 * j << endl;
  }
}
