#include <bits/stdc++.h>
using namespace std;
vector<int> g[100500];
vector<int> t[100500];
bool used[100500];
int ch = 1;
vector<pair<int, int> > most;
map<pair<int, int>, int> mp;
int timer = 0, tin[100500], fup[100500];
void dfs1(int v, int p = 0) {
  used[v] = 1;
  timer++;
  tin[v] = timer;
  fup[v] = timer;
  for (int 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 {
      dfs1(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tin[v]) {
        most.push_back({v, to});
        mp[{v, to}] = 1;
        mp[{to, v}] = 1;
      }
    }
  }
}
int ver[100500];
void clearused(int n) {
  for (int i = 0; i <= n; i++) {
    used[i] = 0;
  }
}
void dfs2(int v, int nom) {
  used[v] = 1;
  ver[v] = nom;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (mp[{to, v}] != 0) {
      continue;
    }
    if (used[to] != 1) {
      dfs2(to, nom);
    }
  }
}
int ton[100500], tout[100500];
int l;
vector<vector<int> > up;
int len[100500];
int o = 0;
void dfs3(int v, int p = 1, int leng = 0) {
  o++;
  ton[v] = o;
  len[v] = leng;
  used[v] = 1;
  up[v][0] = p;
  for (int i = 1; i <= l; i++) {
    up[v][i] = up[up[v][i - 1]][i - 1];
  }
  for (int i = 0; i < t[v].size(); i++) {
    int to = t[v][i];
    if (to != p) {
      dfs3(to, v, leng + 1);
    }
  }
  tout[v] = o;
}
bool upper(int a, int b) { return ton[a] <= ton[b] && tout[a] >= tout[b]; }
int get_len(int a, int b) {
  if (upper(a, b)) return len[b] - len[a];
  if (upper(b, a)) return len[a] - len[b];
  int a1 = a;
  for (int i = l; i >= 0; i--) {
    if (!upper(up[a][i], b)) {
      a = up[a][i];
    }
  }
  a = up[a][0];
  return len[a1] - len[a] + len[b] - len[a];
}
int main() {
  int n, m, k;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dfs1(1);
  int nom = 1;
  clearused(n);
  for (int i = 1; i <= n; i++) {
    if (used[i] != 1) {
      dfs2(i, nom);
      nom++;
    }
  }
  nom--;
  l = 1;
  while (1 << l <= nom) l++;
  up.resize(nom + 1);
  for (int i = 0; i < most.size(); i++) {
    int x = most[i].first;
    int y = most[i].second;
    x = ver[x];
    y = ver[y];
    t[x].push_back(y);
    t[y].push_back(x);
  }
  for (int i = 0; i <= nom; i++) {
    up[i].resize(l + 1);
  }
  clearused(n);
  dfs3(1, 1, 0);
  cin >> k;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    x = ver[x];
    y = ver[y];
    cout << get_len(x, y) << endl;
  }
}
