#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5 + 1, MOD = 1e9 + 7;
int n, m, timer, color;
vector<list<int>> adj, newAdj;
vector<int> tin, low, cycleColor, dep, dfsIn, sum, sz, mult, flog;
stack<int> s;
int st[19][2 * mxN];
void init() {
  scanf("%d%d", &n, &m);
  adj.resize(n + 1);
  int u, v;
  while (m--) {
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  tin.resize(n + 1);
  low.resize(n + 1);
  cycleColor.resize(n + 1);
  sz.resize(n + 1);
}
void tarjan(int u = 1, int p = 0) {
  tin[u] = low[u] = ++timer;
  s.push(u);
  for (const int &child : adj[u]) {
    if (child == p) continue;
    if (tin[child])
      low[u] = min(low[u], tin[child]);
    else {
      tarjan(child, u);
      low[u] = min(low[u], low[child]);
    }
  }
  if (low[u] == tin[u]) {
    int v;
    color++;
    do {
      v = s.top(), s.pop();
      cycleColor[v] = color;
      ++sz[color];
    } while (u != v);
  }
}
void squeeze() {
  newAdj.resize(n + 1);
  for (int u = 1; u <= n; ++u) {
    for (const int &child : adj[u]) {
      int a = cycleColor[u], b = cycleColor[child];
      if (a ^ b) newAdj[cycleColor[u]].push_back(cycleColor[child]);
    }
  }
  dep.resize(n + 1);
  dfsIn.resize(n + 1);
  timer = 0;
  sum.resize(n + 1);
  flog.resize(2 * n);
}
void dp() {
  for (int i = 1; i <= color; ++i) sum[i] = sz[i] > 1;
  for (int i = 2; i < 2 * n; ++i) flog[i] = flog[i >> 1] + 1;
}
void dfs(int u = 1, int p = 0) {
  dep[u] = dep[p] + 1;
  st[0][++timer] = u;
  sum[u] += sum[p];
  dfsIn[u] = timer;
  for (const int &child : newAdj[u]) {
    if (child == p) continue;
    dfs(child, u);
    st[0][++timer] = u;
  }
}
int LCA(int x, int y) {
  int l = dfsIn[x], r = dfsIn[y];
  if (l > r) swap(l, r);
  int k = flog[r - l + 1];
  if (dep[st[k][l]] < dep[st[k][r - (1 << k) + 1]])
    return st[k][l];
  else
    return st[k][r - (1 << k) + 1];
}
int main() {
  init();
  tarjan();
  squeeze();
  dp();
  dfs();
  for (int i = 1; i <= 18; ++i)
    for (int j = 1; j <= timer; ++j) {
      if (dep[st[i - 1][j]] < dep[st[i - 1][j + (1 << (i - 1))]])
        st[i][j] = st[i - 1][j];
      else
        st[i][j] = st[i - 1][j + (1 << (i - 1))];
    }
  mult.resize(n + 1);
  mult[0] = 1;
  for (int i = 1; i <= n; ++i) mult[i] = 2LL * mult[i - 1] % MOD;
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y, lca;
    scanf("%d%d", &x, &y);
    x = cycleColor[x];
    y = cycleColor[y];
    lca = LCA(x, y);
    printf("%d\n", mult[sum[x] + sum[y] - (sum[lca] << 1) + (sz[lca] > 1)]);
  }
  return 0;
}
