#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long n, m, q, num[100010], depth[100010],
    len = 0, dou[100010], par[30][100010], ti[100010], num2[100010], pw[100010];
bool vis[100010];
stack<long long> st;
vector<long long> g[100010], v[100010];
vector<pair<long long, long long> > e;
long long dfs(long long pos, long long no, long long d) {
  depth[pos] = d;
  vis[pos] = true;
  st.push(pos);
  long long low = d;
  for (int i = 0; i < g[pos].size(); i++) {
    if (g[pos][i] == no) continue;
    if (depth[g[pos][i]] < d)
      low = min(low, depth[g[pos][i]]);
    else if (!vis[g[pos][i]])
      low = min(low, dfs(g[pos][i], pos, d + 1));
  }
  if (low == d) {
    len++;
    int nn = 0;
    while (true) {
      nn++;
      int tmp = st.top();
      st.pop();
      v[len].push_back(tmp);
      num[tmp] = len;
      if (tmp == pos) break;
    }
    if (nn == 1)
      dou[len] = 0;
    else
      dou[len] = 1;
  }
  return low;
}
void dfs2(int pos, int no, int d, int t, int val) {
  num2[pos] = dou[pos] + val;
  ti[pos] = t;
  vis[pos] = true;
  depth[pos] = d;
  par[0][pos] = no;
  for (int i = 0; i < g[pos].size(); i++)
    if (g[pos][i] != no) dfs2(g[pos][i], pos, d + 1, t, num2[pos]);
}
int lca(int pos1, int pos2) {
  if (depth[pos1] < depth[pos2]) swap(pos1, pos2);
  for (int i = 20; i >= 0; i--)
    if (depth[pos1] - (int)pow(2, i) >= depth[pos2]) pos1 = par[i][pos1];
  for (int i = 20; i >= 0; i--) {
    if (par[i][pos1] != par[i][pos2]) {
      pos1 = par[i][pos1];
      pos2 = par[i][pos2];
    }
  }
  if (pos1 == pos2) return pos1;
  return par[0][pos1];
}
int main() {
  pw[0] = 1;
  for (int i = 1; i <= 100005; i++) pw[i] = pw[i - 1] * 2 % MOD;
  cin >> n >> m;
  long long x, y;
  for (int i = 0; i < m; i++) {
    scanf("%I64d%I64d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
    e.push_back(make_pair(x, y));
  }
  for (int i = 0; i < n + 5; i++) depth[i] = 1e18;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    dfs(i, 0, 0);
  }
  for (int i = 1; i <= n; i++) g[i].clear();
  for (int i = 0; i < m; i++) {
    g[num[e[i].first]].push_back(num[e[i].second]);
    g[num[e[i].second]].push_back(num[e[i].first]);
  }
  for (int i = 1; i <= len; i++) {
    sort(g[i].begin(), g[i].end());
    g[i].erase(unique(g[i].begin(), g[i].end()), g[i].end());
    for (int j = 0; j < g[i].size(); j++) {
      if (g[i][j] == i) {
        g[i].erase(g[i].begin() + j);
        break;
      }
    }
  }
  for (int i = 0; i < 25; i++)
    for (int j = 0; j < 100005; j++) par[i][j] = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= len; i++) {
    if (vis[i]) continue;
    dfs2(i, 0, 0, i, 0);
  }
  for (int i = 0; i < 20; i++) {
    for (int j = 1; j <= len; j++) {
      if (par[i][j] == 0) continue;
      par[i + 1][j] = par[i][par[i][j]];
    }
  }
  cin >> q;
  for (int qn = 0; qn < q; qn++) {
    scanf("%I64d%I64d", &x, &y);
    if (ti[num[x]] != ti[num[y]]) {
      puts("0");
      continue;
    }
    long long z = lca(num[x], num[y]);
    long long res = num2[num[x]] + num2[num[y]] - num2[z] * 2 + dou[z];
    printf("%I64d\n", pw[res]);
  }
  return 0;
}
