#include <bits/stdc++.h>
using namespace std;
const int maxn = 300 * 1000, inf = 100000000;
vector<int> v[maxn], u, h;
int mark[maxn], dis[maxn], p[maxn], pwr[maxn], tik[maxn], tt[maxn];
int b[maxn], p2[30], mmin[30][maxn][3], tmin[30][maxn][3], c[maxn];
int n, m, q;
void input() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  cin >> q;
}
void dfs1(int x, int d) {
  mark[x] = 1;
  u.push_back(x);
  dis[x] = d;
  int mh = inf, rh = inf;
  for (int i = 0; i < v[x].size(); i++) {
    if (mark[v[x][i]] == 0) {
      dfs1(v[x][i], d + 1);
      u.push_back(x);
      rh = min(rh, b[v[x][i]]);
    } else
      mh = min(mh, dis[v[x][i]]);
  }
  if (x != 0 && rh >= dis[x] && mh >= dis[x] - 1) tik[x] = 1;
  b[x] = min(rh, mh);
}
void dfs2(int x, int val) {
  tt[x] = 1;
  c[x] = val + tik[x];
  for (int i = 0; i < v[x].size(); i++)
    if (tt[v[x][i]] == 0) dfs2(v[x][i], val + tik[x]);
}
void prepro() {
  for (int i = 0; i < maxn; i++) p[i] = -1;
  for (int i = 0; i < u.size(); i++) {
    p[u[i]] = i;
    h.push_back(dis[u[i]]);
  }
  pwr[1] = 0;
  for (int i = 2; i < maxn; i++) pwr[i] = pwr[i / 2] + 1;
  p2[0] = 1;
  for (int i = 1; i < 30; i++) p2[i] = p2[i - 1] * 2;
  for (int j = 0; j < u.size(); j++) {
    mmin[0][j][0] = h[j];
    mmin[0][j][1] = h[j];
    tmin[0][j][0] = u[j];
    tmin[0][j][1] = u[j];
  }
  for (int i = 1; i < 20; i++)
    for (int j = 0; j < u.size(); j++) {
      if (mmin[i - 1][j][0] <
          mmin[i - 1][min(j + p2[i - 1], int(u.size()) - 1)][0]) {
        mmin[i][j][0] = mmin[i - 1][j][0];
        tmin[i][j][0] = tmin[i - 1][j][0];
      } else {
        mmin[i][j][0] = mmin[i - 1][min(j + p2[i - 1], int(u.size()) - 1)][0];
        tmin[i][j][0] = tmin[i - 1][min(j + p2[i - 1], int(u.size()) - 1)][0];
      }
      if (mmin[i - 1][j][1] < mmin[i - 1][max(j - p2[i - 1], 0)][1]) {
        mmin[i][j][1] = mmin[i - 1][j][1];
        tmin[i][j][1] = tmin[i - 1][j][1];
      } else {
        mmin[i][j][1] = mmin[i - 1][max(j - p2[i - 1], 0)][1];
        tmin[i][j][1] = tmin[i - 1][max(j - p2[i - 1], 0)][1];
      }
    }
}
void query(int x, int y) {
  int w1 = p[x], w2 = p[y], t = abs(w2 - w1) + 1, k = pwr[t];
  if (w1 > w2) swap(w1, w2);
  int lca;
  if (mmin[k][w1][0] < mmin[k][w2][1])
    lca = tmin[k][w1][0];
  else
    lca = tmin[k][w2][1];
  cout << c[x] + c[y] - 2 * c[lca] << endl;
}
void solve() {
  dfs1(0, 0);
  dfs2(0, 0);
  prepro();
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    query(x - 1, y - 1);
  }
}
int main() {
  input();
  solve();
  return 0;
}
