#include <bits/stdc++.h>
using namespace std;
int nn[100000], np[100000][19], ni[100000], nl[100000], nh[100000], nc[100000],
    nv[100000], nd[100000], dist[100000];
vector<int> ne[100000];
int es[100000], ee[100000];
bool eb[100000];
int curp[100000];
int trav = 0;
bool dfs(int n, int p) {
  ni[n] = nl[n] = nh[n] = trav++;
  nc[n] = 1;
  for (int i = 0; i < ne[n].size(); i++) {
    int other = es[ne[n][i]];
    if (other == n) {
      other = ee[ne[n][i]];
    }
    if (other == p) continue;
    if (ni[other] == -1) {
      if (dfs(other, n)) {
        eb[ne[n][i]] = true;
      }
      nc[n] += nc[other];
      nl[n] = min(nl[n], nl[other]);
      nh[n] = max(nh[n], nh[other]);
    } else {
      nl[n] = min(nl[n], ni[other]);
      nh[n] = max(nh[n], ni[other]);
    }
  }
  if (nl[n] == ni[n] && nh[n] < ni[n] + nc[n]) {
    return true;
  }
  return false;
}
class queue_order {
 public:
  int n;
  bool bridge;
  queue_order(int a, bool b) {
    n = a;
    bridge = b;
  }
};
struct cmp {
  bool operator()(queue_order* a, queue_order* b) {
    if (a->bridge == b->bridge) return false;
    if (a->bridge) return true;
    return false;
  }
};
void condense() {
  int curnn = 0;
  priority_queue<queue_order*, vector<queue_order*>, cmp> pq;
  pq.push(new queue_order(0, false));
  while (pq.size() > 0) {
    queue_order* o = pq.top();
    pq.pop();
    if (nn[o->n] != -1) continue;
    if (o->bridge) curnn++;
    nn[o->n] = curnn;
    for (int i = 0; i < ne[o->n].size(); i++) {
      int other = es[ne[o->n][i]];
      if (other == o->n) {
        other = ee[ne[o->n][i]];
      }
      if (nn[other] != -1) continue;
      pq.push(new queue_order(other, eb[ne[o->n][i]]));
    }
  }
}
void dfs2(int n, int p, int d) {
  curp[d] = n;
  nd[n] = d;
  for (int i = 0; i < 18; i++) {
    if (d - (1 << i) >= 0) {
      np[n][i] = curp[d - (1 << i)];
    } else {
      np[n][18] = i - 1;
      break;
    }
  }
  for (int i = 0; i < ne[n].size(); i++) {
    int other = es[ne[n][i]];
    if (other == n) {
      other = ee[ne[n][i]];
    }
    if (other == p) continue;
    dfs2(other, n, d + 1);
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  memset(nv, 0, n * sizeof(int));
  memset(nn, -1, n * sizeof(int));
  memset(ni, -1, n * sizeof(int));
  memset(nc, 0, n * sizeof(int));
  memset(eb, false, m * sizeof(bool));
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &es[i], &ee[i]);
    es[i]--;
    ee[i]--;
    ne[es[i]].push_back(i);
    ne[ee[i]].push_back(i);
  }
  dfs(0, 0);
  condense();
  for (int i = 0; i < n; i++) {
    ne[i].clear();
  }
  for (int i = 0; i < m; i++) {
    es[i] = nn[es[i]];
    ee[i] = nn[ee[i]];
    if (es[i] != ee[i]) {
      ne[es[i]].push_back(i);
      ne[ee[i]].push_back(i);
    }
  }
  int root = 0;
  queue<int> q;
  queue<int> d;
  q.push(root);
  nv[root] = 1;
  while (q.size() > 0) {
    int cur = q.front();
    q.pop();
    root = cur;
    for (int i = 0; i < ne[cur].size(); i++) {
      int other = es[ne[cur][i]];
      if (other == cur) {
        other = ee[ne[cur][i]];
      }
      if (nv[other] < 1) {
        nv[other] = 1;
        q.push(other);
      }
    }
  }
  q.push(root);
  d.push(0);
  nv[root] = 2;
  int maxd = 0;
  while (q.size() > 0) {
    int cur = q.front();
    q.pop();
    int curd = d.front();
    d.pop();
    maxd = curd;
    dist[curd] = cur;
    for (int i = 0; i < ne[cur].size(); i++) {
      int other = es[ne[cur][i]];
      if (other == cur) {
        other = ee[ne[cur][i]];
      }
      if (nv[other] < 2) {
        nv[other] = 2;
        q.push(other);
        d.push(curd + 1);
      }
    }
  }
  root = dist[maxd / 2];
  dfs2(root, root, 0);
  int k, s, e, s2, e2;
  scanf("%d", &k);
  while (k-- > 0) {
    scanf("%d %d", &s, &e);
    s = s2 = nn[s - 1];
    e = e2 = nn[e - 1];
    while (s2 != e2) {
      if (nd[s2] < nd[e2]) {
        for (int i = np[e2][18]; i >= 0; i--) {
          if (nd[e2] - (1 << i) >= nd[s2]) {
            e2 = np[e2][i];
          }
        }
      } else if (nd[s2] > nd[e2]) {
        for (int i = np[s2][18]; i >= 0; i--) {
          if (nd[s2] - (1 << i) >= nd[e2]) {
            s2 = np[s2][i];
          }
        }
      } else {
        for (int i = np[s2][18]; i > 0; i--) {
          if (np[s2][i] != np[e2][i]) {
            s2 = np[s2][i];
            e2 = np[e2][i];
          }
        }
        s2 = np[s2][0];
        e2 = np[e2][0];
      }
    }
    printf("%d\n", nd[s] + nd[e] - 2 * nd[s2]);
  }
  return 0;
}
