#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
void fin() {}
const bool flag = 0;
const int N = 1e5 + 10;
const int K = 17;
vector<int> adj[N];
int fup[N], tin[N], tout[N], tmr;
vector<pii> bridges;
void dfsb(int first = 0, int p = -1) {
  tin[first] = fup[first] = ++tmr;
  for (int to : adj[first]) {
    if (to == p) {
      continue;
    }
    if (tin[to]) {
      fup[first] = min(fup[first], tin[to]);
    } else {
      dfsb(to, first);
      fup[first] = min(fup[first], fup[to]);
      if (fup[to] > tin[first]) {
        bridges.push_back({to, first});
      }
    }
  }
}
int d[N];
void calc(int first = 0, int p = -1) {
  for (int to : adj[first]) {
    if (to != p) {
      d[to] = d[first] + 1;
      calc(to, first);
    }
  }
}
int sum[N], up[K][N];
void dfs(int first = 0, int p = 0) {
  tin[first] = ++tmr;
  up[0][first] = p;
  for (int h = 1; h < K; ++h) {
    up[h][first] = up[h - 1][up[h - 1][first]];
  }
  for (int to : adj[first]) {
    if (to != p) {
      sum[to] += sum[first];
      dfs(to, first);
    }
  }
  tout[first] = tmr;
}
bool upper(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tout[v]; }
int lca(int u, int v) {
  if (upper(u, v)) {
    return u;
  }
  if (upper(v, u)) {
    return v;
  }
  for (int h = K - 1; ~h; --h) {
    if (!upper(up[h][u], v)) {
      u = up[h][u];
    }
  }
  return up[0][u];
}
int p[N], sz[N];
int fnd(int first) {
  if (first == p[first]) {
    return first;
  }
  return p[first] = fnd(p[first]);
}
bool unite(int a, int b) {
  a = fnd(a);
  b = fnd(b);
  if (a == b) {
    return false;
  }
  if (sz[a] > sz[b]) {
    swap(a, b);
  }
  p[a] = b;
  sz[b] += sz[a];
  return true;
}
void ma1n() {
  int n, m;
  cin >> n >> m;
  vector<pii> e;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    e.push_back({u, v});
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfsb();
  for (int i = 0; i < n; ++i) {
    p[i] = i, sz[i] = 1;
    adj[i].clear();
  }
  for (pii first : bridges) {
    int u = first.first, v = first.second;
    if (unite(u, v)) {
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
  }
  for (pii first : e) {
    int u = first.first, v = first.second;
    if (unite(u, v)) {
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
  }
  calc();
  for (pii first : bridges) {
    int u = first.first, v = first.second;
    if (d[u] < d[v]) {
      swap(u, v);
    }
    sum[u]++;
  }
  tmr = 0;
  dfs();
  int q;
  cin >> q;
  for (int u, v; q--;) {
    cin >> u >> v;
    u--, v--;
    cout << sum[u] + sum[v] - sum[lca(u, v)] * 2 << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr), fin();
  int ts = 1;
  if (flag) {
    cin >> ts;
  }
  while (ts--) {
    ma1n();
  }
  return 0;
}
