#include <bits/stdc++.h>
int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};
using namespace std;
template <class T>
T sq(T n) {
  return n * n;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
bool inside(T a, T b, T c) {
  return a <= b && b <= c;
}
template <class T>
void setmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
vector<int> G[100100];
char clr[100100];
int L[100100];
int T[100100];
int comp[100100];
int P[100100][50];
vector<int> GT[100100];
void process(int n) {
  int i, j;
  for (i = 0; i < n; i++)
    for (j = 0; 1 << j < n; j++) P[i][j] = -1;
  for (i = 0; i < n; i++) P[i][0] = T[i];
  for (j = 1; 1 << j < n; j++)
    for (i = 0; i < n; i++)
      if (P[i][j - 1] != -1) P[i][j] = P[P[i][j - 1]][j - 1];
}
stack<pair<int, int> > S;
int dfstime;
int low[100100], vis[100100], used[100100];
int nt;
void dfs1(int u, int par) {
  int v, i, sz = G[u].size();
  pair<int, int> e, curr;
  used[u] = 1;
  vis[u] = low[u] = ++dfstime;
  for (i = 0; i < sz; i++) {
    v = G[u][i];
    if (v == par) continue;
    if (!used[v]) {
      S.push(pair<int, int>(u, v));
      dfs1(v, u);
      if (low[v] >= vis[u]) {
        curr = pair<int, int>(u, v);
        vector<int> tmp;
        do {
          e = S.top();
          S.pop();
          tmp.push_back(e.first);
          tmp.push_back(e.second);
        } while (e != curr);
        if (((int)tmp.size()) == 2) {
        } else {
          int val = -1, j;
          for (j = 0; j < ((int)tmp.size()); j++) {
            if (comp[tmp[j]] != -1) {
              val = comp[tmp[j]];
              break;
            }
          }
          if (val == -1) val = nt++;
          for (j = 0; j < ((int)tmp.size()); j++) comp[tmp[j]] = val;
        }
      }
      low[u] = min(low[u], low[v]);
    } else if (vis[v] < vis[u]) {
      S.push(pair<int, int>(u, v));
      low[u] = min(low[u], vis[v]);
    }
  }
}
int 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];
}
void dfs(int u) {
  clr[u] = 1;
  int i, v;
  for (i = 0; i < ((int)GT[u].size()); i++) {
    v = GT[u][i];
    if (clr[v]) continue;
    T[v] = u;
    L[v] = L[u] + 1;
    dfs(v);
  }
}
int main() {
  int n, m, i, j, k, u, v, x, y;
  scanf("%d", &n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &i);
    scanf("%d", &j);
    i--;
    j--;
    G[i].push_back(j);
    G[j].push_back(i);
  }
  memset(comp, -1, sizeof(comp));
  nt = 0;
  dfs1(0, -1);
  for (u = 0; u < n; u++) {
    for (i = 0; i < ((int)G[u].size()); i++) {
      v = G[u][i];
      if (comp[u] == -1)
        x = comp[u] = nt++;
      else
        x = comp[u];
      if (comp[v] == -1)
        y = comp[v] = nt++;
      else
        y = comp[v];
      if (x != y) {
        GT[x].push_back(y);
      }
    }
  }
  T[0] = 0;
  L[0] = 0;
  dfs(0);
  process(nt);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &i);
    scanf("%d", &j);
    i--;
    j--;
    i = comp[i];
    j = comp[j];
    k = lca(i, j);
    int ans = L[i] + L[j] - 2 * L[k];
    printf("%d\n", ans);
  }
  return 0;
}
