#include <bits/stdc++.h>
using namespace std;
vector<int> cities[100000];
vector<bool> visited(100000);
vector<int> t(100000), low(100000);
map<pair<int, int>, int> b;
int c = 0, ans = 0;
void dfs(int v, int p = -1) {
  visited[v] = true;
  t[v] = low[v] = c++;
  for (int dest : cities[v]) {
    if (dest == p) continue;
    if (visited[dest]) {
      low[v] = min(low[v], t[dest]);
    } else {
      dfs(dest, v);
      low[v] = min(low[v], low[dest]);
      if (low[dest] > t[v]) {
        b[{v, dest}] = 1;
        b[{dest, v}] = 1;
      } else {
        b[{v, dest}] = 0;
        b[{dest, v}] = 0;
      }
    }
  }
}
vector<long long> dist(100001);
void Dijkstra(int r, int e) {
  set<pair<int, int> > s;
  dist[r] = 0;
  s.insert({0, r});
  while (!s.empty()) {
    pair<int, int> p = *s.begin();
    s.erase(s.begin());
    int x = p.first, y = p.second;
    if (x > dist[y]) {
      continue;
    } else if (dist[e] != INT_MAX) {
      return;
    }
    for (int j = 0; j < cities[y].size(); j++) {
      if (dist[y] + b[{y, cities[y][j]}] < dist[cities[y][j]]) {
        dist[cities[y][j]] = dist[y] + b[{y, cities[y][j]}];
        s.insert({dist[cities[y][j]], cities[y][j]});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    cities[x - 1].push_back(y - 1);
    cities[y - 1].push_back(x - 1);
  }
  c = 0;
  t.assign(n, -1);
  low.assign(n, -1);
  visited.assign(n, false);
  for (int i = 0; i < n; ++i) {
    if (!visited[i]) {
      dfs(i);
    }
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    ans = 0;
    dist.assign(n, INT_MAX);
    int root, shop;
    cin >> root >> shop;
    Dijkstra(root - 1, shop - 1);
    cout << dist[shop - 1] << "\n";
  }
  return 0;
}
