#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1000 * 100 + 100;
int n, m, num[Maxn], d[Maxn], NUM, total, par[Maxn];
vector<int> adj[Maxn], cut[Maxn];
bool mark[Maxn], flag;
set<pair<int, int> > CUT;
void DFS(int x) {
  for (int i = 0; i < adj[x].size(); i++)
    if (!num[adj[x][i]]) {
      num[adj[x][i]] = NUM++;
      d[adj[x][i]] = num[adj[x][i]];
      par[adj[x][i]] = x;
      DFS(adj[x][i]);
      d[x] = min(d[x], d[adj[x][i]]);
      if (d[adj[x][i]] > num[x]) CUT.insert(pair<int, int>(x, adj[x][i]));
    } else if (adj[x][i] != par[x])
      d[x] = min(d[x], num[adj[x][i]]);
  return;
}
void dfs(int x, int y) {
  mark[x] = true;
  if (x == y) flag = true;
  if (flag) return;
  for (int i = 0; i < adj[x].size(); i++)
    if (!mark[adj[x][i]]) {
      if (flag) return;
      total += cut[x][i];
      dfs(adj[x][i], y);
      if (flag) return;
      total -= cut[x][i];
    }
  return;
}
int main() {
  ifstream fin("input.txt");
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  NUM = 1;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    cut[x].push_back(0);
    adj[y].push_back(x);
    cut[y].push_back(0);
  }
  num[1] = NUM++;
  d[1] = num[1];
  DFS(1);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < adj[i].size(); j++)
      if (CUT.find(pair<int, int>(i, adj[i][j])) != CUT.end() ||
          CUT.find(pair<int, int>(adj[i][j], i)) != CUT.end())
        cut[i][j] = 1;
  vector<int> out;
  int k;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    for (int j = 1; j <= n; j++) mark[j] = false;
    total = 0;
    flag = false;
    dfs(x, y);
    out.push_back(total);
  }
  for (int i = 1; i <= k; i++) cout << out[i - 1] << endl;
  return 0;
}
