#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e5 + 5;
int n, m, sta[N], tp, tot, siz[N], low[N], dfn[N], be[N], bl, dep[N], f[N][22],
    w[N];
vector<int> e[N], vec[N];
int read() {
  int x = 0, f = 1;
  char s;
  while ((s = getchar()) > '9' || s < '0')
    if (s == '-') f = -1;
  while (s >= '0' && s <= '9')
    x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();
  return x * f;
}
void addEdge(int u, int v) {
  e[u].push_back(v);
  e[v].push_back(u);
}
void tarjan(int u, int fa) {
  sta[++tp] = u;
  dfn[u] = low[u] = ++tot;
  for (int i = 0; i < e[u].size(); ++i) {
    int v = e[u][i];
    if (v == fa) continue;
    if (!dfn[v])
      tarjan(v, u), low[u] = min(low[u], low[v]);
    else
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    int v = 0;
    ++bl;
    do {
      v = sta[tp--];
      be[v] = bl;
      ++siz[bl];
    } while (v ^ u);
  }
}
int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 20; i >= 0; --i)
    if (dep[f[u][i]] >= dep[v]) u = f[u][i];
  if (u == v) return u;
  for (int i = 20; i >= 0; --i)
    if (f[u][i] ^ f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  f[u][0] = fa;
  w[u] = w[fa] + (siz[u] > 1);
  for (int i = 1; i <= 20; ++i) f[u][i] = f[f[u][i - 1]][i - 1];
  for (int i = 0; i < vec[u].size(); ++i)
    if (vec[u][i] ^ fa) dfs(vec[u][i], u);
}
int qkpow(int x, int y) {
  int r = 1;
  while (y) {
    if (y & 1) r = 1ll * r * x % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return r;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; ++i) addEdge(read(), read());
  tarjan(1, 0);
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < e[i].size(); ++j)
      if (be[i] ^ be[e[i][j]]) vec[be[i]].push_back(be[e[i][j]]);
  dfs(1, 0);
  int u, v;
  for (int t = read(); t; --t) {
    u = be[read()], v = be[read()];
    int lca = LCA(u, v);
    printf("%d\n", qkpow(2, w[u] + w[v] - w[lca] * 2 + (siz[lca] > 1)));
  }
  return 0;
}
