#include <bits/stdc++.h>
using namespace std;
vector<int> a[100005], e[100005];
int dep[100005], low[100005];
int u[100005], g[100005];
int FIND(int x) { return g[x] == x ? x : g[x] = FIND(g[x]); }
void UNION(int x, int y) { g[FIND(x)] = FIND(y); }
void go(int lev, int x, int from = -1) {
  u[x] = 1;
  dep[x] = lev;
  low[x] = lev;
  for (int i = 0; i < (int)a[x].size(); i++) {
    if (!u[a[x][i]]) {
      go(lev + 1, a[x][i], x);
      if (low[a[x][i]] <= lev) {
        UNION(a[x][i], x);
        low[x] = min(low[x], low[a[x][i]]);
      }
    } else if (a[x][i] != from) {
      if (low[a[x][i]] <= lev) {
        UNION(a[x][i], x);
        low[x] = min(low[x], low[a[x][i]]);
      }
    }
  }
}
int ldep[100005];
int lca[100005];
vector<pair<int, int> > q[100005];
int gg[100005];
int v[100005];
int FIND2(int x) { return x == gg[x] ? x : gg[x] = FIND2(gg[x]); }
void UNION2(int x, int y) { gg[FIND2(x)] = FIND2(y); }
void dfs(int x, int from = -1, int lev = 0) {
  v[x] = 1;
  ldep[x] = lev;
  for (int i = 0; i < (int)e[x].size(); i++) {
    int y = e[x][i];
    if (!v[y]) dfs(y, x, lev + 1);
  }
  for (int i = 0; i < (int)q[x].size(); i++) {
    int to = q[x][i].first;
    if (v[to]) lca[q[x][i].second] = ldep[x] + ldep[to] - 2 * ldep[FIND2(to)];
  }
  UNION2(x, from);
  v[x] = 2;
}
int main(void) {
  int n, m, k;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) g[i] = i;
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  scanf("%d", &k);
  for (int i = 1; i <= n; i++) gg[i] = i;
  for (int i = 1; i <= n; i++) {
    if (!u[i]) {
      go(0, i);
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < (int)a[i].size(); j++)
      if (FIND(i) != FIND(a[i][j])) e[FIND(i)].push_back(FIND(a[i][j]));
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = FIND(x);
    y = FIND(y);
    q[x].push_back(make_pair(y, i));
    q[y].push_back(make_pair(x, i));
  }
  dfs(FIND(1));
  for (int i = 0; i < k; i++) printf("%d\n", lca[i]);
  return 0;
}
