#include <bits/stdc++.h>
using namespace std;
int n, m, k, trav;
int fpar[100000];
int prevu[100000];
int place[100000];
vector<int> conecc[100000];
bool check[100000];
int in[100000];
int out[100000];
int tol[100000];
vector<int> st[100000];
int par(int i) {
  while (fpar[i] != fpar[fpar[i]]) fpar[i] = fpar[fpar[i]];
  return fpar[i];
}
void loopdfs(int i) {
  in[i] = ++trav;
  check[i] = true;
  for (int u : conecc[i]) {
    if (u != prevu[i]) {
      if (check[u]) {
        int v = par(i);
        fpar[u] = par(u);
        while (v != fpar[u]) {
          fpar[v] = fpar[u];
          v = par(prevu[v]);
        }
      } else {
        st[u][0] = i;
        prevu[u] = i;
        loopdfs(u);
      }
    }
  }
  out[i] = ++trav;
}
bool ispar(int a, int b) {
  if (a == -1) return true;
  return in[a] <= in[b] && out[a] >= out[b];
}
int lca(int a, int b) {
  int ans = 0;
  if (!ispar(a, b)) {
    for (int i = 17; i >= 0; i--) {
      if (!ispar(st[a][i], b)) {
        a = st[a][i];
        ans += pow(2, i);
      }
    }
    a = st[a][0];
    ans++;
  }
  if (!ispar(b, a)) {
    for (int i = 17; i >= 0; i--) {
      if (!ispar(st[b][i], a)) {
        b = st[b][i];
        ans += pow(2, i);
      }
    }
    ans++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  trav = 0;
  for (int i = 0; i < n; i++) {
    fpar[i] = i;
    prevu[i] = -1;
    place[i] = -1;
    check[i] = false;
  }
  for (int i = 0; i < m; i++) {
    int a;
    int b;
    cin >> a >> b;
    a--;
    b--;
    conecc[b].push_back(a);
    conecc[a].push_back(b);
  }
  for (int i = 0; i < n; i++) st[i].resize(18, -1);
  st[0][0] = -1;
  loopdfs(0);
  for (int i = 0; i < n; i++) {
    fpar[i] = par(i);
    if (st[i][0] != -1) st[i][0] = par(st[i][0]);
  }
  int j = 0;
  bool yeet = true;
  while (yeet) {
    yeet = false;
    for (int i = 0; i < n; i++) {
      if (fpar[i] == i) {
        if (st[i][j] != -1) {
          yeet = true;
          st[i][j + 1] = st[st[i][j]][j];
        }
      }
    }
    j++;
  }
  cin >> k;
  while (k--) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    a = fpar[a];
    b = fpar[b];
    cout << lca(a, b) << '\n';
  }
}
