#include <bits/stdc++.h>
using namespace std;
const int SIZE = 110000;
int G[2 * SIZE][3], p, P[SIZE];
bool B[SIZE];
int dfs_timer, Tin[SIZE], Fup[SIZE];
void dfs(int a, int prev = -1) {
  B[a] = true;
  Tin[a] = Fup[a] = dfs_timer++;
  int ind = G[a][1];
  while (G[ind][0]) {
    if (prev == G[ind][0])
      ;
    else if (B[G[ind][0]]) {
      if (Fup[a] > Tin[G[ind][0]]) Fup[a] = Tin[G[ind][0]];
    } else {
      dfs(G[ind][0], a);
      if (Fup[a] > Fup[G[ind][0]]) Fup[a] = Fup[G[ind][0]];
      if (Fup[G[ind][0]] > Tin[a]) {
        G[ind][2] = 1;
      }
    }
    ind = G[ind][1];
  }
}
int C[SIZE], kk = 1;
int G1[SIZE][2], p1, P1[SIZE];
void dfs1(int a, int k) {
  B[a] = true, C[a] = k;
  int ind = G[a][1];
  while (G[ind][0]) {
    if (!B[G[ind][0]]) {
      if (G[ind][2]) {
        kk++;
        G1[P1[k]][0] = kk, G1[P1[k]][1] = p1, P1[k] = p1++;
        G1[P1[kk]][0] = k, G1[P1[kk]][1] = p1, P1[kk] = p1++;
        dfs1(G[ind][0], kk);
      } else
        dfs1(G[ind][0], k);
    }
    ind = G[ind][1];
  }
}
int dfs2(int a, int c) {
  B[a] = true;
  int ind = G1[a][1], r;
  while (G1[ind][0]) {
    if (G1[ind][0] == c) {
      return 1;
    }
    if (!B[G1[ind][0]]) {
      r = dfs2(G1[ind][0], c);
      if (r) return r + 1;
    }
    ind = G1[ind][1];
  }
  return 0;
}
int main() {
  int N, M, K;
  cin >> N >> M;
  p = N + 1;
  int a, b;
  for (int i = 1; i != N + 1; i++) G[i][1] = p, P[i] = p++;
  while (M--) {
    cin >> a >> b;
    G[P[a]][0] = b, G[P[a]][1] = p, P[a] = p++;
    G[P[b]][0] = a, G[P[b]][1] = p, P[b] = p++;
  }
  dfs(1);
  for (int i = 0; i != SIZE; i++) B[i] = false;
  p1 = N + 1;
  for (int i = 1; i != N + 1; i++) G1[i][1] = p1, P1[i] = p1++;
  dfs1(1, 1);
  cin >> K;
  while (K--) {
    cin >> a >> b;
    for (int i = 0; i != kk; i++) B[i] = false;
    if (C[a] == C[b])
      cout << 0 << endl;
    else
      cout << dfs2(C[a], C[b]) << endl;
  }
  return 0;
}
