#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 5;
const int inf = 1 << 30;
bool used[maxn];
vector<int> A[maxn], C[maxn], Cc[maxn], G[maxn];
int D[maxn];
int Q[maxn];
int tin[maxn], fup[maxn];
int Ind[maxn];
int n;
int tm = 0;
void dfs(int v, int p = -1) {
  used[v] = 1;
  tin[v] = fup[v] = tm++;
  for (int i = ((int)(A[v]).size()) - 1; i >= 0; --i) {
    int u = A[v][i];
    if (u == p) {
      continue;
    }
    if (!used[u]) {
      dfs(u, v);
      fup[v] = min(fup[v], fup[u]);
      if (fup[u] > tin[v]) {
        C[v][i] = C[u][Cc[v][i]] = 0;
      }
    } else {
      fup[v] = min(fup[v], tin[u]);
    }
  }
}
void dfs2(int v, int ind) {
  used[v] = 1;
  Ind[v] = ind;
  for (int i = ((int)(A[v]).size()) - 1; i >= 0; --i) {
    int u = A[v][i];
    if (!used[u] && C[v][i]) {
      dfs2(u, ind);
    }
  }
}
int solve(int v, int f) {
  memset(used, 0, sizeof(used));
  D[v] = 0;
  int l = 0, r = 0;
  Q[l] = v;
  used[v] = 1;
  while (l <= r) {
    int v = Q[l++];
    if (v == f) {
      break;
    }
    for (int i = ((int)(G[v]).size()) - 1; i >= 0; --i) {
      int u = G[v][i];
      if (!used[u]) {
        used[u] = 1;
        D[u] = D[v] + 1;
        Q[++r] = u;
      }
    }
  }
  return D[f];
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    --v, --u;
    A[v].push_back(u);
    A[u].push_back(v);
    Cc[v].push_back(((int)(C[u]).size()));
    Cc[u].push_back(((int)(C[v]).size()));
    C[v].push_back(1);
    C[u].push_back(1);
  }
  for (int i = 0; i < n; ++i) {
    if (!used[i]) {
      dfs(i);
    }
  }
  memset(used, 0, sizeof(used));
  int N = 0;
  for (int i = 0; i < n; ++i) {
    if (!used[i]) {
      dfs2(i, N++);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = ((int)(A[i]).size()) - 1; j >= 0; --j) {
      if (!C[i][j]) {
        G[Ind[i]].push_back(Ind[A[i][j]]);
      }
    }
  }
  n = N;
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    int v, u;
    scanf("%d%d", &v, &u);
    --v, --u;
    printf("%d\n", solve(Ind[v], Ind[u]));
  }
  return 0;
}
