#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> adj[N], gfo[N];
int n, num[N], low[N], comp[N], glob, c;
stack<int> S;
bool vst[N];
void tarjan(int u, int pa) {
  num[u] = low[u] = glob++;
  vst[u] = true;
  S.push(u);
  for (int v : adj[u])
    if (v != pa) {
      if (num[v] == -1) tarjan(v, u);
      if (vst[v]) low[u] = min(low[u], low[v]);
    }
  if (num[u] == low[u]) {
    while (true) {
      int v = S.top();
      S.pop();
      vst[v] = false;
      comp[v] = c;
      if (u == v) break;
    }
    c++;
  }
}
void buildgfo() {
  for (int u = int(0); u < int(n); ++u)
    for (int v : adj[u])
      if (comp[u] != comp[v]) {
        gfo[comp[u]].push_back(comp[v]), gfo[comp[v]].push_back(comp[u]);
      }
  for (int u = int(0); u < int(n); ++u) sort((gfo[u]).begin(), (gfo[u]).end());
  for (int u = int(0); u < int(n); ++u)
    gfo[u].resize(unique((gfo[u]).begin(), (gfo[u]).end()) - gfo[u].begin());
}
int t[2 * N];
void build() {
  for (int i = int(n - 1); i >= int(1); i--) t[i] = t[i << 1] + t[i << 1 | 1];
}
int query(int l, int r) {
  int ans = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans += t[l++];
    if (r & 1) ans += t[--r];
  }
  return ans;
}
int id[N], rt[N], p[N], tsz[N], d[N], gid;
int makesz(int u, int pa, int de) {
  tsz[u] = 1, d[u] = de, p[u] = pa;
  for (int v : gfo[u])
    if (v != pa) tsz[u] += makesz(v, u, de + 1);
  return tsz[u];
}
void dfs(int u, int root) {
  rt[u] = root, id[u] = gid++;
  int mx = -1, big = -1;
  for (int v : gfo[u])
    if (v != p[u] && tsz[v] > mx) mx = tsz[v], big = v;
  if (big != -1) dfs(big, root);
  for (int v : gfo[u])
    if (v != p[u] && v != big) dfs(v, v);
}
void hldinit() {
  gid = 0;
  makesz(0, -1, 0);
  dfs(0, 0);
  for (int i = int(n); i < int(2 * n); ++i) t[i] = 1;
  build();
}
int hldquery(int u, int v) {
  int ans = 0;
  while (rt[u] != rt[v]) {
    if (d[rt[u]] > d[rt[v]]) swap(u, v);
    ans += query(id[rt[v]], id[v] + 1);
    v = p[rt[v]];
  }
  if (id[u] > id[v]) swap(u, v);
  ans += query(id[u] + 1, id[v] + 1);
  return ans;
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = int(0); i < int(m); ++i) {
    int k1, k2;
    scanf("%d%d", &k1, &k2);
    k1--, k2--;
    adj[k1].push_back(k2);
    adj[k2].push_back(k1);
  }
  glob = c = 0;
  memset(num, -1, sizeof(num));
  memset(low, -1, sizeof(low));
  memset(vst, false, sizeof(vst));
  tarjan(0, -1);
  buildgfo();
  n = c;
  hldinit();
  int q;
  scanf("%d", &q);
  while (q--) {
    int k1, k2;
    scanf("%d%d", &k1, &k2);
    k1--, k2--;
    printf("%d\n", hldquery(comp[k1], comp[k2]));
  }
  return 0;
}
