#include <bits/stdc++.h>
using namespace std;
int deg[2005], g[2005][2005], p[2005], st[2005], en[2005], lowp[2005],
    arti[2005];
bool bridge[2005][2005], bi[2005], articup[2005], gr[2005][2005];
int temp[2005];
int t, n, cnt, o;
void articu(int i) {
  t++;
  st[i] = t;
  lowp[i] = t;
  bi[i] = 1;
  int a, b, c, d;
  for (a = 0; a < deg[i]; a++) {
    if (!bi[g[i][a]]) {
      p[g[i][a]] = i;
      articu(g[i][a]);
    }
  }
  for (a = 0; a < deg[i]; a++) {
    b = g[i][a];
    if (p[i] == b) continue;
    lowp[i] = min(lowp[i], lowp[b]);
    if (p[b] == i && lowp[b] >= st[i])
      if (!articup[i]) {
        arti[cnt] = i;
        cnt++;
      }
  }
  t++;
  en[i] = t;
}
void dfs(int i) {
  bi[i] = 1;
  int a, b;
  for (a = 0; a < deg[i]; a++) {
    b = g[i][a];
    if (bi[b]) continue;
    if (bridge[b][i])
      temp[b] = temp[i] + 1;
    else
      temp[b] = temp[i];
    dfs(b);
  }
}
int main() {
  int a, b, c, d, e, x, y, z, m;
  scanf("%d %d", &n, &m);
  for (a = 1; a <= m; a++) {
    scanf("%d %d", &x, &y);
    g[x][deg[x]] = y;
    g[y][deg[y]] = x;
    gr[x][y] = 1;
    gr[y][x] = 1;
    deg[x]++;
    deg[y]++;
  }
  t = 0;
  cnt = 0;
  articu(1);
  bool tr;
  for (a = 1; a <= n; a++) {
    for (b = 0; b < deg[a]; b++) {
      c = g[a][b];
      if (p[a] == c) continue;
      if (p[c] != a) continue;
      tr = false;
      for (d = 0; d < deg[c]; d++) {
        e = g[c][d];
        if (p[c] == e) continue;
        if (lowp[e] <= st[a]) tr = true;
      }
      if (tr == false) {
        bridge[a][c] = 1;
        bridge[c][a] = 1;
      }
    }
  }
  scanf("%d", &z);
  while (z--) {
    scanf("%d %d", &b, &c);
    for (a = 0; a <= n; a++) {
      bi[a] = 0;
      temp[a] = 0;
    }
    dfs(b);
    printf("%d\n", temp[c]);
  }
  return 0;
}
