#include <bits/stdc++.h>
using namespace std;
struct query {
  int u, v, id, r;
} q[222222];
vector<int> node1[222222], node2[222222], Q[222222];
int dfn[222222], low[222222], id[222222], cnt[222222], dp[222222],
    parent[222222], _n;
bool visited[222222];
stack<int> s;
void dfs(int now, int from, int deepth) {
  dfn[now] = low[now] = deepth;
  visited[now] = true;
  s.push(now);
  for (int i = 0; i < node1[now].size(); i++) {
    if (node1[now][i] == from) continue;
    if (visited[node1[now][i]])
      low[now] = min(low[now], low[node1[now][i]]);
    else {
      dfs(node1[now][i], now, deepth + 1);
      low[now] = min(low[now], low[node1[now][i]]);
    }
  }
  if (low[now] < dfn[now]) return;
  int v;
  _n++;
  do {
    v = s.top();
    s.pop();
    id[v] = _n;
    cnt[_n]++;
  } while (now != v);
}
void dfs1(int now, int from, int all) {
  if (cnt[now] > 1) all++;
  dp[now] = all;
  visited[now] = true;
  for (int i = 0; i < node2[now].size(); i++) {
    if (node2[now][i] == from) continue;
    if (visited[node2[now][i]]) continue;
    dfs1(node2[now][i], now, all);
  }
}
int find(int x) {
  int tempx = x;
  while (parent[tempx] >= 0) tempx = parent[tempx];
  while (parent[x] >= 0) {
    int k = parent[x];
    parent[x] = tempx;
    x = k;
  }
  return tempx;
}
void tarjan(int now, int from) {
  for (int i = 0; i < node2[now].size(); i++) {
    if (node2[now][i] == from) continue;
    if (visited[node2[now][i]] == false) tarjan(node2[now][i], now);
    parent[node2[now][i]] = now;
  }
  visited[now] = true;
  for (int i = 0; i < Q[now].size(); i++) {
    int k = Q[now][i];
    int u;
    if (q[k].u == now)
      u = q[k].v;
    else
      u = q[k].u;
    if (visited[u] == true) q[k].r = find(u);
  }
}
long long output(long long num) {
  long long ret = 1, temp = 2;
  while (num) {
    if (num % 2) ret = (ret * temp) % 1000000007ll;
    num /= 2;
    temp = (temp * temp) % 1000000007ll;
  }
  return ret;
}
int main() {
  int n, m;
  cin >> n >> m;
  _n = 0;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    node1[u].push_back(v);
    node1[v].push_back(u);
  }
  dfs(1, -1, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < node1[i].size(); j++) {
      if (id[i] != id[node1[i][j]]) {
        node2[id[i]].push_back(id[node1[i][j]]);
        node2[id[node1[i][j]]].push_back(id[i]);
      }
    }
  }
  memset(visited, false, sizeof visited);
  dfs1(1, -1, 0);
  int k;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    int u, v;
    cin >> u >> v;
    u = id[u];
    v = id[v];
    q[i].u = u;
    q[i].v = v;
    Q[u].push_back(i);
    Q[v].push_back(i);
  }
  memset(parent, -1, sizeof parent);
  memset(visited, false, sizeof visited);
  tarjan(1, -1);
  for (int i = 1; i <= k; i++) {
    int num = dp[q[i].u] + dp[q[i].v] - 2 * dp[q[i].r];
    if (cnt[q[i].r] > 1) num++;
    cout << output(num) << endl;
  }
  return 0;
}
