#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, bool> bridge;
bool isBridge(int u, int v) {
  if (u > v) swap(u, v);
  return bridge.count(pair<int, int>(u, v));
}
void addBridge(int u, int v) {
  if (u > v) swap(u, v);
  bridge[pair<int, int>(u, v)] = true;
}
int n, number[100111], low[100111], counter;
vector<int> adj[100111], adj2[100111];
int root[100111], parent[100111], N, P[100111][20], level[100111];
void dfs(int u, int p) {
  low[u] = number[u] = ++counter;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (number[v] == 0) {
      dfs(v, u);
      if (low[v] > number[u]) addBridge(u, v);
      low[u] = min(low[u], low[v]);
    } else if (v != p)
      low[u] = min(low[u], number[v]);
  }
}
void visit(int u, int p) {
  root[u] = p;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (isBridge(u, v)) continue;
    if (!root[v]) visit(v, p);
  }
}
void buildTree(int u, int p, int lvl) {
  parent[u] = p;
  level[u] = lvl;
  for (int i = 0; i < adj2[u].size(); i++) {
    int v = adj2[u][i];
    if (!parent[v]) buildTree(v, u, lvl + 1);
  }
}
void prepare() {
  counter = 0;
  for (int i = 1; i <= n; i++) {
    low[i] = number[i] = 0;
    root[i] = parent[i] = 0;
  }
  for (int i = 1; i <= n; i++)
    if (number[i] == 0) dfs(i, -1);
  counter = 0;
  for (typeof(bridge.begin()) it = bridge.begin(); it != bridge.end(); it++) {
    int u = it->first.first, v = it->first.second;
    if (!root[u]) visit(u, ++counter);
    if (!root[v]) visit(v, ++counter);
    u = root[u];
    v = root[v];
    adj2[u].push_back(v);
    adj2[v].push_back(u);
  }
  N = counter;
  if (N == 0) return;
  buildTree(1, -1, 0);
  for (int i = 1; i <= N; i++) P[i][0] = parent[i];
  for (int j = 1; (1 << (j)) <= N; j++) {
    for (int i = 1; i <= N; i++)
      if (P[i][j - 1] == -1)
        P[i][j] = -1;
      else
        P[i][j] = P[P[i][j - 1]][j - 1];
  }
}
int getLCA(int u, int v) {
  if (level[u] < level[v]) swap(u, v);
  int m = 0;
  while ((1 << (m)) <= level[u]) m++;
  for (int i = m; i >= 0; i--)
    if (level[u] - (1 << (i)) >= level[v]) u = P[u][i];
  if (u == v) return u;
  for (int i = m; i >= 0; i--) {
    if (P[u][i] != -1 && P[u][i] != P[v][i]) u = P[u][i], v = P[v][i];
  }
  return parent[u];
}
int solveLCA(int u, int v) {
  if (N == 0) return 0;
  u = root[u], v = root[v];
  int p = getLCA(u, v);
  if (p == u || p == v) return abs(level[v] - level[u]);
  return level[u] + level[v] - 2 * level[p];
}
int main() {
  int m, u, v, k;
  scanf("%d %d", &n, &m);
  while (m--) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  prepare();
  scanf("%d", &k);
  while (k--) {
    scanf("%d %d", &u, &v);
    printf("%d\n", solveLCA(u, v));
  }
  return 0;
}
