#include <bits/stdc++.h>
using namespace std;
int get(vector<int> &comp, int a) {
  if (comp[a] == a) return a;
  return comp[a] = get(comp, comp[a]);
}
void unite(vector<int> &comp, vector<int> &sz, int a, int b) {
  a = get(comp, a);
  b = get(comp, b);
  if (a == b) return;
  if (sz[b] > sz[a]) swap(a, b);
  sz[a] += sz[b];
  comp[b] = a;
}
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> comp(n);
  vector<int> sz(n, 1);
  for (int i = 0; i < n; i++) comp[i] = i;
  vector<vector<int> > ribs(n), tree(n);
  vector<pair<int, int> > riblist;
  int p, q;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &p, &q);
    p--;
    q--;
    riblist.push_back(make_pair(p, q));
    ribs[p].push_back(q);
    ribs[q].push_back(p);
  }
  vector<pair<int, int> > st;
  vector<int> prv(n, -1);
  vector<bool> fl(n, 0);
  st.push_back(make_pair(0, 0));
  while (!st.empty()) {
    p = st.back().first;
    fl[p] = 1;
    int i;
    for (i = st.back().second; i < ribs[p].size(); i++)
      if (ribs[p][i] != prv[p]) {
        if (fl[ribs[p][i]] == 0) {
          st.back().second = i + 1;
          prv[ribs[p][i]] = p;
          st.push_back(make_pair(ribs[p][i], 0));
          break;
        } else if (get(comp, p) != get(comp, ribs[p][i])) {
          for (int j = st.size() - 1; st[j].first != ribs[p][i]; j--)
            unite(comp, sz, ribs[p][i], st[j].first);
        }
      }
    if (i == ribs[p].size()) st.pop_back();
  }
  int root = get(comp, comp[0]);
  for (int i = 0; i < m; i++) {
    riblist[i].first = get(comp, riblist[i].first);
    riblist[i].second = get(comp, riblist[i].second);
    if (riblist[i].first != riblist[i].second) {
      tree[riblist[i].first].push_back(riblist[i].second);
      tree[riblist[i].second].push_back(riblist[i].first);
    }
  }
  st.push_back(make_pair(root, 0));
  int ln = 0;
  q = 1;
  while (q * 2 <= 2 * n) {
    ln++;
    q *= 2;
  }
  vector<vector<int> > sparse;
  vector<int> first(n);
  vector<int> hh(n);
  int curh = 0;
  fl.assign(n, 0);
  while (!st.empty()) {
    int p = st.back().first;
    if (st.back().second == 0) first[p] = sparse.size();
    sparse.push_back(vector<int>(ln + 1));
    sparse.back()[0] = curh;
    fl[p] = 1;
    hh[p] = curh;
    int i;
    for (i = st.back().second; i < tree[p].size(); i++)
      if (!fl[tree[p][i]]) {
        curh++;
        st.back().second = i + 1;
        st.push_back(make_pair(tree[p][i], 0));
        break;
      }
    if (i == tree[p].size()) {
      curh--;
      st.pop_back();
    }
  }
  q = 1;
  for (int j = 1; j <= ln; j++) {
    for (int i = 0; i < sparse.size(); i++) {
      sparse[i][j] = sparse[i][j - 1];
      if (i + q < sparse.size())
        sparse[i][j] = min(sparse[i][j], sparse[i + q][j - 1]);
    }
    q *= 2;
  }
  int l, w;
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &p, &q);
    p--;
    q--;
    p = get(comp, p);
    q = get(comp, q);
    if (first[p] > first[q]) swap(p, q);
    w = 1;
    l = 0;
    while (w * 2 <= first[q] - first[p] + 1) {
      w *= 2;
      l++;
    }
    int r = min(sparse[first[p]][l], sparse[first[q] - w + 1][l]);
    r = hh[p] + hh[q] - 2 * r;
    printf("%d\n", r);
  }
}
