#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
struct LCA {
  int n;
  vector<int> order;
  int h[100001];
  bool used[100001];
  int first[100001];
  int t[4 * (100001 * 2) + 1];
  int lca(int a, int b);
  int rmq(int l, int r, int i, int tl, int tr);
  void build_rmq(int i, int l, int r);
  void dfs(const vector<vector<int> >& g, int v, int d);
  void dfs_iter(const vector<vector<int> >& g, int root);
  void prepare(const vector<vector<int> >& g, int root);
};
int LCA::lca(int a, int b) {
  int l = first[a], r = first[b];
  if (l > r) swap(l, r);
  return rmq(l, r, 1, 0, (int)((order).size()) - 1);
}
int LCA::rmq(int l, int r, int i, int tl, int tr) {
  if (l == tl && r == tr) return t[i];
  int m = (tl + tr) / 2;
  if (r <= m)
    return rmq(l, r, i * 2, tl, m);
  else if (l > m)
    return rmq(l, r, i * 2 + 1, m + 1, tr);
  int v1 = rmq(l, m, i * 2, tl, m);
  int v2 = rmq(m + 1, r, i * 2 + 1, m + 1, tr);
  return h[v1] < h[v2] ? v1 : v2;
}
void LCA::build_rmq(int i, int l, int r) {
  if (l == r) {
    t[i] = order[l];
    return;
  }
  int m = (l + r) / 2;
  build_rmq(i * 2, l, m);
  build_rmq(i * 2 + 1, m + 1, r);
  t[i] = h[t[i * 2]] < h[t[i * 2 + 1]] ? t[i * 2] : t[i * 2 + 1];
}
void LCA::dfs(const vector<vector<int> >& g, int v, int d) {
  used[v] = true;
  h[v] = d;
  order.push_back(v);
  for (int i = 0, _n = ((int)((g[v]).size())); i < _n; ++i)
    if (!used[g[v][i]]) {
      dfs(g, g[v][i], d + 1);
      order.push_back(v);
    }
}
void LCA::dfs_iter(const vector<vector<int> >& g, int root) {
  stack<int> s;
  s.push(root);
  h[root] = 1;
  while (!s.empty()) {
    int v = s.top();
    s.pop();
    if (used[v])
      order.push_back(v);
    else {
      order.push_back(v);
      used[v] = true;
      for (int i = 0, _n = ((int)((g[v]).size())); i < _n; ++i) {
        h[g[v][i]] = h[v] + 1;
        s.push(v);
        s.push(g[v][i]);
      }
    }
  }
}
void LCA::prepare(const vector<vector<int> >& g, int root) {
  n = (int)((g).size());
  memset((used), (0), sizeof((used)));
  order.clear();
  order.reserve(2 * n);
  dfs(g, root, 1);
  build_rmq(1, 0, (int)((order).size()) - 1);
  memset(first, -1, sizeof(first));
  for (int i = 0, _n = ((int)((order).size())); i < _n; ++i)
    if (first[order[i]] == -1) first[order[i]] = i;
}
int n, m;
vector<int> g[100000];
bool used[100000];
int CNT, IN[100000], UP[100000];
set<pair<int, int> > B;
vector<vector<int> > cc;
int col[100000];
vector<vector<int> > G;
LCA lca;
int H[100000];
pair<int, int> NORM(pair<int, int> a) {
  if (a.first > a.second) swap(a.first, a.second);
  return a;
}
void dfs(int v, int p = -1) {
  used[v] = true;
  IN[v] = UP[v] = CNT++;
  for (int i = 0, _n = ((int)((g[v]).size())); i < _n; ++i) {
    int to = g[v][i];
    if (to == p) continue;
    if (used[to])
      UP[v] = min(UP[v], IN[to]);
    else {
      dfs(to, v);
      UP[v] = min(UP[v], UP[to]);
      if (UP[to] > IN[v]) B.insert(NORM(pair<int, int>(to, v)));
    }
  }
}
void addCC(int v) {
  if (used[v]) return;
  used[v] = true;
  cc.back().push_back(v);
  col[v] = (int)((cc).size()) - 1;
  for (int i = 0, _n = ((int)((g[v]).size())); i < _n; ++i) {
    int v2 = g[v][i];
    if (B.find(NORM(pair<int, int>(v, v2))) != B.end()) continue;
    addCC(v2);
  }
}
void fillH(int v, int v0, int h) {
  H[v] = h;
  for (int i = 0, _n = ((int)((G[v]).size())); i < _n; ++i) {
    int i2 = G[v][i];
    if (i2 == v0) continue;
    fillH(i2, v, h + 1);
  }
}
void solution() {
  scanf("%d %d", &n, &m);
  for (int i = 0, _n = (m); i < _n; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  CNT = 0;
  for (int i = 0, _n = (n); i < _n; ++i) used[i] = false;
  for (int i = 0, _n = (n); i < _n; ++i)
    if (!used[i]) dfs(i);
  memset((used), (0), sizeof((used)));
  for (int i = 0, _n = (n); i < _n; ++i)
    if (!used[i]) {
      cc.push_back(vector<int>());
      addCC(i);
    }
  G.resize((int)((cc).size()));
  for (int i = 0, _n = (n); i < _n; ++i)
    for (int j = 0, _n = ((int)((g[i]).size())); j < _n; ++j) {
      int i2 = g[i][j];
      if (B.find(NORM(pair<int, int>(i, i2))) == B.end()) continue;
      int c1 = col[i];
      int c2 = col[i2];
      if (c1 == c2) continue;
      G[c1].push_back(c2);
      G[c2].push_back(c1);
    }
  for (int i = 0, _n = ((int)((G).size())); i < _n; ++i) {
    sort((G[i]).begin(), (G[i]).end());
    G[i].erase(unique((G[i]).begin(), (G[i]).end()), G[i].end());
  }
  lca.prepare(G, 0);
  fillH(0, -1, 0);
  int k;
  scanf("%d", &k);
  for (int i = 0, _n = (k); i < _n; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    int col1 = col[a];
    int col2 = col[b];
    if (col1 == col2) {
      printf("0\n");
      continue;
    }
    int L = lca.lca(col1, col2);
    int ret = 0;
    if (L == col1)
      ret = H[col2] - H[col1];
    else if (L == col2)
      ret = H[col1] - H[col2];
    else
      ret = H[col1] - H[L] + H[col2] - H[L];
    printf("%d\n", ret);
  }
}
int main() {
  solution();
  return 0;
}
