#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int id[N], low[N], bcc[N];
vector<int> a[N];
void BCC(int u, int p) {
  static int last = 0;
  static stack<int> S;
  id[u] = last++;
  low[u] = u;
  S.push(u);
  for (vector<int>::iterator it = a[u].begin(); it != a[u].end(); ++it) {
    int v = *it;
    if (v == p) continue;
    if (id[v] == -1) BCC(v, u);
    if (id[low[v]] < id[low[u]]) low[u] = low[v];
  }
  if (low[u] == u) {
    while (S.top() != u) {
      bcc[S.top()] = u;
      S.pop();
    }
    bcc[u] = u;
    S.pop();
  }
}
vector<int> b[N];
vector<pair<int, int> > c[N];
int dep[N];
bool flag[N];
int f[N];
int ans[N];
int find(int x) {
  if (f[x] != f[f[x]]) f[x] = find(f[x]);
  return f[x];
}
void LCA(int u) {
  f[u] = u;
  flag[u] = true;
  for (vector<int>::iterator it = b[u].begin(); it != b[u].end(); ++it) {
    int v = *it;
    if (flag[v]) continue;
    LCA(v);
    f[find(v)] = find(u);
  }
  for (vector<pair<int, int> >::iterator it = c[u].begin(); it != c[u].end();
       ++it) {
    int v = it->first;
    if (flag[v]) {
      ans[it->second] = dep[u] + dep[v] - 2 * dep[find(v)];
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  while (m--) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  fill(id, id + n, -1);
  BCC(0, -1);
  for (int i = 0; i < n; ++i) {
    for (vector<int>::iterator it = a[i].begin(); it != a[i].end(); ++it) {
      int j = *it;
      if (bcc[i] != bcc[j]) b[bcc[i]].push_back(bcc[j]);
    }
  }
  int L;
  scanf("%d", &L);
  for (int i = 0; i < L; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    x = bcc[x];
    y = bcc[y];
    c[x].push_back(pair<int, int>(y, i));
    c[y].push_back(pair<int, int>(x, i));
  }
  queue<int> Q;
  Q.push(bcc[0]);
  fill(flag, flag + n, false);
  flag[bcc[0]] = true;
  while (!Q.empty()) {
    int i = Q.front();
    Q.pop();
    for (vector<int>::iterator it = b[i].begin(); it != b[i].end(); ++it) {
      int j = *it;
      if (!flag[j]) {
        flag[j] = true;
        Q.push(j);
        dep[j] = dep[i] + 1;
      }
    }
  }
  fill(flag, flag + n, false);
  LCA(bcc[0]);
  for (int i = 0; i < L; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
