#include <bits/stdc++.h>
using namespace std;
void trace_() { cerr << "\n"; }
template <typename T1, typename... T2>
void trace_(T1 t1, T2... t2) {
  cerr << ' ' << t1;
  trace_(t2...);
}
const long long mxN = 1e5 + 5;
long long n, m, Q;
bitset<mxN> vis, in, incy;
long long dsu[mxN], lca[mxN], eu[mxN], ev[mxN], tag[mxN], sum[mxN];
vector<long long> g[mxN], q[mxN];
long long get(long long x) { return x == dsu[x] ? x : dsu[x] = get(dsu[x]); }
void tarjan(long long u, long long p = -1) {
  dsu[u] = u;
  in[u] = 1;
  for (long long v : g[u])
    if (!in[v]) tarjan(v, u);
  for (long long i : q[u]) {
    long long v = u ^ eu[i] ^ ev[i];
    if (vis[v]) {
      lca[i] = get(v);
    }
    if (v == u) lca[v] = u;
  }
  vis[u] = 1;
  dsu[u] = p;
}
vector<long long> stk;
void dfs(long long u, long long p = -1) {
  vis[u] = in[u] = 1;
  stk.emplace_back(u);
  for (long long v : g[u]) {
    if (v == p) continue;
    if (in[v]) {
      tag[v]++;
      incy[v] = 1;
      while (!stk.empty() and stk.back() != v) {
        incy[stk.back()] = 1, stk.pop_back();
      }
      stk.pop_back();
    }
    if (vis[v]) continue;
    dfs(v, u);
  }
  if (!stk.empty() and stk.back() == u) stk.pop_back();
  in[u] = 0;
}
void add(long long u) {
  vis[u] = 1;
  sum[u] += tag[u];
  for (long long v : g[u]) {
    if (vis[v]) continue;
    sum[v] += sum[u];
    add(v);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n >> m;
  while (m--) {
    long long a, b;
    cin >> a >> b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  dfs(1, 0);
  vis = 0;
  add(1);
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    cin >> eu[i] >> ev[i];
    q[eu[i]].emplace_back(i);
    q[ev[i]].emplace_back(i);
  }
  vis = 0;
  in = 0;
  tarjan(1, 0);
  vector<long long> p2(n + 1);
  p2[0] = 1;
  for (long long i = 1; i <= n; i++) p2[i] = (p2[i - 1] << 1) % 1000000007;
  for (long long i = 0; i < Q; i++) {
    cout << p2[sum[eu[i]] + sum[ev[i]] - 2 * sum[lca[i]] + incy[lca[i]]]
         << '\n';
  }
}
