#include <bits/stdc++.h>
using namespace std;
inline long long bip(long long x, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x) % mod;
    }
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
const int ppr[] = {257, 263};
const long long INF = 2e18;
const int inf = 2e9;
const int mod = int(998244353);
const int N = 1e6 + 123;
const long double pi = 3.141592653589793238462643;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int n, m, q, fup[N], timer, tinn[N], c[N], tin[N], tout[N], p[20][N], k, d[N];
vector<int> g[N], gr[N];
bool used[N], u[N];
set<int> b[N], r[N];
void dffs(int v, int p = -1) {
  used[v] = true;
  tinn[v] = fup[v] = timer++;
  for (size_t i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (to == p) continue;
    if (used[to])
      fup[v] = min(fup[v], tinn[to]);
    else {
      dffs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tinn[v]) {
        b[v].insert(to);
        b[to].insert(v);
      }
    }
  }
}
void dfss(int v, int p = -1) {
  c[v] = k;
  u[v] = 1;
  for (auto to : g[v]) {
    if (!u[to]) {
      if (b[v].find(to) == b[v].end()) dfss(to, v);
    } else {
      if (b[v].find(to) != b[v].end() && r[c[v]].find(c[to]) == r[c[v]].end()) {
        gr[c[v]].push_back(c[to]);
        gr[c[to]].push_back(c[v]);
        r[c[v]].insert(c[to]);
        r[c[to]].insert(c[v]);
      }
    }
  }
}
void dfs(int v, int pr = 0) {
  d[v] = d[pr] + 1;
  p[0][v] = pr;
  tin[v] = ++timer;
  for (int i = 1; i < 18; i++) p[i][v] = p[i - 1][p[i - 1][v]];
  for (auto to : gr[v]) {
    if (to == pr) continue;
    dfs(to, v);
  }
  tout[v] = ++timer;
}
inline bool isp(int x, int y) {
  return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}
inline int lca(int x, int y) {
  if (isp(x, y)) return x;
  if (isp(y, x)) return y;
  for (int i = 17; i >= 0; i--)
    if (p[i][x] && !isp(p[i][x], y)) x = p[i][x];
  return p[0][x];
}
inline int dist(int x, int y) {
  int p = lca(x, y);
  return d[x] + d[y] - d[p] * 2;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  while (m--) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  dffs(1);
  for (int i = 1; i <= n; i++)
    if (!u[i]) k++, dfss(i);
  timer = 0;
  dfs(1);
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    cout << dist(c[x], c[y]) << '\n';
  }
  return 0;
}
