#include <bits/stdc++.h>
using namespace std;
const int MAX = 1E5 + 5;
int n, m, q;
vector<int> edg[MAX], gph[MAX];
map<pair<int, int>, int> mp;
int vis[MAX], _time, lo[MAX], lvl[MAX];
int table[MAX][20], cst[MAX][20];
void dfs1(int node, int p) {
  vis[node] = ++_time;
  lo[node] = _time;
  for (auto x : edg[node]) {
    if (x == p) continue;
    if (vis[x]) {
      lo[node] = min(lo[node], vis[x]);
    } else {
      dfs1(x, node);
      lo[node] = min(lo[node], lo[x]);
      if (lo[x] > vis[node]) {
        mp[{x, node}] = 1;
        mp[{node, x}] = 1;
      }
    }
  }
}
void dfs2(int node, int l) {
  lvl[node] = l;
  vis[node] = 1;
  for (auto x : edg[node]) {
    if (vis[x]) continue;
    table[x][0] = node;
    if (mp[{x, node}]) cst[x][0] = 1;
    dfs2(x, l + 1);
  }
}
void build() {
  for (int j = 1; j < 20; j++) {
    for (int i = 1; i <= n; i++) {
      if (table[i][j - 1] == -1) continue;
      table[i][j] = table[table[i][j - 1]][j - 1];
      cst[i][j] = cst[i][j - 1] + cst[table[i][j - 1]][j - 1];
    }
  }
}
int query(int u, int v) {
  if (lvl[u] < lvl[v]) swap(u, v);
  int ret = 0;
  while (lvl[u] > lvl[v]) {
    int val = log2(lvl[u] - lvl[v]);
    ret += cst[u][val];
    u = table[u][val];
  }
  if (u == v) return ret;
  for (int i = 19; i >= 0; i--) {
    if (table[u][i] == table[v][i]) continue;
    ret += cst[u][i];
    ret += cst[v][i];
    u = table[u][i];
    v = table[v][i];
  }
  return ret + cst[u][0] + cst[v][0];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    edg[u].push_back(v);
    edg[v].push_back(u);
  }
  dfs1(1, -1);
  memset(vis, 0, sizeof vis);
  memset(table, -1, sizeof table);
  dfs2(1, 0);
  build();
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    cout << query(u, v) << '\n';
  }
  return 0;
}
