#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:25600000")
using namespace std;
const double pi = acos(-1.0);
vector<vector<int> > cities;
vector<vector<int> > cities_without_bridges;
vector<vector<int> > g;
vector<vector<int> > pv;
vector<int> tin;
vector<int> tout;
vector<int> fup;
vector<int> used;
vector<int> component;
vector<int> depth;
set<pair<int, int> > bridges;
int timer;
int num_of_comp;
int n, m;
int L = 1;
void bridges_dfs(int v, int prev) {
  tin[v] = fup[v] = timer++;
  used[v] = true;
  for (long long i = 0; i < cities[v].size(); i++) {
    int next = cities[v][i];
    if (next == prev) continue;
    if (used[next] == true)
      fup[v] = min(fup[v], tin[next]);
    else {
      bridges_dfs(next, v);
      fup[v] = min(fup[v], fup[next]);
      if (fup[next] > tin[v]) {
        bridges.insert(pair<int, int>(next, v));
        bridges.insert(pair<int, int>(v, next));
      }
    }
  }
}
void find_bridges() {
  used.assign(n, 0);
  tin.assign(n, 0);
  fup.assign(n, 0);
  timer = 0;
  for (long long i = 0; i < n; i++)
    if (!used[i]) bridges_dfs(i, -1);
}
void delete_bridges() {
  cities_without_bridges.resize(n);
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < cities[i].size(); j++) {
      int v1 = i;
      int v2 = cities[i][j];
      if (bridges.empty() ||
          bridges.find(pair<int, int>(v1, v2)) == bridges.end())
        cities_without_bridges[i].push_back(v2);
    }
}
void comp_dfs(int v) {
  component[v] = num_of_comp;
  used[v] = true;
  for (long long i = 0; i < cities_without_bridges[v].size(); i++) {
    int next = cities_without_bridges[v][i];
    if (!used[next]) comp_dfs(next);
  }
}
void find_components() {
  used.assign(n, 0);
  component.resize(n);
  for (long long i = 0; i < n; i++)
    if (!used[i]) {
      comp_dfs(i);
      ++num_of_comp;
    }
}
void build_skel() {
  g.resize(num_of_comp);
  for (set<pair<int, int> >::iterator it = bridges.begin(); it != bridges.end();
       ++it) {
    int a = component[it->second];
    int b = component[it->first];
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (long long i = 0; i < g.size(); i++) {
    sort((g[i]).begin(), (g[i]).end());
    vector<int>::iterator it = unique((g[i]).begin(), (g[i]).end());
    g[i].resize(it - g[i].begin());
  }
}
void lca_dfs(int v, int prev) {
  tin[v] = timer++;
  used[v] = true;
  pv[v][0] = prev;
  for (long long i = 1; i <= L - 1; i++) pv[v][i] = pv[pv[v][i - 1]][i - 1];
  for (long long i = 0; i < g[v].size(); i++) {
    int next = g[v][i];
    if (!used[next]) lca_dfs(next, v);
  }
  tout[v] = timer++;
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int find_lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (long long l = L - 1; l >= 0; l--)
    if (!upper(pv[a][l], b)) a = pv[a][l];
  return pv[a][0];
}
void find_depth(int v, int d) {
  used[v] = true;
  depth[v] = d;
  for (long long i = 0; i < g[v].size(); i++) {
    int next = g[v][i];
    if (!used[next]) find_depth(next, d + 1);
  }
}
int main() {
  cin >> n >> m;
  cities.resize(n);
  for (long long i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    cities[x].push_back(y);
    cities[y].push_back(x);
  }
  find_bridges();
  delete_bridges();
  find_components();
  build_skel();
  while ((1 << L) <= n) ++L;
  ++L;
  int n = g.size();
  pv.resize(n);
  for (long long i = 0; i < n; i++) pv[i].resize(L);
  used.assign(n, 0);
  tin.assign(n, 0);
  tout.assign(n, 0);
  lca_dfs(0, 0);
  used.assign(n, 0);
  depth.assign(n, 0);
  find_depth(0, 0);
  int requests;
  cin >> requests;
  for (long long r = 0; r < requests; r++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    x = component[x];
    y = component[y];
    int lca = find_lca(x, y);
    cout << depth[x] + depth[y] - 2 * depth[lca] << endl;
  }
}
