#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
inline long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
inline long long power(long long a, long long n, long long m) {
  if (n == 0) return 1;
  long long p = power(a, n / 2, m);
  p = (p * p) % m;
  if (n % 2)
    return (p * a) % m;
  else
    return p;
}
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
int Time = 0;
int low[100001];
int vt[100001];
bool visited[100001];
vector<pair<int, int> > bridge;
vector<int> adj2[100001];
int par[100001];
int up[2000001][21];
int tin[200001], tout[200001];
int d[100001];
void dfs1(vector<int> adj1[], int u, int p) {
  vt[u] = (++Time);
  low[u] = vt[u];
  visited[u] = 1;
  int v;
  for (int i = 0; i < adj1[u].size(); i++) {
    v = adj1[u][i];
    if (!visited[v]) {
      dfs1(adj1, v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] > vt[u]) {
        bridge.push_back(make_pair(u, v));
      } else {
        adj2[u].push_back(v);
        adj2[v].push_back(u);
      }
    } else if (p != v) {
      low[u] = min(low[u], vt[v]);
      if (low[v] > vt[u]) {
        bridge.push_back(make_pair(u, v));
      } else {
        adj2[u].push_back(v);
        adj2[v].push_back(u);
      }
    }
  }
}
void dfs2(int u, int p) {
  visited[u] = 1;
  par[u] = p;
  int v;
  for (int i = 0; i < adj2[u].size(); i++) {
    v = adj2[u][i];
    if (!visited[v]) {
      dfs2(v, p);
    }
  }
}
void dfs(vector<int> adj[], int u, int parent) {
  tin[u] = ++Time;
  up[u][0] = parent;
  visited[u] = 1;
  for (int i = 1; i <= 20; i++) {
    up[u][i] = up[up[u][i - 1]][i - 1];
  }
  for (int i = 0; i < adj[u].size(); i++)
    if (!visited[adj[u][i]]) {
      d[adj[u][i]] = 1 + d[u];
      dfs(adj, adj[u][i], u);
    }
  tout[u] = ++Time;
}
int is_ancestor(int u, int v) {
  return (tin[u] <= tin[v] && tout[u] >= tout[v]);
}
int lca(int u, int v) {
  if (is_ancestor(u, v)) return u;
  if (is_ancestor(v, u)) return v;
  for (int i = 20; i >= 0; i--)
    if (!is_ancestor(up[u][i], v)) u = up[u][i];
  return up[u][0];
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  vector<int> adj1[n + 1];
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    adj1[u].push_back(v);
    adj1[v].push_back(u);
  }
  dfs1(adj1, 1, 0);
  memset(visited, 0, sizeof(visited));
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      par[i] = i;
      dfs2(i, i);
    }
  }
  vector<int> adj[n + 1];
  memset(visited, 0, sizeof(visited));
  for (int i = 0; i < bridge.size(); i++) {
    u = bridge[i].first;
    v = bridge[i].second;
    if (par[u] != par[v]) {
      adj[par[u]].push_back(par[v]);
      adj[par[v]].push_back(par[u]);
    }
  }
  Time = 0;
  d[1] = 0;
  dfs(adj, 1, 1);
  int k, lc, ans;
  cin >> k;
  while (k--) {
    cin >> u >> v;
    u = par[u];
    v = par[v];
    if (u == v)
      cout << 0;
    else {
      lc = lca(u, v);
      ans = d[u] + d[v] - 2 * d[lc];
      cout << ans;
    }
    cout << endl;
  }
  return 0;
}
