#include <bits/stdc++.h>
using namespace std;
vector<int> cur[200000], g[20000];
map<pair<int, int>, int> cnt;
int n, m;
int tim = 0;
vector<int> up, s, used;
vector<pair<int, int> > e;
vector<int> tin, tout;
set<pair<int, int> > bridge;
vector<int> p;
int t = 0, kmp = 0;
vector<int> dist;
int upp[20000][25];
void vvod() {
  cin >> n >> m;
  p.assign(n, 0);
  tin.assign(n, 0);
  tout.assign(n, 0);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cur[x].push_back(y);
    cur[y].push_back(x);
    e.push_back({x, y});
    cnt[{min(x, y), max(x, y)}]++;
  }
}
void DFS(int v) {
  used[v] = 1;
  p[v] = kmp;
  for (int to : cur[v]) {
    if (used[to]) continue;
    if (bridge.count({v, to}) || bridge.count({to, v})) continue;
    DFS(to);
  }
}
int get(int v) { return p[v]; }
void dfs(int v, int pr) {
  t++;
  s[v] = t;
  up[v] = t;
  for (int to : cur[v]) {
    if (!s[to]) {
      dfs(to, v);
      up[v] = min(up[v], up[to]);
      continue;
    }
    if (to != pr) {
      up[v] = min(up[v], s[to]);
    }
  }
}
void modification() {
  up.assign(n, 0);
  s.assign(n, 0);
  for (int i = 0; i < n; i++) {
    if (!s[i]) {
      dfs(i, -1);
    }
  }
  for (int i = 0; i < e.size(); i++) {
    int v = e[i].first, to = e[i].second;
    if ((up[v] > s[to] || up[to] > s[v]) && cnt[{to, v}] <= 1 &&
        cnt[{v, to}] <= 1) {
      bridge.insert({v, to});
    }
  }
  used.assign(n + 5, 0);
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      kmp++;
      DFS(i);
    }
  }
  tin.assign(kmp, 0);
  tout.assign(kmp, 0);
  for (auto to : e) {
    int x = to.first, y = to.second;
    x = get(x);
    y = get(y);
    if (x == y) continue;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dist.assign(kmp + 1, 0);
}
void build(int v, int pr) {
  tim++;
  tin[v] = tim;
  upp[v][0] = pr;
  for (int i = 1; i < 21; i++) {
    upp[v][i] = upp[upp[v][i - 1]][i - 1];
  }
  int cnt = 0;
  for (int to : g[v]) {
    if (to == pr) continue;
    dist[to] = dist[v] + 1;
    build(to, v);
    cnt++;
  }
  tim++;
  tout[v] = tim;
}
bool upper(int a, int b) { return (tin[a] <= tin[b] && tout[a] >= tout[b]); }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = 20; i >= 0; i--) {
    if (!upper(upp[a][i], b)) {
      a = upp[a][i];
    }
  }
  return upp[a][0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vvod();
  modification();
  int root = 1;
  tin.assign(kmp + 1, 0);
  tout.assign(kmp + 1, 0);
  dist[root] = 1;
  build(root, root);
  int q;
  cin >> q;
  int nw = 0;
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    nw++;
    x = get(x);
    y = get(y);
    int v = lca(x, y);
    long long ans = dist[x] + dist[y] - 2 * dist[v];
    cout << abs(ans) << endl;
  }
  return 0;
}
