#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int M = 10010;
const int K = 510;
const int LIT = 2500;
const long long INF = 1LL << 60;
int n, m, q;
vector<int> r[N], nr[N];
vector<pair<int, int> > qr[N];
int output[N], col[N];
bool vis[N];
set<pair<int, int> > brige;
int cut[N];
int deep[N], ans[N];
void dfs(int idx, int fa, int d) {
  deep[idx] = ans[idx] = d;
  vis[idx] = 1;
  int s = r[idx].size();
  for (int i = 0; i < s; i++) {
    int v = r[idx][i];
    if (v == fa) continue;
    if (vis[v]) {
      ans[idx] = min(ans[idx], deep[v]);
      continue;
    }
    dfs(v, idx, d + 1);
    ans[idx] = min(ans[idx], ans[v]);
    if (ans[v] > d) {
      int a = min(idx, v), b = max(idx, v);
      brige.insert(make_pair(a, b));
    }
    if (ans[v] >= d) cut[idx]++;
  }
  if (fa != -1) cut[idx]++;
}
int cc;
void dfs2(int u, int c) {
  vis[u] = 1;
  col[u] = c;
  int s = r[u].size();
  for (int i = 0; i < s; i++) {
    int v = r[u][i];
    if (vis[v]) continue;
    int a = min(u, v), b = max(u, v);
    if (brige.count(make_pair(a, b))) {
      cc++;
      nr[c].push_back(cc);
      nr[cc].push_back(c);
      dfs2(v, cc);
    } else
      dfs2(v, c);
  }
}
void dfs3(int u, int d) {
  vis[u] = 1;
  deep[u] = d;
  int s = nr[u].size();
  for (int i = 0; i < s; i++) {
    int v = nr[u][i];
    if (vis[v]) continue;
    dfs3(v, d + 1);
  }
}
int check[N], fa[N];
int sea(int a) {
  int mid = N - 1;
  while (1) {
    if (!fa[a]) return a;
    fa[mid] = fa[a];
    mid = a;
    a = fa[a];
  }
}
void uni(int a, int b) {
  a = sea(a);
  b = sea(b);
  if (a == b) return;
  fa[b] = a;
}
void LCA(int u, int fa) {
  int s = nr[u].size();
  for (int i = 0; i < s; i++) {
    int v = nr[u][i];
    if (v == fa) continue;
    LCA(v, u);
    uni(u, v);
  }
  check[u] = 1;
  s = qr[u].size();
  for (int i = 0; i < s; i++) {
    int v = qr[u][i].first, p = qr[u][i].second;
    if (!check[v]) continue;
    int lca = sea(v);
    int res = deep[u] + deep[v] - deep[lca] * 2;
    output[p] = res;
  }
}
void init() {
  memset(col, 0, sizeof(col));
  memset(vis, 0, sizeof(vis));
  memset(cut, 0, sizeof(cut));
  memset(ans, 0, sizeof(ans));
  memset(deep, 0, sizeof(deep));
  brige.clear();
  for (int i = 0; i <= n; i++) {
    r[i].clear(), qr[i].clear();
    nr[i].clear();
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    r[a].push_back(b);
    r[b].push_back(a);
  }
  dfs(1, -1, 0);
  cc = 1;
  memset(vis, 0, sizeof(vis));
  dfs2(1, cc);
  memset(vis, 0, sizeof(vis));
  memset(deep, 0, sizeof(deep));
  dfs3(1, 1);
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a = col[a], b = col[b];
    qr[a].push_back(make_pair(b, i));
    qr[b].push_back(make_pair(a, i));
  }
  memset(fa, 0, sizeof(fa));
  memset(check, 0, sizeof(check));
  LCA(1, -1);
}
void solve() {
  for (int i = 1; i <= q; i++) {
    printf("%d\n", output[i]);
  }
}
int main() {
  while (cin >> n >> m) {
    init();
    solve();
  }
}
