#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T a) {
  return a < 0 ? -a : a;
}
template <typename T>
T sqr(T a) {
  return a * a;
}
const int INF = (int)1e9;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
const int N = 100500;
int n, m;
vector<int> g[N];
int pr[N], h[N];
int minH[N];
void dfs(int v) {
  minH[v] = h[v];
  for (int i = 0; i < int(int((g[v]).size())); ++i) {
    int u = g[v][i];
    if (u == pr[v]) continue;
    if (h[u] != -1) {
      minH[v] = min(minH[v], h[u]);
      continue;
    }
    pr[u] = v;
    h[u] = h[v] + 1;
    dfs(u);
    minH[v] = min(minH[v], minH[u]);
  }
}
int a[N][20];
int cnt[N];
int timer;
int tIn[N], tOut[N];
void dfs2(int v, int cm) {
  tIn[v] = timer++;
  cnt[v] = cm;
  a[v][0] = pr[v];
  for (int i = 1; i < 20; ++i) a[v][i] = a[a[v][i - 1]][i - 1];
  for (int i = 0; i < int(int((g[v]).size())); ++i) {
    int u = g[v][i];
    if (pr[u] != v) continue;
    dfs2(u, cm + ((minH[u] > h[v]) ? 1 : 0));
  }
  tOut[v] = timer++;
}
inline bool isChild(int pr, int ch) {
  return tIn[pr] <= tIn[ch] && tOut[ch] <= tOut[pr];
}
inline int lca(int v, int u) {
  if (isChild(v, u)) return v;
  if (isChild(u, v)) return u;
  for (int i = 19; i >= 0; --i)
    if (!isChild(a[v][i], u)) v = a[v][i];
  return a[v][0];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < int(m); ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  memset(h, -1, sizeof(h));
  memset(minH, -1, sizeof(h));
  h[0] = 0;
  minH[0] = 0;
  dfs(0);
  dfs2(0, 0);
  int q;
  cin >> q;
  for (int cq = 0; cq < int(q); ++cq) {
    int v, u;
    scanf("%d %d", &v, &u);
    v--;
    u--;
    int mid = lca(v, u);
    printf("%d\n", cnt[v] + cnt[u] - 2 * cnt[mid]);
  }
  return 0;
}
