#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  int sign = 0;
  int c = getchar();
  for (; !isdigit(c); c = getchar()) {
    sign |= c == '-';
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  return sign ? -x : x;
}
void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x / 10) {
    write(x / 10);
  }
  putchar(x % 10 + '0');
}
const int mv = 112345;
const int me = 2 * mv;
int from[me], to[me], ant[me], adj[mv], z;
bool bridge[me];
int dfs_num[mv], dfs_low[mv], dfs_parent[mv];
int dfsNumberCounter, dfsRoot, rootChildren;
int s[mv], l[mv];
void add(int u, int v) {
  to[z] = v;
  from[z] = u;
  ant[z] = adj[u];
  adj[u] = z++;
  swap(u, v);
  to[z] = v;
  from[z] = u;
  ant[z] = adj[u];
  adj[u] = z++;
}
void artPointAndBridge(int u) {
  dfs_low[u] = dfs_num[u] = dfsNumberCounter++;
  for (int i = adj[u]; ~i; i = ant[i]) {
    int v = to[i];
    if (dfs_num[v] == -1) {
      dfs_parent[v] = u;
      if (u == dfsRoot) rootChildren++;
      artPointAndBridge(v);
      if (dfs_low[v] > dfs_num[u]) {
        bridge[i] = bridge[i ^ 1] = true;
      }
      dfs_low[u] = min(dfs_low[u], dfs_low[v]);
    } else if (v != dfs_parent[u]) {
      dfs_low[u] = min(dfs_low[u], dfs_num[v]);
    }
  }
}
int dist[112345];
void bfs(int k) {
  int src = s[k];
  int dest = l[k];
  deque<int> Q;
  Q.push_back(src);
  dist[src] = 0;
  while (Q.size()) {
    int u = Q.front();
    Q.pop_front();
    for (int i = adj[u]; ~i; i = ant[i]) {
      int v = to[i];
      if (dist[v] == -1) {
        if (bridge[i]) {
          dist[v] = dist[u] + 1;
          Q.push_back(v);
        } else {
          dist[v] = dist[u];
          Q.push_front(v);
        }
      }
      if (v == dest) return;
    }
  }
}
int dfnum[mv];
int inv_dfnum[mv];
int pai[mv];
int h[mv];
int I[mv];
int L[mv];
int depth[mv];
int A[mv];
vector<int> ADJ[mv];
void dfs0(int u, int p, int d) {
  static int num = 0;
  depth[u] = d;
  dfnum[u] = ++num;
  inv_dfnum[num] = u;
  h[num] = __builtin_ctz(num) + 1;
  pai[num] = dfnum[p];
  int max_hI = -1, max_I;
  for (auto v : ADJ[u]) {
    if (v != p) {
      dfs0(v, u, d + 1);
      if (max_hI < h[I[dfnum[v]]]) {
        max_hI = h[I[dfnum[v]]];
        max_I = I[dfnum[v]];
      }
    }
  }
  if (h[dfnum[u]] > max_hI) {
    I[dfnum[u]] = dfnum[u];
  } else {
    I[dfnum[u]] = max_I;
  }
  L[I[dfnum[u]]] = dfnum[u];
}
void dfs1(int u, int p) {
  A[dfnum[u]] = A[dfnum[p]];
  A[dfnum[u]] |= 1 << (h[I[dfnum[u]]] - 1);
  for (auto v : ADJ[u]) {
    if (v != p) {
      dfs1(v, u);
    }
  }
}
int enter_node(int x, int j) {
  int l = __builtin_ctz(A[x]) + 1;
  if (l == j) {
    return x;
  } else {
    int k = 32 - __builtin_clz(A[x] & ~((~0) << (j - 1)));
    int Iw = (I[x] & ((~0) << k)) | (1 << (k - 1));
    return pai[L[Iw]];
  }
}
int lca(int x, int y) {
  x = dfnum[x];
  y = dfnum[y];
  int hb = 32 - __builtin_clz(I[x] ^ I[y]);
  hb = max(hb, max(__builtin_ctz(I[x]), __builtin_ctz(I[y]) + 1));
  int j = __builtin_ctz((A[x] & A[y]) & ((~0) << (hb - 1))) + 1;
  int xx = enter_node(x, j);
  int yy = enter_node(y, j);
  return xx < yy ? inv_dfnum[xx] : inv_dfnum[yy];
}
int comp[mv], ptr;
void dfs2(int u) {
  if (comp[u]) return;
  comp[u] = ptr;
  for (int i = adj[u]; ~i; i = ant[i]) {
    if (bridge[i]) continue;
    dfs2(to[i]);
  }
}
void rebuild(int n) {
  for (int i = 1; i <= n; ++i) {
    ++ptr;
    dfs2(i);
  }
  for (int i = 0; i < z; i += 2) {
    if (bridge[i]) {
      int u = comp[from[i]];
      int v = comp[to[i]];
      ADJ[u].push_back(v);
      ADJ[v].push_back(u);
    }
  }
}
int main() {
  memset(adj, -1, sizeof adj);
  memset(dfs_num, -1, sizeof dfs_num);
  memset(dfs_parent, -1, sizeof dfs_parent);
  int n = read(), m = read();
  for (int i = 0; i < m; ++i) {
    int a = read(), b = read();
    add(a, b);
  }
  for (int i = 1; i <= n; ++i) {
    if (dfs_num[i] == -1) {
      dfsRoot = 1;
      rootChildren = 0;
      artPointAndBridge(i);
    }
  }
  int k = read();
  for (int i = 1; i <= k; ++i) {
    s[i] = read();
    l[i] = read();
  }
  rebuild(n);
  dfs0(1, 0, 0);
  dfs1(1, 0);
  for (int i = 1; i <= k; ++i) {
    int u = comp[s[i]];
    int v = comp[l[i]];
    int x = lca(u, v);
    int dist = depth[u] + depth[v] - 2 * depth[x];
    write(dist);
    putchar('\n');
  }
  return 0;
}
