#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int N = 100100;
int num[N], low[N], link_[N], head[N], adj[N], parent[N];
bool avail[N], isBridge[N];
int number, n, m, ed, u[N], v[N], l[N], h[N], a[N], lab[N], e;
int depth[N], p[N][16], k;
void dfs(int u) {
  num[u] = ++number;
  low[u] = INF;
  int i = head[u], v;
  while (i) {
    if (avail[i]) {
      if (i & 1)
        avail[i + 1] = false;
      else
        avail[i - 1] = false;
      v = adj[i];
      if (!num[v]) {
        parent[v] = u;
        dfs(v);
        low[u] = min(low[u], low[v]);
      } else
        low[u] = min(num[v], low[u]);
    }
    i = link_[i];
  }
}
void visit(int u) {
  num[u] = number;
  int i = head[u];
  while (i) {
    if (!isBridge[i] && !num[adj[i]]) visit(adj[i]);
    i = link_[i];
  }
}
void add(int u, int v) {
  link_[++ed] = head[u];
  head[u] = ed;
  adj[ed] = v;
}
void DFSvisit(int u) {
  int i = h[u], v;
  while (i) {
    v = a[i];
    if (!parent[v]) {
      parent[v] = u;
      p[v][0] = u;
      depth[v] = depth[u] + 1;
      DFSvisit(v);
    }
    i = l[i];
  }
}
int move(int u, int rr) {
  int i = 0;
  while (rr > 0) {
    if (rr & 1) u = p[u][i];
    i++;
    rr /= 2;
  }
  return u;
}
int LCA(int u, int v) {
  if (depth[u] > depth[v]) u = move(u, depth[u] - depth[v]);
  if (depth[v] > depth[u]) v = move(v, depth[v] - depth[u]);
  if (u == v) return u;
  for (int i = 15; i >= 0; i--) {
    if (p[u][i] != p[v][i]) {
      u = p[u][i];
      v = p[v][i];
    }
  }
  return p[u][0];
}
int findset(int u) {
  if (lab[u] <= 0) return u;
  lab[u] = findset(lab[u]);
  return lab[u];
}
void union_(int r, int w) {
  if (lab[r] > lab[w])
    lab[r] = w;
  else {
    if (lab[r] == lab[w]) lab[r]--;
    lab[w] = r;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> u[i] >> v[i];
    add(u[i], v[i]);
    add(v[i], u[i]);
  }
  memset(avail, true, sizeof(avail));
  for (int i = 1; i <= n; i++)
    if (parent[i] == 0) {
      parent[i] = -1;
      dfs(i);
    }
  for (int i = 1; i <= n; i++) {
    int v = parent[i];
    if (v != -1 && low[i] >= num[i]) {
      int ii = head[v];
      while (ii) {
        if (adj[ii] == i) {
          isBridge[ii] = true;
          if (ii & 1)
            isBridge[ii + 1] = true;
          else
            isBridge[ii - 1] = true;
          break;
        }
        ii = link_[ii];
      }
    }
  }
  memset(num, 0, sizeof(num));
  number = 0;
  for (int i = 1; i <= n; i++)
    if (!num[i]) {
      number++;
      visit(i);
    }
  int q, w;
  for (int i = 1; i <= m; i++) {
    q = findset(num[u[i]]);
    w = findset(num[v[i]]);
    if (q != w) {
      l[++e] = h[num[u[i]]];
      h[num[u[i]]] = e;
      a[e] = num[v[i]];
      l[++e] = h[num[v[i]]];
      h[num[v[i]]] = e;
      a[e] = num[u[i]];
      union_(q, w);
    }
  }
  int i = h[1];
  memset(parent, 0, sizeof(parent));
  for (int i = 1; i <= n; i++)
    if (!parent[i]) {
      parent[i] = -1;
      DFSvisit(i);
    }
  for (int ii = 1; ii <= 15; ii++)
    for (int i = 1; i <= n; i++) p[i][ii] = p[p[i][ii - 1]][ii - 1];
  cin >> k;
  int r, t, rr, tt;
  for (int i = 1; i <= k; i++) {
    cin >> r >> t;
    r = num[r];
    t = num[t];
    rr = findset(r);
    tt = findset(t);
    if (rr != tt) {
      cout << 0 << endl;
      continue;
    }
    rr = LCA(r, t);
    cout << depth[r] - 2 * depth[rr] + depth[t] << endl;
  }
}
