#include <bits/stdc++.h>
using namespace std;
long long fpm(long long b, long long e, long long m) {
  long long t = 1;
  for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;
  return t;
}
template <class T>
inline bool chkmin(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <class T>
inline bool chkmax(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const int maxn = 110000, maxm = 110000;
struct edge {
  int t;
  edge *n;
};
typedef int arr32[maxn];
edge graph[maxm << 1], *eptr = graph, *adj[maxn];
int top, tms, tail;
arr32 stk, rep, low, dfn, Q, size, ways, tid, aux, root, fth, depth;
const int mod = 1000000007;
void adde(int s, int t) { *(++eptr) = (edge){t, adj[s]}, adj[s] = eptr; }
void dfs(int v, int f) {
  edge *e;
  low[v] = dfn[v] = ++tms, rep[v] = v, stk[++top] = v;
  for (e = adj[v]; e; e = e->n)
    if (e->t != f && !dfn[e->t])
      dfs(e->t, v), low[v] = min(low[v], low[e->t]);
    else if (e->t != f)
      low[v] = min(low[v], dfn[e->t]);
  int u;
  if (low[v] == dfn[v])
    for (rep[v] = v; (u = stk[top--]) != v;) rep[u] = v;
}
void dfs2(int v, int f) {
  Q[++tail] = v, size[v] = 1, tid[v] = tid[f] + ways[v], fth[v] = f,
  depth[v] = depth[f] + 1;
  for (edge *e = adj[v]; e; e = e->n)
    if (e->t != f)
      dfs2(e->t, v), size[v] += size[e->t],
          size[aux[v]] < size[e->t] ? aux[v] = e->t : 0;
}
int LCA(int s, int t) {
  for (; root[s] != root[t]; s = fth[root[s]])
    if (depth[root[s]] < depth[root[t]]) swap(s, t);
  return depth[s] < depth[t] ? s : t;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1, s, t; i <= m; ++i) cin >> s >> t, adde(s, t), adde(t, s);
  dfs(1, 0);
  for (int i = 1; i <= n; ++i)
    if (rep[i] != i) ways[rep[i]] = 1;
  set<pair<int, int> > E;
  for (int v = 1; v <= n; ++v)
    for (edge *e = adj[v]; e; e = e->n)
      if (rep[v] < rep[e->t]) E.insert(make_pair(rep[v], rep[e->t]));
  memset(adj, 0, sizeof(adj)), eptr = graph;
  for_each(E.begin(), E.end(), [](pair<int, int> e) {
    adde(e.first, e.second);
    adde(e.second, e.first);
  });
  dfs2(1, 1);
  assert(tail == E.size() + 1);
  for (int i = 1, v; v = Q[i], i <= tail; ++i)
    if (!root[v])
      for (int u = v; u; u = aux[u]) root[u] = v;
  int K, s, t;
  for (cin >> K; K--;) {
    cin >> s >> t, s = rep[s], t = rep[t];
    int x = LCA(s, t);
    cout << fpm(2, tid[s] + tid[t] - tid[x] * 2 + ways[x], mod) << endl;
  }
  return 0;
}
