#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
long long timer = 1;
vector<vector<long long>> adj(500001);
vector<long long> v1, v2, disc, low, road;
map<pair<long long, long long>, long long> important;
void dfs(long long u, long long p) {
  v1[u] = 1;
  disc[u] = low[u] = timer++;
  for (long long v : adj[u]) {
    if (p == v) continue;
    if (v1[v]) {
      low[u] = min(low[u], disc[v]);
    } else {
      dfs(v, u);
      low[u] = min(low[v], low[u]);
      if (low[v] > disc[u]) {
        important[{u, v}] = 1;
        important[{v, u}] = 1;
      }
    }
  }
}
void dfs1(long long u) {
  v2[u] = 1;
  for (long long v : adj[u]) {
    if (!v2[v]) {
      road[v] = road[u] + important[{u, v}];
      dfs1(v);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, k, i, u, v;
  cin >> n >> m;
  v1.assign(n + 1, 0);
  disc.assign(n + 1, -1);
  low.assign(n + 1, -1);
  v2.assign(n + 1, 0);
  road.assign(n + 1, 0);
  adj[0].push_back(1);
  adj[1].push_back(0);
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  cin >> k;
  dfs(0, -1);
  dfs1(0);
  while (k--) {
    for (i = 0; i <= n; i++) {
      v2[i] = road[i] = 0;
    }
    cin >> u >> v;
    dfs1(u);
    cout << road[v] << "\n";
  }
  return 0;
}
