#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3000;
vector<int> g[MAXN];
bool used[MAXN];
int timer, tin[MAXN], fup[MAXN];
vector<pair<int, int> > brd;
int n;
void dfs(int v, int 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]) brd.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() {
  int m, k;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int temp1, temp2;
    cin >> temp1 >> temp2;
    --temp1;
    --temp2;
    g[temp1].push_back(temp2);
    g[temp2].push_back(temp1);
  }
  find_bridges();
  cin >> k;
  vector<pair<int, int> > traders(k);
  for (int i = 0; i < k; ++i) cin >> traders[i].first >> traders[i].second;
  for (int i = 0; i < k; ++i) {
    --traders[i].first;
    --traders[i].second;
  }
  vector<long long> ans(k);
  for (int i = 0; i < brd.size(); ++i) {
    pair<int, int> cur = brd[i];
    vector<int> used(n, -1);
    queue<int> q;
    q.push(cur.first);
    q.push(cur.second);
    used[cur.first] = 1;
    used[cur.second] = 2;
    while (!q.empty()) {
      int cur1 = q.front();
      q.pop();
      for (int j = 0; j < g[cur1].size(); ++j)
        if (used[g[cur1][j]] == -1) {
          used[g[cur1][j]] = used[cur1];
          q.push(g[cur1][j]);
        }
    }
    for (int j = 0; j < k; ++j)
      if (used[traders[j].first] != used[traders[j].second]) ++ans[j];
  }
  for (int i = 0; i < k; ++i) cout << ans[i] << endl;
}
