#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v;
  Edge(int _u, int _v) : u(_u), v(_v) {}
  bool operator<(const Edge& e) const {
    if (u != e.u) return u < e.u;
    return v < e.v;
  }
};
vector<vector<int> > adj;
class BiconnectedComponent {
  int N;
  int dfs_time;
  int root;
  void _dfs(int u);

 public:
  vector<Edge> bridges;
  vector<int> dfs_order;
  vector<int> low;
  vector<int> dfs_level;
  vector<int> par;
  BiconnectedComponent(int _N) : N(_N) { adj = vector<vector<int> >(N); }
  void run();
};
void BiconnectedComponent::_dfs(int u) {
  dfs_order[u] = low[u] = ++dfs_time;
  for (int j = 0; j < adj[u].size(); ++j) {
    int v = adj[u][j];
    if (par[u] == v) continue;
    if (dfs_order[v] == 0) {
      dfs_level[v] = dfs_level[u] + 1;
      par[v] = u;
      _dfs(v);
      if (u == root) {
      } else {
        if (low[v] >= dfs_order[u]) {
        }
      }
      if (low[v] > dfs_order[u]) bridges.push_back(Edge(u, v));
      low[u] = min(low[u], low[v]);
    } else if (dfs_level[v] < dfs_level[u] - 1) {
      low[u] = min(low[u], dfs_order[v]);
    }
  }
}
void BiconnectedComponent::run() {
  N = adj.size();
  bridges.clear();
  dfs_order = vector<int>(N, 0);
  low = vector<int>(N, 0);
  dfs_level = vector<int>(N, 0);
  par = vector<int>(N, -1);
  dfs_time = 0;
  for (int u = 0; u < N; ++u) {
    if (dfs_order[u] == 0) _dfs(root = u);
  }
}
int which_comp[100004];
set<Edge> is_bridge;
vector<vector<int> > adj2;
void bfs2(int src, int id) {
  which_comp[src] = id;
  queue<int> q;
  q.push(src);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int j = 0; j < adj[u].size(); ++j) {
      int v = adj[u][j];
      if (is_bridge.count(Edge(u, v))) continue;
      if (which_comp[v] < 0) {
        which_comp[v] = id;
        q.push(v);
      }
    }
  }
}
vector<int> LCA_P;
vector<int> LCA_L;
class LCA {
  vector<vector<int> > M;

 public:
  LCA(int _N = 0) {
    LCA_P = vector<int>(_N, -1);
    LCA_L = vector<int>(_N, -1);
  }
  void preprocess() {
    int N = LCA_P.size();
    if (N == 0) return;
    int LOGN = N > 1 ? 1 + (sizeof(int) * 8 - 1 - __builtin_clz((N - 1))) : 0;
    M = vector<vector<int> >(LOGN, vector<int>(N, -1));
    for (int i = 0; i < N; ++i) M[0][i] = LCA_P[i];
    for (int j = 1; (1 << j) < N; ++j)
      for (int i = 0; i < N; ++i)
        if (M[j - 1][i] != -1) M[j][i] = M[j - 1][M[j - 1][i]];
  }
  int query(int p, int q) {
    if (LCA_L[p] < LCA_L[q]) swap(p, q);
    int LOGLp =
        LCA_L[p] > 0 ? (sizeof(int) * 8 - 1 - __builtin_clz((LCA_L[p]))) : 0;
    for (int j = LOGLp; j >= 0; --j)
      if (LCA_L[p] - (1 << j) >= LCA_L[q]) p = M[j][p];
    if (p == q) return p;
    for (int j = LOGLp; j >= 0; --j)
      if (M[j][p] != -1 && M[j][p] != M[j][q]) p = M[j][p], q = M[j][q];
    return LCA_P[p];
  }
};
void bfs3(int src) {
  LCA_L[src] = 0;
  queue<int> q;
  q.push(src);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int j = 0; j < adj2[u].size(); ++j) {
      int v = adj2[u][j];
      if (LCA_L[v] < 0) {
        LCA_L[v] = LCA_L[u] + 1;
        LCA_P[v] = u;
        q.push(v);
      }
    }
  }
}
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  BiconnectedComponent bc(N);
  for (int m = 0; m < M; ++m) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  bc.run();
  for (int j = 0; j < bc.bridges.size(); ++j) {
    Edge e = bc.bridges[j];
    is_bridge.insert(e);
    is_bridge.insert(Edge(e.v, e.u));
  }
  memset(which_comp, -1, sizeof(which_comp));
  for (int j = 0; j < bc.bridges.size(); ++j) {
    Edge e = bc.bridges[j];
    int comp_u = which_comp[e.u];
    if (comp_u < 0) {
      comp_u = adj2.size();
      adj2.push_back(vector<int>());
      bfs2(e.u, comp_u);
    }
    int comp_v = which_comp[e.v];
    if (comp_v < 0) {
      comp_v = adj2.size();
      adj2.push_back(vector<int>());
      bfs2(e.v, comp_v);
    }
    adj2[comp_u].push_back(comp_v);
    adj2[comp_v].push_back(comp_u);
  }
  LCA lca(adj2.size());
  bfs3(0);
  lca.preprocess();
  int K;
  scanf("%d", &K);
  for (int k = 1; k <= K; ++k) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u, --v;
    int comp_u = which_comp[u];
    int comp_v = which_comp[v];
    int x = lca.query(comp_u, comp_v);
    int res = (LCA_L[comp_u] - LCA_L[x]) + (LCA_L[comp_v] - LCA_L[x]);
    printf("%d\n", res);
  }
  return 0;
}
