#include <bits/stdc++.h>
using namespace std;
typedef struct stown {
  struct stown** next;
  int* n;
  int nn;
  struct stown** dnext;
  int* dn;
  int dnn;
  int pos;
} town;
int* resa;
int* der;
int resl;
int dera(town* town1) {
  if (town1->pos == 1) {
    return 0;
  } else {
    int a;
    town1->pos = 1;
    for (int i = 0; i < town1->nn; i++) {
      a = dera(town1->next[i]);
      if (a == 1) {
        der[town1->n[i]] = 1;
        resa[town1->n[i]] = 1;
      }
    }
    return 1;
  }
}
int obh1(town* town1, town* town2) {
  int res = 0;
  if (town1 == town2) {
    return 1;
  } else if (town1->pos == 1) {
    return 0;
  } else {
    int a;
    res = 0;
    town1->pos = 1;
    for (int i = 0; i < town1->dnn; i++) {
      a = obh1(town1->dnext[i], town2);
      if (a == 1) {
        resa[town1->dn[i]] = 0;
        town1->pos = 0;
        return 1;
      }
      res += a;
    }
    town1->pos = 0;
    return res;
  }
}
int obh2(town* town1, town* town2) {
  int res = 0;
  if (town1 == town2) {
    return 1;
  } else if (town1->pos == 1) {
    return 0;
  } else {
    int a;
    res = 0;
    town1->pos = 1;
    for (int i = 0; i < town1->dnn; i++) {
      a = obh2(town1->dnext[i], town2);
      if (a == 1 && resa[town1->dn[i]] == 1) {
        resl++;
        town1->pos = 0;
        return 1;
      }
      res += a;
    }
    town1->pos = 0;
    return res;
  }
}
int main() {
  int s, l;
  int n;
  int m;
  int *a, *b;
  int res;
  int i, j;
  int k;
  town* arr;
  cin >> n >> m;
  a = new int[m];
  der = new int[m];
  b = new int[m];
  resa = new int[m];
  arr = new town[n];
  for (i = 0; i < n; i++) {
    arr[i].next = new town*[m];
    arr[i].dnext = new town*[m];
    arr[i].n = new int[m];
    arr[i].dn = new int[m];
    arr[i].nn = 0;
    arr[i].dnn = 0;
    arr[i].pos = 0;
  }
  for (i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    resa[i] = 0;
    der[i] = 0;
    arr[a[i] - 1].next[arr[a[i] - 1].nn] = &arr[b[i] - 1];
    arr[a[i] - 1].n[arr[a[i] - 1].nn] = i;
    arr[b[i] - 1].next[arr[b[i] - 1].nn] = &arr[a[i] - 1];
    arr[b[i] - 1].n[arr[b[i] - 1].nn] = i;
    arr[b[i] - 1].nn++;
    arr[a[i] - 1].nn++;
  }
  dera(&arr[0]);
  for (i = 0; i < m; i++) {
    if (der[i] == 1) {
      arr[a[i] - 1].dnext[arr[a[i] - 1].dnn] = &arr[b[i] - 1];
      arr[a[i] - 1].dn[arr[a[i] - 1].dnn] = i;
      arr[b[i] - 1].dnext[arr[b[i] - 1].dnn] = &arr[a[i] - 1];
      arr[b[i] - 1].dn[arr[b[i] - 1].dnn] = i;
      arr[b[i] - 1].dnn++;
      arr[a[i] - 1].dnn++;
    }
  }
  for (i = 0; i < n; i++) {
    arr[i].pos = 0;
  }
  for (i = 0; i < m; i++) {
    if (der[i] == 0) obh1(&arr[a[i] - 1], &arr[b[i] - 1]);
  }
  int neobh = 0;
  cin >> k;
  for (i = 0; i < k; i++) {
    cin >> s >> l;
    resl = 0;
    obh2(&arr[s - 1], &arr[l - 1]);
    cout << resl << endl;
  }
  return 0;
}
