#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5 + 1, MOD = 1e9 + 7;
int n, m, q, dfn[mxN], low[mxN], dfsc, tag[mxN], tagc, stac[mxN], top, dep[mxN],
    dfs_in[mxN], sz[mxN], rmq[20][2 * mxN], Log[2 * mxN + 1], sum[mxN],
    mul[mxN];
vector<int> v[mxN], new_v[mxN];
inline void chmin(int &x, int y) { x = x < y ? x : y; }
void tarjan(int from, int f) {
  dfn[from] = low[from] = ++dfsc;
  stac[top++] = from;
  for (int i = 0; i < v[from].size(); ++i) {
    int to = v[from][i];
    if (to == f) continue;
    if (!dfn[to])
      tarjan(to, from), chmin(low[from], low[to]);
    else
      chmin(low[from], dfn[to]);
  }
  if (low[from] == dfn[from]) {
    ++tagc;
    while (stac[top] != from) {
      tag[stac[top - 1]] = tagc;
      ++sz[tagc];
      --top;
    }
  }
}
void dfs(int from, int f) {
  dep[from] = dep[f] + 1;
  rmq[0][++dfsc] = from;
  sum[from] += sum[f];
  dfs_in[from] = dfsc;
  for (int i = 0; i < new_v[from].size(); ++i) {
    int to = new_v[from][i];
    if (to == f) continue;
    dfs(to, from);
    rmq[0][++dfsc] = from;
  }
}
int LCA(int x, int y) {
  int l = dfs_in[x], r = dfs_in[y];
  if (l > r) swap(l, r);
  int k = Log[r - l + 1];
  if (dep[rmq[k][l]] < dep[rmq[k][r - (1 << k) + 1]])
    return rmq[k][l];
  else
    return rmq[k][r - (1 << k) + 1];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 2; i <= (n << 1); ++i) Log[i] = Log[i >> 1] + 1;
  tarjan(1, 0);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < v[i].size(); ++j) {
      int to = v[i][j];
      if (tag[i] != tag[to]) new_v[tag[i]].push_back(tag[to]);
    }
  }
  for (int i = 1; i <= tagc; ++i) sum[i] = sz[i] > 1;
  dfsc = 0;
  dfs(1, 0);
  for (int i = 1; i < 20; ++i)
    for (int j = 1; j <= dfsc; ++j) {
      if (dep[rmq[i - 1][j]] < dep[rmq[i - 1][j + (1 << (i - 1))]])
        rmq[i][j] = rmq[i - 1][j];
      else
        rmq[i][j] = rmq[i - 1][j + (1 << (i - 1))];
    }
  mul[0] = 1;
  for (int i = 1; i <= n; ++i) mul[i] = 2LL * mul[i - 1] % MOD;
  scanf("%d", &q);
  while (q--) {
    int x, y, lca;
    scanf("%d%d", &x, &y);
    x = tag[x];
    y = tag[y];
    lca = LCA(x, y);
    printf("%d\n", mul[sum[x] + sum[y] - (sum[lca] << 1) + (sz[lca] > 1)]);
  }
  return 0;
}
