#include <bits/stdc++.h>
using namespace std;
struct DJS {
  int fa[100010];
  void init(int n) {
    for (int i = 1; i <= n; i++) fa[i] = i;
  }
  int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
  void Union(int a, int b) { fa[Find(a)] = Find(b); }
} bcc;
int n, m;
vector<int> e[100010];
void input() {
  scanf("%d%d", &n, &m);
  int a, b;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
}
int vis[100010], low[100010], dfn[100010];
set<pair<int, int> > bri;
void go(int p, int f, int lv) {
  vis[p] = 1;
  low[p] = dfn[p] = lv;
  for (__typeof((e[p]).begin()) it = (e[p]).begin(); it != (e[p]).end(); it++)
    if (*it != f) {
      if (vis[*it])
        low[p] = min(low[p], dfn[*it]);
      else {
        go(*it, p, lv + 1);
        low[p] = min(low[p], low[*it]);
        if (low[*it] > dfn[p]) bri.insert(make_pair(p, *it));
      }
    }
}
vector<int> ee[100010];
int fa[100010][17], dep[100010];
void dfs(int p, int f, int lv) {
  fa[p][0] = f;
  dep[p] = lv;
  for (int i = 1; i < 17; i++) fa[p][i] = fa[fa[p][i - 1]][i - 1];
  for (__typeof((ee[p]).begin()) it = (ee[p]).begin(); it != (ee[p]).end();
       it++)
    if (*it != f) dfs(*it, p, lv + 1);
}
void build() {
  bcc.init(n);
  go(1, 0, 1);
  for (int i = 1; i <= n; i++)
    for (__typeof((e[i]).begin()) it = (e[i]).begin(); it != (e[i]).end(); it++)
      if (!bri.count(make_pair(i, *it)) && !bri.count(make_pair(*it, i)))
        bcc.Union(i, *it);
  for (__typeof((bri).begin()) it = (bri).begin(); it != (bri).end(); it++) {
    int a = bcc.Find(it->first);
    int b = bcc.Find(it->second);
    ee[a].push_back(b);
    ee[b].push_back(a);
  }
  dfs(bcc.Find(1), 0, 1);
}
inline int bit(int x, int i) { return (x >> i) & 1; }
int lca(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  for (int i = 16; i >= 0; i--)
    if (bit(dep[a] - dep[b], i)) a = fa[a][i];
  if (a == b) return a;
  for (int i = 16; i >= 0; i--)
    if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i];
  return fa[a][0];
}
void solve() {
  int q, a, b;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &a, &b);
    a = bcc.Find(a);
    b = bcc.Find(b);
    int c = lca(a, b);
    printf("%d\n", dep[a] + dep[b] - 2 * dep[c]);
  }
}
int main() {
  input();
  build();
  solve();
  return 0;
}
