#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-10;
const int MODULO = 1000000007;
template <int size>
class UnionFind {
  int par[size];
  int rank[size];

 public:
  UnionFind() { reset(); }
  void reset() {
    for (int i = 0; i < (size); i++) par[i] = i, rank[i] = 0;
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
UnionFind<100000> u;
int n, m, k;
vector<int> v[100000];
vector<int> v2[100000];
bool use[100000];
vector<int> use_num;
stack<int> st;
void Unit(int x) {
  stack<int> s(st);
  while (s.top() != x) {
    u.unite(x, s.top());
    s.pop();
  }
}
void connect(int x) {
  st.push(x);
  int next = st.top();
  use[next] = true;
  use_num.push_back(next);
  for (__typeof__((v[next]).begin()) it = (v[next]).begin();
       it != (v[next]).end(); ++it) {
    vector<int>::iterator i = find(v[*it].begin(), v[*it].end(), next);
    if (i != v[*it].end()) v[*it].erase(i);
    if (use[*it]) {
      Unit(*it);
    } else {
      connect(*it);
    }
  }
  st.pop();
}
class GT {
 public:
  bool operator()(const pair<int, int>& x, const pair<int, int>& y) {
    return less<int>()(x.second, y.second);
  }
};
int get_len(int l, int s) {
  memset(use, 0, sizeof(use));
  priority_queue<pair<int, int>, vector<pair<int, int> >, GT> q;
  q.push(pair<int, int>(l, 0));
  while (!q.empty()) {
    pair<int, int> next = q.top();
    q.pop();
    if (use[next.first]) continue;
    if (next.first == s) return next.second;
    use[next.first] = true;
    for (__typeof__((v2[next.first]).begin()) it = (v2[next.first]).begin();
         it != (v2[next.first]).end(); ++it) {
      if (!use[(*it)]) {
        int len = next.second;
        if (!u.same(next.first, *it)) len++;
        q.push(pair<int, int>(*it, len));
      }
    }
  }
  return -1;
}
int main() {
  iostream::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < (m); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
    v2[a].push_back(b);
    v2[b].push_back(a);
  }
  connect(0);
  cin >> k;
  for (int i = 0; i < (k); i++) {
    int s, l;
    cin >> s >> l;
    s--, l--;
    int ans = get_len(s, l);
    cout << ans << endl;
  }
  return 0;
}
