#include <bits/stdc++.h>
using namespace std;
struct node {
  int used = 0, in = 0, up = 0;
};
struct in_out {
  int in = 0, out = 0;
};
struct point {
  int value = 0;
  in_out Time;
};
vector<vector<int> > g, g1, tree, UP;
vector<node> nodes;
vector<point> points;
vector<int> color;
set<pair<int, int> > bridges;
int t = 1, l = 1;
void FindBridges(int v, int p = -1) {
  nodes[v].used = 1;
  nodes[v].in = nodes[v].up = t++;
  for (const int& to : g[v]) {
    if (to == p) continue;
    if (nodes[to].used)
      nodes[v].up = min(nodes[v].up, nodes[to].in);
    else {
      FindBridges(to, v);
      nodes[v].up = min(nodes[v].up, nodes[to].up);
      if (nodes[to].up > nodes[v].in)
        bridges.insert(make_pair(min(v, to), max(v, to)));
    }
  }
}
void cond(int v, int CurColor) {
  color[v] = CurColor;
  for (int& to : g1[v])
    if (color[to] == -1) cond(to, CurColor);
}
void dfs(int v, int p = 1) {
  points[v].Time.in = t++;
  UP[v][0] = p;
  for (int i = 1; i <= l; i++) UP[v][i] = UP[UP[v][i - 1]][i - 1];
  for (const int& i : tree[v])
    if (i != p) dfs(i, v);
  points[v].Time.out = t++;
}
void DfsForValue(int v, int p = -1, int res = 0) {
  points[v].value = res;
  for (const int& i : tree[v])
    if (i != p) DfsForValue(i, v, res + 1);
}
bool Parent(int& a, int& b) {
  return (points[a].Time.in <= points[b].Time.in &&
          points[a].Time.out >= points[b].Time.out);
}
int LCA(int& a, int& b) {
  if (Parent(a, b)) return a;
  if (Parent(b, a)) return b;
  for (int i = l; i >= 0; i--)
    if (!Parent(UP[a][i], b)) a = UP[a][i];
  return UP[a][0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > edges(m);
  g.clear();
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
    edges[i] = make_pair(min(x, y), max(x, y));
  }
  nodes.clear();
  nodes.resize(n);
  bridges.clear();
  for (int i = 0; i < n; i++)
    if (!nodes[i].used) FindBridges(i);
  g1.clear();
  g1.resize(n);
  for (int i = 0; i < m; i++)
    if (bridges.find(edges[i]) == bridges.end()) {
      g1[edges[i].first].push_back(edges[i].second);
      g1[edges[i].second].push_back(edges[i].first);
    }
  int NumColor = 1;
  color.assign(n + 10, -1);
  for (int i = 0; i < n; i++)
    if (color[i] == -1) {
      cond(i, NumColor);
      NumColor++;
    }
  tree.clear();
  tree.resize(NumColor);
  for (const auto& [f, s] : bridges) {
    tree[color[f]].push_back(color[s]);
    tree[color[s]].push_back(color[f]);
  }
  points.clear();
  points.resize(NumColor);
  UP.clear();
  UP.resize(NumColor + 2);
  while ((1 << l) <= tree.size() + 1) l++;
  for (int i = 0; i <= NumColor; i++) UP[i].resize(l + 1);
  t = 1;
  dfs(1);
  DfsForValue(1);
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    int color_x = color[x - 1], color_y = color[y - 1];
    int res = points[color_x].value + points[color_y].value -
              2 * points[LCA(color_x, color_y)].value;
    cout << res << "\n";
  }
  return 0;
}
