#include <bits/stdc++.h>
using namespace std;
vector<vector<long> > g;
vector<bool> used;
long timer;
vector<long> tin, fup;
long n;
vector<pair<long, long> > bridge;
void dfs(long v, long p = -1) {
  used[v] = true;
  tin[v] = fup[v] = timer++;
  for (size_t i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to == p) continue;
    if (used[to])
      fup[v] = min(fup[v], tin[to]);
    else {
      dfs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tin[v]) bridge.push_back(make_pair(v, to));
    }
  }
}
void find_bridges() {
  timer = 0;
  for (int i = 0; i < n; ++i) used[i] = false;
  for (int i = 0; i < n; ++i)
    if (!used[i]) dfs(i);
}
int main() {
  long m;
  cin >> n >> m;
  long a, b;
  vector<long> temp;
  temp.reserve(n);
  used.resize(n);
  tin.resize(n);
  fup.resize(n);
  g.assign(n, temp);
  for (long i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<long>::iterator it;
  find_bridges();
  for (long i = 0; i < n; i++) sort(g[i].begin(), g[i].end());
  for (long i = 0; i < bridge.size(); i++) {
    a = bridge[i].first;
    b = bridge[i].second;
    it = lower_bound(g[a].begin(), g[a].end(), b);
    g[a].erase(it);
    it = lower_bound(g[b].begin(), g[b].end(), a);
    g[b].erase(it);
  }
  vector<long> komp(n, -1);
  long kol = -1;
  long v;
  for (long i = 0; i < n; i++)
    if (komp[i] == -1) {
      kol++;
      komp[i] = kol;
      queue<long> q;
      q.push(i);
      while (!q.empty()) {
        v = q.front();
        q.pop();
        for (long j = 0; j < g[v].size(); j++)
          if (komp[g[v][j]] == -1) {
            komp[g[v][j]] = kol;
            q.push(g[v][j]);
          }
      }
    }
  vector<vector<pair<long, long> > > gg(kol + 1);
  for (long i = 0; i < bridge.size(); i++) {
    gg[komp[bridge[i].first]].push_back(make_pair(1, komp[bridge[i].second]));
    gg[komp[bridge[i].second]].push_back(make_pair(1, komp[bridge[i].first]));
  }
  long kk;
  cin >> kk;
  for (long i = 0; i < kk; i++) {
    cin >> a >> b;
    a--;
    b--;
    a = komp[a];
    b = komp[b];
    if (a > b) swap(a, b);
    vector<int> d(kol + 1, 10000000), p(kol + 1);
    d[a] = 0;
    set<pair<int, int> > q;
    q.insert(make_pair(d[a], a));
    while (!q.empty()) {
      int v = q.begin()->second;
      q.erase(q.begin());
      for (size_t j = 0; j < gg[v].size(); ++j) {
        int len = gg[v][j].first, to = gg[v][j].second;
        if (d[v] + len < d[to]) {
          q.erase(make_pair(d[to], to));
          d[to] = d[v] + len;
          p[to] = v;
          q.insert(make_pair(d[to], to));
        }
      }
    }
    cout << d[b] << "\n";
  }
}
