#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
const int mod = 1e9 + 7;
vector<int> adj[N], gfo[N];
int num[N], low[N], comp[N], cnt, c;
int ans[N], tsz[N], p[N], pw[N], w[N];
stack<int> S;
bool vst[N];
vector<pair<int, int> > ask[N];
int find(int u) {
  if (u == p[u]) return p[u];
  return p[u] = find(p[u]);
}
void tarjan(int u, int pa) {
  S.push(u), vst[u] = true;
  num[u] = low[u] = cnt++;
  for (int v : adj[u])
    if (v != pa) {
      if (num[v] == -1) tarjan(v, u);
      if (vst[v]) low[u] = min(low[u], low[v]);
    }
  if (low[u] == num[u]) {
    while (true) {
      int v = S.top();
      S.pop();
      vst[v] = false;
      comp[v] = c;
      if (v == u) break;
    }
    c++;
  }
}
void build(int n) {
  for (int i = int(0); i < int(n); ++i)
    for (int j : adj[i])
      if (comp[i] != comp[j]) gfo[comp[i]].push_back(comp[j]);
  for (int i = int(0); i < int(n); ++i) tsz[comp[i]]++;
}
void dfs(int u, int pa, int ind) {
  w[u] = ind + (tsz[u] > 1);
  for (int v : gfo[u])
    if (v != pa) dfs(v, u, w[u]);
}
void ziggy(int u, int pa) {
  vst[u] = true;
  for (pair<int, int> par : ask[u])
    if (vst[par.second]) {
      int lca = find(par.second);
      ans[par.first] = w[u] + w[par.second] - 2 * w[lca] + (tsz[lca] > 1);
    }
  for (int v : gfo[u])
    if (!vst[v]) ziggy(v, u);
  p[u] = pa;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = int(0); i < int(m); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  memset(num, -1, sizeof(num));
  tarjan(0, -1);
  build(n);
  for (int i = int(0); i < int(c); ++i) p[i] = i;
  int q;
  scanf("%d", &q);
  for (int i = int(0); i < int(q); ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--, v--;
    ask[comp[u]].push_back({i, comp[v]});
    ask[comp[v]].push_back({i, comp[u]});
  }
  dfs(0, -1, 0);
  ziggy(0, -1);
  pw[0] = 1;
  for (int i = int(1); i < int(n + 1); ++i) pw[i] = (2LL * pw[i - 1]) % mod;
  for (int i = int(0); i < int(q); ++i) printf("%d\n", pw[ans[i]]);
  return 0;
}
