#include <bits/stdc++.h>
using namespace std;
template <typename Arg1, typename Arg2>
ostream& operator<<(ostream& out, const pair<Arg1, Arg2>& x) {
  return out << "(" << x.first << "," << x.second << ")";
}
template <typename Arg1>
ostream& operator<<(ostream& out, const vector<Arg1>& a) {
  out << "[";
  for (const auto& x : a) out << x << ",";
  return out << "]";
}
template <typename Arg1>
ostream& operator<<(ostream& out, const set<Arg1>& a) {
  out << "[";
  for (const auto& x : a) out << x << ",";
  return out << "]";
}
template <typename Arg1, typename Arg2>
ostream& operator<<(ostream& out, const map<Arg1, Arg2>& a) {
  out << "[";
  for (const auto& x : a) out << x << ",";
  return out << "]";
}
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << " ] " << endl;
}
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args) {
  const string name = names.substr(0, names.find(','));
  cerr << name << " : " << arg1 << " | ";
  __trace__(names.substr(1 + (int)name.size()), args...);
}
clock_t time_p = clock();
void time_taken() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
const long long mod = 1e9 + 7;
const long long INF = 1e18;
struct BCC {
  vector<int> g[100005], B[100005];
  vector<pair<int, int>> tree[100005];
  int U[100005], V[100005], W[100005], temp[100005], bcc[100005], ind[100005],
      T, cmpno, m, n;
  bitset<100005> vis, bridge;
  vector<int> Q[100005];
  void init(int _n) { n = _n, cmpno = 0, T = 0, m = 0; }
  void reset(int n) {
    for (int i = 1; i <= n; i++) {
      g[i].clear(), tree[i].clear(), B[i].clear();
      ind[i] = 0;
    }
    bridge.reset();
  }
  int adj(int u, int e) { return U[e] == u ? V[e] : U[e]; }
  void addedge(int u, int v, int w) {
    U[m] = u, V[m] = v, W[m] = w;
    g[u].push_back(m), g[v].push_back(m);
    m++;
  }
  void get_bridges() {
    for (int i = 1; i <= n; i++)
      if (!vis[i]) dfs1(i, -1);
    vis.reset();
  }
  void go() {
    get_bridges();
    for (int i = 1; i <= n; i++)
      if (!vis[i]) {
        cmpno++;
        dfs2(i);
      }
    vis.reset();
  }
  int dfs1(int u, int e) {
    vis[u] = 1;
    temp[u] = T++;
    int t = temp[u];
    for (int id : g[u]) {
      int v = adj(u, id);
      if (!vis[v])
        t = min(t, dfs1(v, id));
      else if (id != e)
        t = min(t, temp[v]);
    }
    if (t == temp[u] && e != -1) bridge[e] = 1;
    return t;
  }
  void dfs2(int u) {
    int cur_cmp = cmpno;
    Q[cur_cmp].push_back(u);
    bcc[u] = cur_cmp;
    B[cur_cmp].push_back(u);
    vis[u] = 1;
    while (Q[cur_cmp].size() != ind[cur_cmp]) {
      int u = Q[cur_cmp][ind[cur_cmp]];
      ind[cur_cmp]++;
      for (int e : g[u]) {
        int v = adj(u, e);
        if (vis[v]) continue;
        if (bridge[e]) {
          cmpno++;
          tree[cur_cmp].push_back({cmpno, W[e]});
          tree[cmpno].push_back({cur_cmp, W[e]});
          dfs2(v);
        } else {
          Q[cur_cmp].push_back(v);
          vis[v] = 1;
          bcc[v] = cur_cmp;
          B[cur_cmp].push_back(v);
        }
      }
    }
  }
} B;
const int maxn = 1e5 + 5;
const int LOGN = 22;
vector<int> depth(maxn);
int par[maxn][LOGN];
long long cost[maxn][LOGN];
void dfs(int u = 1, int p = -1) {
  par[u][0] = p;
  cost[u][0] = 0;
  for (pair<int, int> v : B.tree[u]) {
    if (v.first == p) {
      cost[u][0] = v.second;
    } else {
      depth[v.first] = depth[u] + 1;
      dfs(v.first, u);
    }
  }
}
void pre(int n) {
  dfs();
  for (int i = 1; i < LOGN; i++) {
    for (int u = 1; u <= n; u++) {
      if (par[u][i - 1] == -1) {
        par[u][i] = -1;
        cost[u][i] = cost[u][i - 1];
      } else {
        par[u][i] = par[par[u][i - 1]][i - 1];
        cost[u][i] = cost[u][i - 1] + cost[par[u][i - 1]][i - 1];
      }
    }
  }
}
long long query(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  long long ans = 0;
  for (int i = LOGN - 1; i >= 0; i--) {
    if (depth[u] - (1 << i) >= depth[v]) {
      ans += cost[u][i];
      u = par[u][i];
    }
  }
  for (int i = LOGN - 1; i >= 0; i--) {
    if (par[u][i] != par[v][i]) {
      ans += cost[u][i] + cost[v][i];
      u = par[u][i];
      v = par[v][i];
    }
  }
  if (u != v) {
    ans += cost[u][0] + cost[v][0];
    u = par[u][0];
    v = par[v][0];
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(12);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  B.init(n);
  while (m--) {
    int u, v, w;
    cin >> u >> v;
    B.addedge(u, v, 1);
  }
  B.go();
  pre(B.cmpno);
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    cout << query(B.bcc[u], B.bcc[v]) << '\n';
  }
  time_taken();
  return 0;
}
