#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[2010];
int d[2010], l[2010], TIM, x, y;
char color[2010];
vector<pair<int, int> > critical;
void bridge(int node, int parent) {
  int len = G[node].size(), i, p;
  l[node] = d[node] = TIM++;
  color[node] = 1;
  for (i = 0; i < len; i++) {
    p = G[node][i];
    if (color[p] == 0) {
      bridge(p, node);
      if (l[p] > d[node]) {
        if (p < node) {
          x = p;
          y = node;
        } else {
          y = p;
          x = node;
        }
        critical.push_back(make_pair(x, y));
      }
      if (l[node] > l[p]) l[node] = l[p];
    } else if (color[p] == 1 && parent != p && l[node] > d[p])
      l[node] = d[p];
  }
  color[node] = 2;
}
char clr[2010];
int R[2010][2010][2];
int c, f, no;
void dfs(int u) {
  clr[u] = 1;
  R[c][u][f] = 1;
  int i, v;
  for (i = 0; i < ((int)G[u].size()); i++) {
    v = G[u][i];
    if (clr[v]) continue;
    if (v == no) continue;
    dfs(v);
  }
}
int main() {
  int n, T, t = 1, m, i, j, k;
  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);
  }
  for (i = 0; i < n; i++)
    if (color[i] == 0) {
      TIM = 0;
      bridge(i, 0);
    }
  sort(critical.begin(), critical.end());
  {}
  for (i = 0; i < ((int)critical.size()); i++) {
    no = critical[i].second;
    memset(clr, 0, sizeof(clr));
    f = 0;
    c = i;
    dfs(critical[i].first);
    no = critical[i].first;
    memset(clr, 0, sizeof(clr));
    f = 1;
    c = i;
    dfs(critical[i].second);
  }
  scanf("%d", &k);
  while (k--) {
    scanf("%d", &i);
    scanf("%d", &j);
    i--;
    j--;
    int ans = 0;
    for (c = 0; c < ((int)critical.size()); c++) {
      if (R[c][i][0] && R[c][j][1])
        ans++;
      else if (R[c][i][1] && R[c][j][0])
        ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
