#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
template <class T>
inline T sqr(T x) {
  return x * x;
}
int n, m, k;
pair<int, int> edge[1 << 17];
vector<vector<int> > g;
pair<int, int> a[1 << 17];
pair<int, int> forb;
int comp[1 << 11];
int ans[1 << 11] = {0};
void dfs(int v, int cnt) {
  comp[v] = cnt;
  for (int i = 0; i < (int)((g[v]).size()); ++i) {
    int to = g[v][i];
    pair<int, int> cur = make_pair(v, to);
    if (v > to) swap(cur.first, cur.second);
    if (cur == forb) continue;
    if (comp[to] == -1) dfs(to, cnt);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    if (x > y) swap(x, y);
    edge[i] = make_pair(x, y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  scanf("%d", &k);
  for (int i = 0; i < k; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    a[i] = make_pair(x, y);
  }
  for (int i = 0; i < m; ++i) {
    forb = edge[i];
    memset(comp, -1, sizeof comp);
    int cnt = 0;
    for (int j = 0; j < n; ++j)
      if (comp[j] == -1) dfs(j, cnt++);
    for (int j = 0; j < k; ++j) {
      int x = a[j].first;
      int y = a[j].second;
      if (comp[x] != comp[y]) ++ans[j];
    }
  }
  for (int i = 0; i < k; ++i) printf("%d\n", ans[i]);
  return 0;
}
