#include <bits/stdc++.h>
using namespace std;
const int oo = 999999999;
const double PI = 3.1415931;
const double eps = 1e-9;
const int maxN = 100000 + 10;
int h[maxN], dp[maxN], parent[maxN], n, m, k, hei[maxN];
pair<int, int> par[24][maxN];
bool mark[maxN], mark2[maxN];
vector<int> t[maxN], v[maxN];
map<int, map<int, bool> > mp;
void dfs(int x) {
  mark[x] = true;
  for (int i = 0; i < t[x].size(); i++)
    if (!mark[t[x][i]]) {
      h[t[x][i]] = h[x] + 1;
      v[x].push_back(t[x][i]);
      v[t[x][i]].push_back(x);
      parent[t[x][i]] = x;
      dfs(t[x][i]);
    }
  dp[x] = h[x];
  for (int i = 0; i < t[x].size(); i++) {
    if (t[x][i] != parent[x]) dp[x] = min(dp[x], min(dp[t[x][i]], h[t[x][i]]));
  }
  if (dp[x] > h[parent[x]]) {
    mp[x][parent[x]] = true;
    mp[parent[x]][x] = true;
  }
}
void make(int x) {
  mark2[x] = true;
  int mem = par[0][x].first;
  for (int i = 1; i <= 19; i++) {
    par[i][x].second = par[i - 1][x].second + par[i - 1][mem].second;
    par[i][x].first = par[i - 1][mem].first;
    mem = par[i][x].first;
  }
  for (int i = 0; i < v[x].size(); i++)
    if (!mark2[v[x][i]]) {
      hei[v[x][i]] = hei[x] + 1;
      par[0][v[x][i]].first = x;
      par[0][v[x][i]].second = (mp[x][v[x][i]] == true);
      make(v[x][i]);
    }
}
int lca(int x, int y) {
  int ans = 0;
  if (hei[x] > hei[y]) swap(x, y);
  for (int i = 19; i >= 0; i--)
    if (par[i][y].first != 0 && hei[par[i][y].first] >= hei[x]) {
      ans += par[i][y].second;
      y = par[i][y].first;
    }
  for (int i = 19; i >= 0; i--) {
    if (par[i][y].first != par[i][x].first) {
      ans += par[i][y].second;
      ans += par[i][x].second;
      x = par[i][x].first;
      y = par[i][y].first;
    }
  }
  while (x != y) {
    ans += par[0][y].second;
    ans += par[0][x].second;
    x = par[0][x].first;
    y = par[0][y].first;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  for (int i = 1; i < maxN; i++) dp[i] = oo;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    t[x].push_back(y);
    t[y].push_back(x);
  }
  dfs(1);
  make(1);
  cin >> k;
  while (k--) {
    int x, y;
    cin >> x >> y;
    cout << lca(x, y) << endl;
  }
  return 0;
}
