#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
const long long INF = 1000000001;
const long double EPS = 1E-3;
const int MAXN = 100500;
const int LOG = 20;
int n, bridges, par[MAXN], bl[MAXN], comp[MAXN], size[MAXN];
void init() {
  for (int i = 0; i < n; ++i) {
    bl[i] = comp[i] = i;
    size[i] = 1;
    par[i] = -1;
  }
  bridges = 0;
}
int get(int v) {
  if (v == -1) return -1;
  return bl[v] == v ? v : bl[v] = get(bl[v]);
}
int get_comp(int v) {
  v = get(v);
  return comp[v] == v ? v : comp[v] = get_comp(comp[v]);
}
void make_root(int v) {
  v = get(v);
  int root = v, child = -1;
  while (v != -1) {
    int p = get(par[v]);
    par[v] = child;
    comp[v] = root;
    child = v;
    v = p;
  }
  size[root] = size[child];
}
int cu, u[MAXN];
void merge_path(int a, int b) {
  ++cu;
  vector<int> va, vb;
  int lca = -1;
  for (;;) {
    if (a != -1) {
      a = get(a);
      va.push_back(a);
      if (u[a] == cu) {
        lca = a;
        break;
      }
      u[a] = cu;
      a = par[a];
    }
    if (b != -1) {
      b = get(b);
      vb.push_back(b);
      if (u[b] == cu) {
        lca = b;
        break;
      }
      u[b] = cu;
      b = par[b];
    }
  }
  for (size_t i = 0; i < va.size(); ++i) {
    bl[va[i]] = lca;
    if (va[i] == lca) break;
    --bridges;
  }
  for (size_t i = 0; i < vb.size(); ++i) {
    bl[vb[i]] = lca;
    if (vb[i] == lca) break;
    --bridges;
  }
}
void add_edge(int a, int b) {
  a = get(a);
  b = get(b);
  if (a == b) return;
  int ca = get_comp(a), cb = get_comp(b);
  if (ca != cb) {
    ++bridges;
    if (size[ca] > size[cb]) {
      swap(a, b);
      swap(ca, cb);
    }
    make_root(a);
    par[a] = comp[a] = b;
    size[cb] += size[a];
  } else
    merge_path(a, b);
}
vector<vector<int> > g;
vector<pair<int, int> > e;
int timer = 0, m;
vector<int> dfs_list;
vector<int> ribs_list;
vector<int> h;
void dfs(int v, const vector<vector<int> >& g,
         const vector<vector<int> >& rib_ids, int cur_h = 1) {
  h[v] = cur_h;
  dfs_list.push_back(v);
  for (size_t i = 0; i < g[v].size(); ++i)
    if (h[g[v][i]] == -1) {
      ribs_list.push_back(rib_ids[v][i]);
      dfs(g[v][i], g, rib_ids, cur_h + 1);
      ribs_list.push_back(rib_ids[v][i]);
      dfs_list.push_back(v);
    }
}
vector<int> lca_tree;
vector<int> first;
void lca_tree_build(int i, int l, int r) {
  if (l == r)
    lca_tree[i] = dfs_list[l];
  else {
    int m = (l + r) >> 1;
    lca_tree_build(i + i, l, m);
    lca_tree_build(i + i + 1, m + 1, r);
    int lt = lca_tree[i + i], rt = lca_tree[i + i + 1];
    lca_tree[i] = h[lt] < h[rt] ? lt : rt;
  }
}
void lca_prepare(int n) {
  lca_tree.assign(dfs_list.size() * 8, -1);
  lca_tree_build(1, 0, (int)dfs_list.size() - 1);
  first.assign(n, -1);
  for (int i = 0; i < (int)dfs_list.size(); ++i) {
    int v = dfs_list[i];
    if (first[v] == -1) first[v] = i;
  }
}
int lca_tree_query(int i, int tl, int tr, int l, int r) {
  if (tl == l && tr == r) return lca_tree[i];
  int m = (tl + tr) >> 1;
  if (r <= m) return lca_tree_query(i + i, tl, m, l, r);
  if (l > m) return lca_tree_query(i + i + 1, m + 1, tr, l, r);
  int lt = lca_tree_query(i + i, tl, m, l, m);
  int rt = lca_tree_query(i + i + 1, m + 1, tr, m + 1, r);
  return h[lt] < h[rt] ? lt : rt;
}
int lca(int a, int b) {
  if (first[a] > first[b]) swap(a, b);
  return lca_tree_query(1, 0, (int)dfs_list.size() - 1, first[a], first[b]);
}
vector<int> first1, first2;
vector<char> rib_used;
vector<int> tree1, tree2;
void query_prepare(int n) {
  first1.resize(n - 1, -1);
  first2.resize(n - 1, -1);
  for (int i = 0; i < (int)ribs_list.size(); ++i) {
    int j = ribs_list[i];
    if (first1[j] == -1)
      first1[j] = i;
    else
      first2[j] = i;
  }
  rib_used.resize(n - 1);
  tree1.resize(ribs_list.size() * 8);
  tree2.resize(ribs_list.size() * 8);
}
void sum_tree_update(vector<int>& tree, int i, int l, int r, int j, int delta) {
  tree[i] += delta;
  if (l < r) {
    int m = (l + r) >> 1;
    if (j <= m)
      sum_tree_update(tree, i + i, l, m, j, delta);
    else
      sum_tree_update(tree, i + i + 1, m + 1, r, j, delta);
  }
}
int sum_tree_query(const vector<int>& tree, int i, int tl, int tr, int l,
                   int r) {
  if (l > r || tl > tr) return 0;
  if (tl == l && tr == r) return tree[i];
  int m = (tl + tr) >> 1;
  if (r <= m) return sum_tree_query(tree, i + i, tl, m, l, r);
  if (l > m) return sum_tree_query(tree, i + i + 1, m + 1, tr, l, r);
  return sum_tree_query(tree, i + i, tl, m, l, m) +
         sum_tree_query(tree, i + i + 1, m + 1, tr, m + 1, r);
}
int query(int v1, int v2) {
  return sum_tree_query(tree1, 1, 0, (int)ribs_list.size() - 1, first[v1],
                        first[v2] - 1) -
         sum_tree_query(tree2, 1, 0, (int)ribs_list.size() - 1, first[v1],
                        first[v2] - 1);
}
vector<int> xs, c;
vector<vector<int> > rib_ids;
int main() {
  cin >> n >> m;
  init();
  for (int i = 0; i < (int)m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    v1--;
    v2--;
    add_edge(v1, v2);
    e.push_back(make_pair(v1, v2));
  }
  for (int i = 0; i < (int)n; i++) {
    xs.push_back(get(i));
  }
  sort((xs).begin(), (xs).end());
  xs.erase(unique((xs).begin(), (xs).end()), xs.end());
  c.resize(n);
  for (int i = 0; i < (int)n; i++) {
    int v = get(i);
    v = lower_bound((xs).begin(), (xs).end(), v) - xs.begin();
    c[i] = v;
  }
  n = bridges + 1;
  g.resize(n);
  rib_ids.resize(n);
  int cur = 0;
  for (int i = 0; i < (int)m; i++) {
    int v1 = e[i].first, v2 = e[i].second;
    v1 = c[v1];
    v2 = c[v2];
    if (v1 != v2) {
      g[v1].push_back(v2);
      g[v2].push_back(v1);
      rib_ids[v1].push_back(cur);
      rib_ids[v2].push_back(cur);
      cur++;
    }
  }
  h.assign(n, -1);
  dfs(0, g, rib_ids);
  lca_prepare(n);
  query_prepare(n);
  int k;
  cin >> k;
  for (int i = 0; i < (int)k; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    v1--;
    v2--;
    v1 = c[v1];
    v2 = c[v2];
    int l = lca(v1, v2);
    int result = h[v2] - h[l] + h[v1] - h[l];
    cout << result << endl;
  }
}
