#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100004], addj[100004];
int pi[100004], ri[100004];
int find(int x) { return (x == pi[x]) ? x : pi[x] = find(pi[x]); }
void uni(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (ri[x] > ri[y])
    pi[y] = x;
  else {
    pi[x] = y;
    if (ri[x] == ri[y]) ++ri[y];
  }
}
int depth[100004] = {0}, low[100004];
int timer = 0;
void dfs(int x, int p) {
  depth[x] = low[x] = ++timer;
  int omar = adj[x].size();
  for (int i = 0; i < omar; ++i) {
    int to = adj[x][i];
    if (to == p) continue;
    if (depth[to] == 0) {
      dfs(to, x);
      low[x] = min(low[to], low[x]);
      if (low[to] <= depth[x]) uni(to, x);
    } else
      low[x] = min(low[x], depth[to]);
  }
}
int dist[100004], dp[100004][21] = {0};
void root(int x, int p) {
  int omar = addj[x].size();
  for (int i = 0; i < omar; ++i) {
    int to = addj[x][i];
    if (to == p || to == x) continue;
    dist[to] = dist[x] + 1;
    dp[to][0] = x;
    root(to, x);
  }
}
int mxlog = 0;
int n;
void bdp() {
  while ((1 << mxlog) <= n) ++mxlog;
  for (int j = 1; j < mxlog; ++j)
    for (int i = 1; i <= n; ++i) dp[i][j] = dp[dp[i][j - 1]][j - 1];
}
int lca(int x, int y) {
  if (dist[x] < dist[y]) return lca(y, x);
  int diff = dist[x] - dist[y];
  for (int i = 0; i < mxlog; ++i)
    if (((1 << i) & diff)) x = dp[x][i];
  if (x == y) return x;
  for (int i = mxlog - 1; i >= 0; --i)
    if (dp[x][i] != dp[y][i]) {
      x = dp[x][i];
      y = dp[y][i];
    }
  return dp[x][0];
}
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) pi[i] = i, ri[i] = 0;
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, -1);
  for (int i = 1; i <= n; ++i) {
    int omar = adj[i].size();
    int x = find(i);
    for (int j = 0; j < omar; ++j) {
      int y = find(adj[i][j]);
      if (x != y) {
        addj[x].push_back(y);
      }
    }
  }
  dist[find(1)] = 0;
  root(find(1), -1);
  bdp();
  int q;
  scanf("%d", &q);
  while (q--) {
    int u, v;
    scanf("%d%d", &u, &v);
    u = find(u), v = find(v);
    printf("%d\n", dist[u] + dist[v] - 2 * dist[lca(u, v)]);
  }
  return 0;
}
