#include <bits/stdc++.h>
using namespace std;
const long long INFLL = LLONG_MAX;
const int INF = INT_MAX;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T> >;
template <class T>
void sort(vector<T>& v) {
  sort(v.begin(), v.end());
}
template <class T, class U>
void sort(vector<T>& v, U func) {
  sort(v.begin(), v.end(), func);
}
template <class T>
int lb_index(vector<T>& v, T k) {
  return lower_bound(v.begin(), v.end(), k) - v.begin();
}
template <class T>
int ub_index(vector<T>& v, T k) {
  return upper_bound(v.begin(), v.end(), k) - v.begin();
}
int n, m;
vector<int> v[100000];
vector<int> st(100000, -1), et(100000, -1);
vector<int> low(100000);
vector<pair<int, int> > bridge;
int tim;
vector<vector<int> > dp(100000, vector<int>(20, -1));
vector<int> dep(100000);
void dfs(int u, int p) {
  st[u] = tim++;
  low[u] = st[u];
  for (auto i : v[u]) {
    if (p == i) continue;
    if (st[i] == -1) {
      dp[i][0] = u;
      dep[i] = dep[u] + 1;
      dfs(i, u);
      low[u] = min(low[u], low[i]);
      if (st[u] < low[i]) {
        bridge.emplace_back(u, i);
      }
    } else if (et[i] == -1) {
      low[u] = min(low[u], st[i]);
    }
  }
  et[u] = tim;
}
int lca(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  for (int i = 19; i >= 0; i--) {
    if (dp[v][i] != -1 && dep[dp[v][i]] >= dep[u]) {
      v = dp[v][i];
    }
  }
  if (u == v) return u;
  for (int i = 19; i >= 0; i--) {
    if (dp[u][i] != dp[v][i]) {
      u = dp[u][i];
      v = dp[v][i];
    }
  }
  return dp[u][0];
}
int main() {
  cin >> n >> m;
  while (m--) {
    int l, r;
    cin >> l >> r;
    v[l - 1].emplace_back(r - 1);
    v[r - 1].emplace_back(l - 1);
  }
  for (int i = 0; i < n; i++) {
    if (st[i] == -1) dfs(i, -1);
  }
  map<pair<int, int>, bool> p;
  for (auto i : bridge) {
    p[i] = 1;
    p[{i.second, i.first}] = 1;
  }
  for (int j = 1; j < 20; j++) {
    for (int i = 0; i < n; i++) {
      dp[i][j] = (dp[i][j - 1] < 0 ? -1 : dp[dp[i][j - 1]][j - 1]);
    }
  }
  vector<int> val(100000);
  vector<bool> vis(100000);
  vis[0] = 1;
  deque<int> q;
  q.emplace_back(0);
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    for (auto i : v[u]) {
      if (!vis[i]) {
        if (p[{u, i}]) {
          val[i] = val[u] + 1;
          vis[i] = 1;
          q.emplace_back(i);
        } else {
          val[i] = val[u];
          vis[i] = 1;
          q.emplace_front(i);
        }
      }
    }
  }
  cin >> m;
  while (m--) {
    int l, r;
    cin >> l >> r;
    cout << val[l - 1] + val[r - 1] - 2 * val[lca(l - 1, r - 1)] << "\n";
  }
}
