#include <bits/stdc++.h>
using namespace std;
struct BridgeTree {
  vector<vector<long long> > g;
  int n, ctr, cc;
  vector<long long> num, in, low, root;
  stack<int> bc;
  void dfs(int i, int par) {
    num[i] = low[i] = ctr++;
    bc.push(i);
    in[i] = 1;
    for (int v = 0; v < g[i].size(); v++) {
      int j = g[i][v];
      if (num[j] == -1) dfs(j, i);
      if (j != par && in[j]) low[i] = min(low[i], low[j]);
    }
    if (low[i] == num[i]) {
      cc++;
      while (bc.top() != i) {
        root[bc.top()] = cc, in[bc.top()] = 0, bc.pop();
      }
      root[bc.top()] = cc;
      in[bc.top()] = 0;
      bc.pop();
    }
  }
  BridgeTree() {}
  BridgeTree(vector<vector<long long> > &g)
      : cc(0), g(g), n(g.size()), ctr(0), num(n, -1), in(n), low(n), root(n) {
    dfs(0, -1);
  }
  vector<vector<long long> > getTree() {
    vector<vector<long long> > t(cc + 1);
    for (int i = 0; i < n; i++) {
      for (int v = 0; v < g[i].size(); v++) {
        int j = g[i][v];
        if (i > j) continue;
        if (root[i] != root[j]) {
          t[root[i]].push_back(root[j]);
          t[root[j]].push_back(root[i]);
        }
      }
    }
    return t;
  }
} BB;
vector<vector<long long> > g;
int nn;
int par[100100][18];
int d[100100];
void dfs(int nn, int pp, int dd) {
  d[nn] = dd;
  par[nn][0] = pp;
  for (int i = 1; i < 18; i++) {
    par[nn][i] = par[par[nn][i - 1]][i - 1];
  }
  for (int i = 0; i < g[nn].size(); i++) {
    int v = g[nn][i];
    if (v == pp) continue;
    dfs(v, nn, dd + 1);
  }
}
int lca(int u, int v) {
  if (d[u] < d[v]) swap(u, v);
  for (int i = 17; i >= 0; i--) {
    if (d[u] - d[v] >= (1LL << i)) {
      u = par[u][i];
    }
  }
  if (u == v) return u;
  for (int i = 17; i >= 0; i--) {
    if (par[u][i] != par[v][i]) {
      u = par[u][i];
      v = par[v][i];
    }
  }
  return par[u][0];
}
int dist(int a, int b) { return d[a] + d[b] - 2 * d[lca(a, b)]; }
int main() {
  int n, m;
  cin >> n >> m;
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  BB = BridgeTree(g);
  g = BB.getTree();
  dfs(1, 0, 0);
  long long ans = 0;
  int k;
  cin >> k;
  while (k--) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    a = BB.root[a];
    b = BB.root[b];
    cout << dist(a, b) << endl;
  }
}
