#include <bits/stdc++.h>
using namespace std;
int f[100010], u[100010];
vector<int> cities[100010];
int marked[100010];
int main() {
  int n, m, k;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> f[i] >> u[i];
    cities[f[i]].push_back(i);
    cities[u[i]].push_back(i);
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    int w, s, tax = 0;
    cin >> w >> s;
    memset(marked, -1, sizeof marked);
    for (int j = 0; j < m; j++) {
      queue<int> q;
      q.push(w);
      bool t = false;
      while (!q.empty()) {
        int r = q.front();
        marked[r] = j;
        if (r == s) {
          t = true;
          break;
        }
        for (int t = 0; t < cities[r].size(); t++)
          if (cities[r][t] != j)
            if (marked[u[cities[r][t]]] != j && f[cities[r][t]] == r)
              q.push(u[cities[r][t]]);
            else if (marked[f[cities[r][t]]] != j && u[cities[r][t]] == r)
              q.push(f[cities[r][t]]);
        q.pop();
      }
      if (!t) tax++;
    }
    cout << tax << endl;
  }
}
