#include <bits/stdc++.h>
using namespace std;
const long double epsilon = 1e-9;
int fathers[1 << 17];
int passed[1 << 17];
int counts[1 << 17];
int getFather(int x) {
  int idx = 0;
  while (fathers[x] != -1) {
    passed[idx++] = x;
    x = fathers[x];
  }
  for (int i = 0; i < idx; i++) {
    fathers[passed[i]] = x;
  }
  return x;
}
void merge(int x, int y) {
  x = getFather(x);
  y = getFather(y);
  if (counts[x] >= counts[y]) {
    fathers[y] = x;
    counts[x] += counts[y];
  } else {
    fathers[x] = y;
    counts[y] += counts[x];
  }
}
int depth[1 << 17];
int lcaFathers[1 << 17][20];
int getLca(int x, int y) {
  int idx = 19;
  while (depth[x] != depth[y]) {
    if (lcaFathers[y][idx] != -1 && depth[x] <= depth[lcaFathers[y][idx]]) {
      y = lcaFathers[y][idx];
    }
    if (lcaFathers[x][idx] != -1 && depth[y] <= depth[lcaFathers[x][idx]]) {
      x = lcaFathers[x][idx];
    }
    idx--;
  }
  if (x == y) return x;
  for (int i = 19; i >= 0; i--) {
    if (lcaFathers[x][i] != lcaFathers[y][i]) {
      x = lcaFathers[x][i];
      y = lcaFathers[y][i];
    }
  }
  return lcaFathers[x][0];
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > neighbours(n);
  int x, y;
  for (int i = 0; i < m; i++) {
    scanf("%d", &x);
    scanf("%d", &y);
    x--;
    y--;
    neighbours[x].push_back(y);
    neighbours[y].push_back(x);
  }
  memset(fathers, -1, sizeof(fathers));
  memset(counts, 1, sizeof(counts));
  stack<pair<int, int> > toProcess;
  toProcess.push(make_pair(0, 0));
  vector<int> levels(n, -1);
  vector<int> prev(n, -1);
  pair<int, int> cur;
  int i;
  prev[0] = -2;
  levels[0] = 0;
  stack<int> components;
  components.push(0);
  int cntComp = n;
  while (!toProcess.empty()) {
    cur = toProcess.top();
    for (i = cur.second; i < neighbours[cur.first].size(); i++) {
      if (neighbours[cur.first][i] == prev[cur.first]) continue;
      if (prev[neighbours[cur.first][i]] == -1) {
        toProcess.top().second = i + 1;
        levels[neighbours[cur.first][i]] = levels[cur.first] + 1;
        prev[neighbours[cur.first][i]] = cur.first;
        toProcess.push(make_pair(neighbours[cur.first][i], 0));
        components.push(neighbours[cur.first][i]);
        break;
      }
      if (levels[neighbours[cur.first][i]] < levels[cur.first]) {
        int f1 = getFather(neighbours[cur.first][i]);
        int f2;
        while ((f2 = getFather(components.top())) != f1) {
          merge(f1, f2);
          f1 = getFather(f1);
          components.pop();
          cntComp--;
        }
        components.pop();
        components.push(f1);
      }
    }
    if (i == neighbours[cur.first].size()) {
      toProcess.pop();
      if (!toProcess.empty() &&
          getFather(toProcess.top().first) != components.top()) {
        components.pop();
      }
    }
  }
  vector<vector<int> > tree(n);
  int tmpF1, tmpF2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < neighbours[i].size(); j++) {
      if ((tmpF1 = getFather(i)) != (tmpF2 = getFather(neighbours[i][j])) &&
          tmpF1 < tmpF2) {
        tree[tmpF1].push_back(tmpF2);
        tree[tmpF2].push_back(tmpF1);
      }
    }
  }
  memset(depth, -1, sizeof(depth));
  memset(lcaFathers, -1, sizeof(lcaFathers));
  queue<int> toProcess2;
  vector<int> vis(n, false);
  int zero = getFather(0);
  toProcess2.push(zero);
  vis[zero] = true;
  depth[zero] = 0;
  int cur2;
  while (!toProcess2.empty()) {
    cur2 = toProcess2.front();
    toProcess2.pop();
    for (int i = 0; i < tree[cur2].size(); i++) {
      if (!vis[tree[cur2][i]]) {
        vis[tree[cur2][i]] = true;
        depth[tree[cur2][i]] = depth[cur2] + 1;
        toProcess2.push(tree[cur2][i]);
        for (int j = 0; j < 20; j++) {
          if (depth[cur2] % (1 << j) == 0)
            lcaFathers[tree[cur2][i]][j] = cur2;
          else
            lcaFathers[tree[cur2][i]][j] = lcaFathers[cur2][j];
        }
      }
    }
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    scanf("%d", &x);
    scanf("%d", &y);
    x = getFather(x - 1);
    y = getFather(y - 1);
    printf("%d\n", depth[x] + depth[y] - 2 * depth[getLca(x, y)]);
  }
  return 0;
}
