#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX_N = 100 * 1000 + 10;
const int LOG = 20 + 5;
vector<int> adj_c[MAX_N];
vector<int> adj[MAX_N];
int h[MAX_N], dp[MAX_N];
int two[MAX_N] = {1};
int par[MAX_N][LOG];
int cmp[MAX_N], cnt;
int sz[MAX_N];
void cycle(int u, int v) {
  cmp[u] = cnt, sz[cnt]++;
  while (u != v) u = par[u][0], cmp[u] = cnt, sz[cnt]++;
  cnt++;
}
void dfs(int u) {
  h[u] = 1;
  for (auto v : adj[u]) {
    if (!h[v])
      par[v][0] = u, dfs(v);
    else if (v != par[u][0] && cmp[v] == -1)
      cycle(u, v);
  }
  if (cmp[u] == -1) cycle(u, u);
}
void lca_dfs(int c, int dad, int l) {
  par[c][0] = dad, h[c] = l;
  dp[c] = dp[dad] + (sz[c] > 1);
  for (int i = 1; i < LOG; i++) par[c][i] = par[par[c][i - 1]][i - 1];
  for (auto x : adj_c[c])
    if (x != dad) lca_dfs(x, c, l + 1);
}
int get_par(int c, int k) {
  for (int i = 0; i < LOG; i++)
    if (k >> i & 1) c = par[c][i];
  return c;
}
int lca(int c, int x) {
  if (h[c] < h[x]) swap(c, x);
  c = get_par(c, h[c] - h[x]);
  if (c == x) return c;
  for (int i = LOG - 1; ~i; i--)
    if (par[c][i] != par[x][i]) c = par[c][i], x = par[x][i];
  return par[c][0];
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  for (int i = 1; i < MAX_N; i++) two[i] = 2LL * two[i - 1] % MOD;
  int n, m;
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  memset(cmp, -1, sizeof cmp), dfs(0);
  for (int i = 0; i < n; i++)
    for (auto v : adj[i])
      if (cmp[i] != cmp[v]) adj_c[cmp[i]].push_back(cmp[v]);
  lca_dfs(0, 0, 0);
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    u = cmp[u], v = cmp[v];
    int x = lca(u, v);
    cout << two[dp[u] + dp[v] - 2 * dp[x] + (sz[x] > 1)] << endl;
  }
  return 0;
}
