#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int p[MAXN];
int low[MAXN];
int n, m;
int tin[MAXN];
int timer;
bool bad[MAXN];
int val[MAXN];
int dp[MAXN][25];
vector<int> v1[MAXN];
int h[MAXN];
void dfsbridges(int curr, int par) {
  p[curr] = par;
  tin[curr] = low[curr] = timer++;
  for (int x : v1[curr]) {
    if (par == x) {
      continue;
    }
    if (tin[x] == -1) {
      dfsbridges(x, curr);
      low[curr] = min(low[curr], low[x]);
    } else {
      low[curr] = min(low[curr], tin[x]);
    }
  }
  if (low[curr] >= tin[curr]) {
    bad[curr] = true;
  } else {
  }
}
void dfs(int curr, int par, int cnt) {
  val[curr] = cnt;
  dp[curr][0] = par;
  for (int i = 1; i <= 19; i++) {
    if (dp[curr][i - 1] == -1) {
      dp[curr][i] = -1;
    } else {
      dp[curr][i] = dp[dp[curr][i - 1]][i - 1];
    }
  }
  for (int x : v1[curr]) {
    if (p[x] == curr) {
      h[x] = h[curr] + 1;
      dfs(x, curr, cnt + bad[x]);
    }
  }
}
int lca(int x, int y) {
  if (h[x] > h[y]) {
    swap(x, y);
  }
  for (int i = 20; i >= 0; i--) {
    if (h[y] - (1 << i) >= h[x]) {
      y = dp[y][i];
    }
  }
  if (x == y) {
    return x;
  }
  for (int i = 20; i >= 0; i--) {
    if (dp[x][i] != -1 && dp[x][i] != dp[y][i]) {
      x = dp[x][i];
      y = dp[y][i];
    }
  }
  return dp[x][0];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v1[x].push_back(y);
    v1[y].push_back(x);
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= 20; j++) {
      dp[i][j] = -1;
      tin[i] = -1;
    }
  }
  dfsbridges(1, -1);
  dfs(1, -1, 0);
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    int anc = lca(u, v);
    cout << val[u] + val[v] - (2 * val[anc]) << endl;
  }
}
