#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9 + 7;
int used[maxn], order[maxn], pw[maxn], O = 0;
int comp[maxn], cnt[maxn], C = 0, lca[maxn][20];
int num[maxn], in[maxn], out[maxn], T = 0;
vector<pair<int, int> > g[maxn];
vector<int> G[maxn];
void dfs(int v) {
  used[v] = 1;
  for (int i = 0; i < (int)(g[v]).size(); i++) {
    int to = g[v][i].first;
    if (used[to]) continue;
    g[v][i].second = 0;
    dfs(to);
  }
  order[O++] = v;
}
void go(int v) {
  comp[v] = C;
  cnt[C]++;
  for (int i = 0; i < (int)(g[v]).size(); i++) {
    int to = g[v][i].first;
    if (!g[v][i].second || comp[to] != -1) continue;
    go(to);
  }
}
void make(int v, int p, int cur) {
  in[v] = ++T;
  cur += cnt[v] > 1;
  num[v] = cur;
  lca[v][0] = p;
  for (int i = 1; i <= 17; i++) lca[v][i] = lca[lca[v][i - 1]][i - 1];
  for (int i = 0; i < (int)(G[v]).size(); i++) {
    int to = G[v][i];
    if (to == p) continue;
    make(to, v, cur);
  }
  out[v] = ++T;
}
int upper(int a, int b) { return in[a] <= in[b] && out[b] <= out[a]; }
int getlca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = 17; i >= 0; i--)
    if (!upper(lca[a][i], b)) a = lca[a][i];
  return lca[a][0];
}
int main() {
  pw[0] = 1;
  for (int i = 1; i < maxn; i++) pw[i] = (long long)pw[i - 1] * 2 % mod;
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(make_pair(b, 1));
    g[b].push_back(make_pair(a, 1));
  }
  dfs(0);
  memset(comp, -1, sizeof(comp));
  for (int i = 0; i < n; i++) {
    int v = order[n - 1 - i];
    if (comp[v] != -1) continue;
    go(v);
    ++C;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (int)(g[i]).size(); j++) {
      int a = i;
      int b = g[i][j].first;
      a = comp[a];
      b = comp[b];
      if (a == b) continue;
      G[a].push_back(b);
    }
  make(0, 0, 0);
  int q;
  cin >> q;
  while (q--) {
    scanf("%d%d", &a, &b);
    --a;
    --b;
    a = comp[a];
    b = comp[b];
    int LCA = getlca(a, b);
    printf("%d\n", pw[num[a] + num[b] - 2 * num[LCA] + (cnt[LCA] > 1)]);
  }
  return 0;
}
