#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2000 + 5;
const int MaxM = 2000 + 5;
const int MaxK = 2000 + 5;
int N, M, K, Cnt[MaxK], First[MaxK], Second[MaxK], EdgeFirst[MaxM],
    EdgeSecond[MaxM], Color[MaxN];
bool Visited[MaxN];
set<int> E[MaxN];
inline void SolveEasyAndMedium(void) {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    int idx, idy;
    scanf("%d %d", &idx, &idy);
    idx--;
    idy--;
    E[idx].insert(idy);
    E[idy].insert(idx);
    EdgeFirst[i] = idx;
    EdgeSecond[i] = idy;
  }
  scanf("%d", &K);
  for (int i = 0; i < K; i++) {
    int idx, idy;
    scanf("%d %d", &idx, &idy);
    idx--;
    idy--;
    First[i] = idx;
    Second[i] = idy;
  }
  for (int i = 0; i < M; i++) {
    int idx = EdgeFirst[i];
    int idy = EdgeSecond[i];
    E[idx].erase(idy);
    E[idy].erase(idx);
    memset(Color, 0, sizeof(Color));
    memset(Visited, false, sizeof(Visited));
    int CurrColor = 0;
    for (int i = 0; i < N; i++) {
      if ((i != idx) && (i != idy)) continue;
      if (Visited[i]) continue;
      queue<int> Q;
      Visited[i] = true;
      Color[i] = ++CurrColor;
      Q.push(i);
      while (!Q.empty()) {
        int Curr = Q.front();
        Q.pop();
        for (set<int>::iterator it = E[Curr].begin(); it != E[Curr].end();
             it++) {
          int j = *it;
          if (Visited[j]) continue;
          if (E[Curr].find(j) == E[Curr].end()) continue;
          Q.push(j);
          Visited[j] = true;
          Color[j] = CurrColor;
        }
      }
    }
    for (int i = 0; i < K; i++)
      if (Color[First[i]] != Color[Second[i]]) Cnt[i]++;
    E[idx].insert(idy);
    E[idy].insert(idx);
  }
  for (int i = 0; i < K; i++) printf("%d\n", Cnt[i]);
  exit(0);
}
int main(void) {
  SolveEasyAndMedium();
  return 0;
}
