#include <bits/stdc++.h>
using namespace std;
struct Time_Data {
  int in, low;
} T[100001];
struct Edge {
  int s, e;
} E;
int n, m, x, y, timer, used[2001], Bridge_cnt[2001];
bool vis[2001], Is_Bridge[2001][2001];
vector<vector<int> > G;
queue<int> q;
int Min(int, int);
void Find_Bridges();
void DFS(int, int);
void Clear_queue();
int main() {
  scanf("%d%d", &n, &m);
  G.resize(n + 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  Find_Bridges();
  int k, S, F, cnt;
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d%d", &S, &F);
    cnt = 0;
    Clear_queue();
    Bridge_cnt[S] = 0;
    used[S] = i;
    q.push(S);
    while (!q.empty() && used[F] != i) {
      x = q.front();
      q.pop();
      for (int j = 0; j < G[x].size(); j++) {
        y = G[x][j];
        if (used[y] != i) {
          used[y] = i;
          Bridge_cnt[y] = Bridge_cnt[x] + Is_Bridge[x][y];
          q.push(y);
        }
      }
    }
    printf("%d\n", Bridge_cnt[F]);
  }
  return 0;
}
int Min(int x, int y) {
  if (x > y) return y;
  return x;
}
void Clear_queue() {
  while (!q.empty()) q.pop();
}
void Find_Bridges() {
  for (int i = 1; i <= n; i++)
    if (!vis[i]) DFS(i, -1);
}
void DFS(int v, int parent) {
  vis[v] = true;
  T[v].in = T[v].low = ++timer;
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (!vis[u]) {
      DFS(u, v);
      T[v].low = Min(T[v].low, T[u].low);
      if (T[v].in < T[u].low) Is_Bridge[v][u] = Is_Bridge[u][v] = true;
    } else if (u != parent)
      T[v].low = Min(T[v].low, T[u].in);
  }
}
