#include <bits/stdc++.h>
using namespace std;
vector<int> E[100005];
int n, m, q;
int low[100005], dfsn[100005], timer;
int ponte[100005];
int p[18][100005];
int h[100005];
void dfsbcc(int u, int pa = -1, int alt = 0) {
  p[0][u] = pa;
  h[u] = alt;
  low[u] = dfsn[u] = ++timer;
  for (typeof E[u].begin() v = E[u].begin(); v != E[u].end(); v++) {
    if (dfsn[*v] == 0) {
      dfsbcc(*v, u, alt + 1);
      low[u] = min(low[u], low[*v]);
      if (low[*v] == dfsn[*v]) ponte[*v] = 1;
    } else if (*v != pa && dfsn[*v] < dfsn[u]) {
      low[u] = min(low[u], dfsn[*v]);
    }
  }
}
void bcc() {
  for (int i = 0; i < n; i++) dfsn[i] = ponte[i] = 0;
  timer = 0;
  for (int i = 0; i < n; i++)
    if (dfsn[i] == 0) dfsbcc(i);
}
void makep() {
  for (int i = 1; i < 18; i++)
    for (int j = 0; j < n; j++) p[i][j] = p[i - 1][p[i - 1][j]];
}
int padre(int u, int k) {
  for (int t = 0; k; t++, k >>= 1)
    if (k & 1) u = p[t][u];
  return u;
}
int lca(int u, int v) {
  int dif = h[u] - h[v];
  if (dif < 0) swap(u, v), dif = -dif;
  u = padre(u, dif);
  if (u == v) return u;
  while (p[0][u] != p[0][v]) {
    int k = 1;
    while (p[k][u] != p[k][v]) k++;
    u = p[k - 1][u];
    v = p[k - 1][v];
  }
  return p[0][u];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  bcc();
  makep();
  cin >> q;
  for (int i = 0; i < q; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    int w = lca(u, v);
    int res = 0;
    for (; u != w; u = p[0][u])
      if (ponte[u]) res++;
    for (; v != w; v = p[0][v])
      if (ponte[v]) res++;
    cout << res << endl;
  }
}
