#include <bits/stdc++.h>
using namespace std;
const int maxn = 420000, maxlen = 502 * 502 + 20, consta = 1050,
          maxi = consta + 4, big = 10000000, magic = 239, magic1 = 359;
const long long INF = 1000000000;
const char BLANK = '-', FULL = '#';
int a[maxn], b[maxn];
vector<pair<int, int> > e[maxn];
vector<int> en[maxn];
int most[maxn];
int usd[maxn], ins[maxn], out[maxn], miv[maxn], botva1 = 1, len = 1;
int me[maxn], p[maxn][23], cnt[maxn];
void dfs(int v, int par = -1) {
  ++botva1;
  ins[v] = botva1;
  usd[v] = 1;
  miv[v] = botva1;
  for (int i = 0; i < e[v].size(); ++i)
    if (!usd[e[v][i].first]) {
      dfs(e[v][i].first, v);
      if (miv[e[v][i].first] > ins[v]) most[e[v][i].second] = 1;
      miv[v] = min(miv[v], miv[e[v][i].first]);
    } else if (e[v][i].first != par) {
      miv[v] = min(miv[v], ins[e[v][i].first]);
    }
  out[v] = botva1;
}
void dfs2(int v) {
  usd[v] = 2;
  me[v] = len;
  for (int i = 0; i < e[v].size(); ++i)
    if (most[e[v][i].second] == 0 && usd[e[v][i].first] != 2) {
      dfs2(e[v][i].first);
    }
}
vector<int> low;
void dfso(int v, int pa = -1) {
  p[v][0] = pa;
  if (pa != -1) cnt[v] = cnt[pa] + 1;
  usd[v] = 3;
  low.push_back(v);
  for (int i = 0; i < en[v].size(); ++i)
    if (usd[en[v][i]] != 3) dfso(en[v][i], v);
}
int main() {
  int n, m, k, af, bf;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &af, &bf);
    e[af].push_back(make_pair(bf, i));
    e[bf].push_back(make_pair(af, i));
  }
  dfs(1);
  for (int i = 1; i <= n; ++i)
    if (usd[i] != 2) {
      dfs2(i);
      ++len;
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < e[i].size(); ++j)
      en[me[i]].push_back(me[e[i][j].first]);
  dfso(1);
  for (int jj = 0; jj < low.size(); ++jj) {
    int i = low[jj];
    for (int j = 1; j < 21; ++j) {
      if (p[i][j - 1] == -1)
        p[i][j] = -1;
      else
        p[i][j] = p[p[i][j - 1]][j - 1];
    }
  }
  cin >> k;
  for (int i = 0; i < k; ++i) {
    scanf("%d%d", &af, &bf);
    af = me[af], bf = me[bf];
    int l = 0, r = min(cnt[af], cnt[bf]), m, v, w, nd;
    while (l < r) {
      m = (l + r + 1) >> 1;
      v = af;
      nd = cnt[af] - m;
      for (int j = 0; j < 22; ++j)
        if ((1 << j) & nd) v = p[v][j];
      w = v;
      v = bf;
      nd = cnt[bf] - m;
      for (int j = 0; j < 22; ++j)
        if ((1 << j) & nd) v = p[v][j];
      if (v == w) {
        l = m;
      } else {
        r = m - 1;
      }
    }
    if (cnt[af] == l || cnt[bf] == l)
      printf("%d\n", abs(cnt[af] - cnt[bf]));
    else
      printf("%d\n", cnt[af] + cnt[bf] - 2 * l);
  }
}
