#include <bits/stdc++.h>
using namespace std;
long a[100002];
long b[100002];
long s[100002];
long l[100002];
vector<int> br0, br1;
map<int, vector<int> > fre, an;
const int MAXN = 100001;
int comp = 0;
vector<int> g[MAXN], h[MAXN];
bool used[MAXN];
int timer, tin[MAXN], fup[MAXN], col[MAXN];
int n, ans = 0;
void IS_BRIDGE(int i, int j) {
  br0.push_back(i);
  br1.push_back(j);
}
void dfs(int v, int p = -1) {
  used[v] = true;
  tin[v] = fup[v] = timer++;
  for (size_t i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to == p) continue;
    if (used[to])
      fup[v] = min(fup[v], tin[to]);
    else {
      dfs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tin[v]) IS_BRIDGE(v, to);
    }
  }
}
void find_bridges() {
  timer = 0;
  for (int i = 0; i < n; ++i) used[i] = false;
  for (int i = 0; i < n; ++i)
    if (!used[i]) dfs(i);
}
void dfs_h(int i) {
  used[i] = 1;
  col[i] = comp;
  for (int j = 0; j < fre[i].size(); j++)
    if (!used[fre[i][j]]) dfs_h(fre[i][j]);
}
void dfs_k(int i, int dl, int z) {
  used[i] = 1;
  for (int j = 0; j < an[i].size(); j++)
    if (an[i][j] == z) {
      ans += dl + 1;
    } else if (!used[an[i][j]])
      dfs_k(an[i][j], dl + 1, z);
}
int main() {
  int m, k, c;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  cin >> k;
  for (int i = 1; i <= k; i++) cin >> s[i] >> l[i];
  find_bridges();
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < g[i].size(); j++) {
      bool OK = 0;
      for (int k = 0; k < br0.size(); k++) {
        if (((br0[k] == i) && (br1[k] == g[i][j])) ||
            ((br1[k] == i) && (br0[k] == g[i][j])))
          OK = 1;
      }
      if (!OK) {
        fre[i].push_back(g[i][j]);
        fre[g[i][j]].push_back(i);
      }
    }
  for (int i = 1; i <= n; i++) used[i] = 0;
  for (int i = 1; i <= n; i++)
    if (!used[i]) {
      comp++;
      dfs_h(i);
    }
  for (int k = 0; k < br0.size(); k++) {
    an[col[br0[k]]].push_back(col[br1[k]]);
    an[col[br1[k]]].push_back(col[br0[k]]);
  }
  for (int i = 1; i <= k; i++) {
    if (col[s[i]] == col[l[i]])
      cout << 0 << endl;
    else {
      for (int j = 1; j <= n; j++) used[j] = 0;
      ans = 0;
      dfs_k(col[s[i]], 0, col[l[i]]);
      cout << ans << endl;
    }
  }
}
