#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int maxm = 2005;
struct Tedge {
  int y, next, opp, f;
  Tedge() {}
  Tedge(int a, int b, int c) {
    y = a;
    next = b;
    opp = c;
    f = 0;
  }
} adj[maxm << 1];
int fch[maxn];
bool vis[maxn];
int s[maxn], t[maxn];
int ans[maxn];
int n, m, ms, K;
void add_edge(int x, int y, int c) {
  adj[++ms] = Tedge(y, fch[x], c);
  fch[x] = ms;
}
void init() {
  scanf("%d%d", &n, &m);
  ms = 0;
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, v, ms + 2);
    add_edge(v, u, ms);
  }
  scanf("%d", &K);
  for (int i = 1; i <= K; i++) scanf("%d%d", &s[i], &t[i]);
}
void dfs(int t) {
  vis[t] = 1;
  for (int i = fch[t]; i; i = adj[i].next)
    if (!adj[i].f && !vis[adj[i].y]) dfs(adj[i].y);
}
void check() {
  for (int i = 1; i <= K; i++)
    if ((vis[s[i]] && !vis[t[i]]) || (vis[t[i]] && !vis[s[i]])) ans[i]++;
}
void work() {
  for (int i = 1; i <= n; i++)
    for (int j = fch[i]; j; j = adj[j].next)
      if (adj[j].y > i) {
        int u = i, v = adj[j].y;
        adj[j].f = adj[adj[j].opp].f = 1;
        memset(vis, 0, sizeof(vis));
        dfs(1);
        check();
        adj[j].f = adj[adj[j].opp].f = 0;
      }
}
void print() {
  for (int i = 1; i <= K; i++) printf("%d\n", ans[i]);
}
int main() {
  init();
  work();
  print();
  return 0;
}
