#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename X>
inline X abs(const X& a) {
  return a < 0 ? -a : a;
}
template <typename X>
inline X sqr(const X& a) {
  return a * a;
}
const int INF = INT_MAX / 2;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
const int N = 100 * 1000 + 3;
int n, m;
vector<pair<int, int> > g[N];
pair<int, int> e[N];
inline bool read() {
  if (scanf("%d%d", &n, &m) != 2) return false;
  for (int i = 0; i < int(m); i++) {
    int first, second;
    assert(scanf("%d%d", &first, &second) == 2);
    first--, second--;
    g[first].push_back(make_pair((second), (i)));
    g[second].push_back(make_pair((first), (i)));
    e[i] = make_pair((first), (second));
  }
  return true;
}
int u = 0;
int used[N];
int tin[N], tup[N], T = 0;
int bridge[N];
void dfs(int v, int p) {
  tin[v] = tup[v] = T++;
  used[v] = u;
  for (int i = 0; i < int(int((g[v]).size())); i++) {
    int to = g[v][i].first;
    int id = g[v][i].second;
    if (id == p) continue;
    if (used[to] != u) {
      dfs(to, id);
      tup[v] = min(tup[v], tup[to]);
      if (tup[to] > tin[v]) bridge[id] = true;
    } else
      tup[v] = min(tup[v], tin[to]);
  }
}
vector<int> gr[N];
int c[N], col = 0;
void dfsGr(int v) {
  used[v] = u;
  c[v] = col;
  for (int i = 0; i < int(int((gr[v]).size())); i++) {
    int to = gr[v][i];
    if (used[to] != u) dfsGr(to);
  }
}
const int LOGN = 18;
vector<int> gg[N];
int d[N];
int p[N][LOGN];
int tout[N];
void dfsGG(int v, int pr = -1) {
  tin[v] = T++;
  used[v] = u;
  if (pr == -1)
    p[v][0] = v, d[v] = 0;
  else
    p[v][0] = pr, d[v] = d[pr] + 1;
  for (int i = 1; i <= int(LOGN - 1); i++) p[v][i] = p[p[v][i - 1]][i - 1];
  for (int i = 0; i < int(int((gg[v]).size())); i++) {
    int to = gg[v][i];
    if (to != pr) dfsGG(to, v);
  }
  tout[v] = T++;
}
inline bool parent(int a, int b) {
  return tin[a] <= tin[b] && tout[b] <= tout[a];
}
inline int lca(int a, int b) {
  if (parent(a, b)) return a;
  if (parent(b, a)) return b;
  for (int i = int(LOGN) - 1; i >= 0; i--)
    if (!parent(p[a][i], b)) a = p[a][i];
  int ans = p[a][0];
  assert(parent(ans, a));
  assert(parent(ans, b));
  return ans;
}
inline int dist(int first, int second) {
  return d[first] + d[second] - 2 * d[lca(first, second)];
}
inline void solve() {
  u++;
  for (int i = 0; i < int(n); i++)
    if (used[i] != u) dfs(i, -1);
  for (int i = 0; i < int(m); i++)
    if (!bridge[i]) {
      int first = e[i].first;
      int second = e[i].second;
      gr[first].push_back(second);
      gr[second].push_back(first);
    }
  u++;
  for (int i = 0; i < int(n); i++)
    if (used[i] != u) dfsGr(i), col++;
  for (int i = 0; i < int(m); i++) {
    int first = c[e[i].first];
    int second = c[e[i].second];
    if (first != second) {
      gg[first].push_back(second);
      gg[second].push_back(first);
    }
  }
  int k;
  assert(scanf("%d", &k) == 1);
  u++;
  dfsGG(0);
  for (int i = 0; i < int(col); i++) assert(used[i] == u);
  for (int i = 0; i < int(k); i++) {
    int first, second;
    assert(scanf("%d%d", &first, &second) == 2);
    first--, second--;
    first = c[first];
    second = c[second];
    int ans = dist(first, second);
    printf("%d\n", ans);
  }
}
int main() {
  assert(read());
  solve();
  return 0;
}
