#include <bits/stdc++.h>
template <typename T>
inline void SWAP(T &a, T &b) {
  T tmp = a;
  a = b;
  b = tmp;
}
template <typename T>
inline T ABS(const T &VAL) {
  return VAL < 0 ? -VAL : VAL;
}
template <typename T>
inline T MAX(const T &a, const T &b) {
  return a < b ? b : a;
}
template <typename T>
inline T MIN(const T &a, const T &b) {
  return a < b ? a : b;
}
template <typename T>
inline T SQR(const T &a) {
  return a * a;
}
const int INTinf = 1000000005;
const int nINTinf = 0 - 2147483648;
const long long LLinf = 9223372036854775807LL;
using namespace std;
const int MAXN = 1e5 + 5;
vector<int> way[MAXN];
int timer, t[MAXN], dfsMin[MAXN];
bool used[MAXN];
int n, m;
vector<int> st;
int MAP[MAXN];
vector<pair<int, int> > bridge;
int CNT = 0, l;
vector<int> tin, tout;
vector<vector<int> > up;
vector<int> deep;
void dfs(int v, int p) {
  st.push_back(v);
  used[v] = true;
  t[v] = dfsMin[v] = timer++;
  for (int i = 0; i != way[v].size(); i++) {
    int to = way[v][i];
    if (to == p) continue;
    if (used[to]) {
      dfsMin[v] = min(dfsMin[v], t[to]);
    } else {
      dfs(to, v);
      dfsMin[v] = min(dfsMin[v], dfsMin[to]);
      if (dfsMin[to] > t[v]) {
        bridge.push_back(pair<int, int>(v, to));
        while (st.back() != to) {
          MAP[st.back()] = CNT;
          st.pop_back();
        }
        MAP[st.back()] = CNT;
        st.pop_back();
        CNT++;
      }
    }
  }
}
void dfs2(int v, int p, int dp) {
  deep[v] = dp;
  tin[v] = ++timer;
  up[v][0] = p;
  for (int i = 1; i <= l; i++) {
    up[v][i] = up[up[v][i - 1]][i - 1];
  }
  for (int i = 0; i != way[v].size(); i++) {
    int to = way[v][i];
    if (to != p) {
      dfs2(to, v, dp + 1);
    }
  }
  tout[v] = ++timer;
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = l; i >= 0; --i) {
    if (!upper(up[a][i], b)) {
      a = up[a][i];
    }
  }
  return up[a][0];
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i != m; i++) {
    int q, w;
    scanf("%d %d", &q, &w);
    --q;
    --w;
    way[w].push_back(q);
    way[q].push_back(w);
  }
  timer = 0;
  dfs(0, -1);
  while (!st.empty()) {
    MAP[st.back()] = CNT;
    st.pop_back();
  }
  CNT++;
  for (int i = 0; i != CNT; i++) {
    way[i].clear();
  }
  for (int i = 0; i != bridge.size(); i++) {
    int W1 = MAP[bridge[i].first];
    int W2 = MAP[bridge[i].second];
    assert(W1 != W2);
    way[W1].push_back(W2);
    way[W2].push_back(W1);
  }
  timer = 0;
  tin.resize(CNT);
  tout.resize(CNT);
  deep.resize(CNT);
  up.resize(CNT);
  l = 1;
  while ((1 << l) <= CNT) {
    ++l;
  }
  for (int i = 0; i < CNT; ++i) {
    up[i].resize(l + 1);
  }
  dfs2(0, 0, 0);
  int k;
  scanf("%d", &k);
  for (int i = 0; i != k; i++) {
    int q, w;
    scanf("%d %d", &q, &w);
    --q;
    --w;
    q = MAP[q];
    w = MAP[w];
    int tmp = lca(q, w);
    int ln = deep[q] + deep[w] - 2 * deep[tmp];
    printf("%d\n", ln);
  }
  return 0;
}
