#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
struct node {
  long long v, id;
  node(long long V, long long ID) {
    v = V;
    id = ID;
  };
};
long long read() {
  long long ivy;
  scanf("%lld", &ivy);
  return ivy;
}
long long DFN, dfn[N], low[N];
bool IsCut[N];
vector<node> G[N];
void Tarjan(long long u, long long fa) {
  dfn[u] = low[u] = ++DFN;
  for (long long i = 0, siz = G[u].size(); i < siz; i++) {
    long long v = G[u][i].v, id = G[u][i].id;
    if (!dfn[v]) {
      Tarjan(v, u);
      if (low[v] > dfn[u]) IsCut[id] = 1;
      low[u] = min(low[u], low[v]);
    } else if (fa != v)
      low[u] = min(low[u], dfn[v]);
  }
}
long long fa[N];
long long find(long long x) {
  if (fa[x] != x) return fa[x] = find(fa[x]);
  return x;
}
long long n, m, vis[N];
vector<long long> G2[N];
long long root, belong[N], siz[N];
void dfs(long long u, long long fa) {
  vis[u] = 1;
  belong[u] = root;
  siz[root]++;
  for (long long i = 0, v, siz = G[u].size(); i < siz; i++) {
    if (vis[v = G[u][i].v] || IsCut[G[u][i].id]) continue;
    dfs(v, u);
  }
}
void MakeGra(long long u, long long fa) {
  vis[u] = 1;
  for (long long i = 0, v, siz = G[u].size(); i < siz; i++) {
    if (vis[v = G[u][i].v]) continue;
    if (IsCut[G[u][i].id]) {
      G2[belong[u]].push_back(belong[v]);
      G2[belong[v]].push_back(belong[u]);
    } else
      MakeGra(v, u);
  }
}
long long pos[N][22], dep[N], g[N][22];
void MakePos(long long u, long long fa) {
  pos[u][0] = fa;
  dep[u] = dep[fa] + 1;
  g[u][0] = (siz[u] > 1);
  for (long long i = 1; i <= 20; i++) {
    pos[u][i] = pos[pos[u][i - 1]][i - 1];
    g[u][i] = g[u][i - 1] + g[pos[u][i - 1]][i - 1];
  }
  for (long long i = 0, v, siz = G2[u].size(); i < siz; i++) {
    if ((v = G2[u][i]) == fa) continue;
    MakePos(v, u);
  }
}
long long lca, num;
long long LCA(long long u, long long v) {
  long long sum = 0;
  lca = u;
  if (u == v) return 0;
  if (dep[u] < dep[v]) swap(u, v);
  for (long long i = 20; i >= 0; i--)
    if (dep[pos[u][i]] >= dep[v]) sum += g[u][i], u = pos[u][i];
  lca = u;
  if (u == v) return sum;
  for (long long i = 20; i >= 0; i--)
    if (pos[u][i] != pos[v][i])
      sum += g[u][i] + g[v][i], u = pos[u][i], v = pos[v][i];
  lca = pos[u][0];
  sum += g[u][0] + g[v][0];
  return sum;
}
long long qkpow(long long b, long long idx) {
  long long sum = 1;
  while (idx) {
    if (idx & 1) sum = sum * b % mod;
    idx >>= 1;
    b = b * b % mod;
  }
  return sum;
}
int main() {
  n = read();
  m = read();
  for (long long u, v, i = 1; i <= m; i++) {
    u = read();
    v = read();
    G[u].push_back(node(v, i));
    G[v].push_back(node(u, i));
  }
  Tarjan(1, 0);
  for (long long i = 1; i <= n; i++) fa[i] = i;
  for (long long i = 1; i <= n; i++)
    if (!vis[i]) root = i, dfs(i, 0);
  memset(vis, 0, sizeof(vis));
  for (long long i = 1; i <= n; i++)
    if (!vis[i]) MakeGra(i, 0);
  MakePos(1, 0);
  long long q = read();
  while (q--) {
    long long u = belong[read()], v = belong[read()];
    long long idx = LCA(u, v) + (siz[lca] > 1);
    cout << qkpow(2, idx) << endl;
  }
}
