#include <bits/stdc++.h>
using namespace std;
vector<int> vn, low, *adj, *E, *G;
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));
}
vector<int> grp;
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]);
    }
}
int main(int argc, char **argv) {
  cin >> n >> m;
  adj = new vector<int>[n];
  vn = vector<int>(n), low = vector<int>(n);
  grp = vector<int>(n, -1);
  for (int i = (0); i < (m); ++i) {
    int first, second;
    cin >> 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);
  E = new vector<int>[n];
  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++;
    }
  G = new vector<int>[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;
  cin >> K;
  for (int q = (0); q < (K); ++q) {
    int px, py;
    cin >> px >> py;
    int first = grp[px - 1], second = grp[py - 1];
    queue<int> Q;
    Q.push(first);
    int vis[g];
    memset(vis, -1, sizeof(vis));
    vis[first] = 0;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      if (u == second) {
        printf("%d\n", vis[second]);
        break;
      }
      for (int i = (0); i < (G[u].size()); ++i)
        if (vis[G[u][i]] == -1) {
          vis[G[u][i]] = vis[u] + 1;
          Q.push(G[u][i]);
        }
    }
  }
  return 0;
}
