#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)1e5 + 7;
int n, m;
bool bri[N];
vector<pair<int, int> > e[N];
int dfn[N], low[N], bcc[N], S[N], top, cnt, no;
void BCC(int u, int eid) {
  dfn[u] = low[u] = ++no;
  S[top++] = u;
  for (auto o : e[u]) {
    int v = o.first, id = o.second;
    if (!dfn[v]) {
      BCC(v, id);
      low[u] = min(low[u], low[v]);
      if (low[v] > dfn[u]) bri[id] = 1;
    } else if (id != eid) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (low[u] == dfn[u]) {
    ++cnt;
    do {
      bcc[S[--top]] = cnt;
    } while (S[top] != u);
  }
}
vector<int> e2[N];
bool cir[N];
void run(int n) {
  no = top = cnt = 0;
  memset(dfn, 0, sizeof(dfn));
  memset(bri, 0, sizeof(bri));
  memset(bcc, 0, sizeof(bcc));
  memset(cir, 0, sizeof(cir));
  for (int i = (1); i < (n + 1); ++i)
    if (!dfn[i]) BCC(i, 0);
  for (int i = (1); i < (cnt + 1); ++i) e2[i].clear();
  for (int u = (1); u < (n + 1); ++u)
    for (auto o : e[u])
      if (bcc[u] != bcc[o.first])
        e2[bcc[u]].push_back(bcc[o.first]);
      else
        cir[bcc[u]] = 1;
}
int f[N][20], dep[N], sum[N];
void dfs(int u, int p, int d) {
  f[u][0] = p;
  dep[u] = d;
  sum[u] = sum[p] + cir[u];
  for (int j = (1); j < (20); ++j) f[u][j] = f[f[u][j - 1]][j - 1];
  for (auto v : e2[u])
    if (v != p) dfs(v, u, d + 1);
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 19, d = dep[u] - dep[v]; i >= 0; --i)
    if (d >> i & 1) u = f[u][i];
  if (u == v) return u;
  for (int i = (20) - 1; i >= (0); --i)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
inline int mul(int a, int b) { return 1ll * a * b % MOD; }
int powmod(int a, int b) {
  int res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
  }
  return res;
}
void Init() {
  int id = 0;
  for (int i = (0); i < (m); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    id++;
    e[u].push_back(make_pair(v, id));
    e[v].push_back(make_pair(u, id));
  }
}
int Solve() {
  run(n);
  dfs(1, 0, 0);
  int k;
  scanf("%d", &k);
  while (k--) {
    int u, v;
    scanf("%d%d", &u, &v);
    u = bcc[u];
    v = bcc[v];
    int uv = lca(u, v);
    int t1 = sum[u] - sum[uv];
    int t2 = sum[v] - sum[uv];
    int t3 = sum[uv] - sum[f[uv][0]];
    int ans = powmod(2, t1 + t2 + t3);
    printf("%d\n", ans);
  }
  return 0;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    Init();
    Solve();
  }
  return 0;
}
