#include <bits/stdc++.h>
using namespace std;
int vn[200010], low[200010], tin[200010], tout[200010], d[200010];
vector<int> *a;
vector<int> adj[200010], E[200010], G[200010];
int ans, n, m, t;
map<pair<int, int>, int> bridge;
void run(int u, int p) {
  vn[u] = low[u] = t++;
  for (int i = 0; i < adj[u].size(); ++i) {
    int v = adj[u][i];
    if (v == p) continue;
    if (!vn[v]) {
      run(v, u);
      low[u] = min(low[u], low[v]);
    } else
      low[u] = min(low[u], vn[v]);
    if (vn[u] < low[v]) ans++, bridge[make_pair(min(u, v), max(u, v))] = 1;
  }
}
pair<int, int> mmp(int first, int second) {
  return make_pair(min(first, second), max(first, second));
}
int grp[200010];
int g = 0;
void dfs(int first) {
  grp[first] = g;
  for (int i = (0); i < (E[first].size()); ++i)
    if (grp[E[first][i]] == -1) {
      dfs(E[first][i]);
    }
}
void DFS(int first, int p) {
  tin[first] = t++;
  a[first][0] = p;
  for (int i = 1; 1 << i < g / 2; ++i) a[first][i] = a[a[first][i - 1]][i - 1];
  for (int i = (0); i < (G[first].size()); ++i)
    if (G[first][i] != p)
      d[G[first][i]] = d[first] + 1, DFS(G[first][i], first);
  tout[first] = t++;
}
inline bool ancestor(int first, int second) {
  return tin[first] <= tin[second] && tout[first] >= tout[second];
}
int log2(int second) {
  int i = 0;
  while (1 << i <= second) i++;
  return i - 1;
}
int R;
inline int LCA(int first, int second) {
  if (ancestor(first, second)) return first;
  if (ancestor(second, first)) return second;
  for (int i = log2(g / 2); i >= 0; --i)
    if (!ancestor(a[first][i], second)) first = a[first][i];
  return a[first][0];
}
int main(int argc, char **argv) {
  cin >> n >> m;
  memset(grp, -1, sizeof(grp));
  for (int i = (0); i < (m); ++i) {
    int first, second;
    scanf("%d%d", &first, &second);
    --first, --second;
    adj[second].push_back(first), adj[first].push_back(second);
  }
  ans = 0;
  for (int i = 0; i < n; i++)
    if (!vn[i]) t = 1, run(i, i);
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (adj[i].size()); ++j)
      if (bridge.find(mmp(i, adj[i][j])) == bridge.end())
        E[i].push_back(adj[i][j]);
  for (int i = (0); i < (n); ++i)
    if (grp[i] == -1) {
      dfs(i);
      g++;
    }
  for (map<pair<int, int>, int>::iterator i = bridge.begin(); i != bridge.end();
       ++i) {
    int first = grp[(i->first).first], second = grp[(i->first).second];
    G[first].push_back(second);
    G[second].push_back(first);
  }
  int K;
  int r = 0;
  for (int i = (0); i < (g); ++i)
    if (G[i].size() == 1) r = i;
  t = 0;
  a = new vector<int>[g];
  R = log2(g / 2);
  for (int i = (0); i < (g); ++i) a[i] = vector<int>(100);
  DFS(r, r);
  cin >> K;
  for (int q = (0); q < (K); ++q) {
    int px, py;
    scanf("%d%d\n", &px, &py);
    int first = grp[px - 1], second = grp[py - 1];
    printf("%d\n", d[first] + d[second] - 2 * d[LCA(first, second)]);
  }
  return 0;
}
