#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int nr = 0;
void dfs(int akt, vector<vector<int> >& G, vector<bool>& odw, vector<int>& oj,
         vector<int>& pre, vector<int>& wlk, vector<int>& gora,
         vector<int>& sum) {
  odw[akt] = true;
  pre[akt] = nr;
  ++nr;
  int cykl = -1;
  vector<bool> uru(G[akt].size(), false);
  for (int i = 0; i < G[akt].size(); ++i) {
    if (!odw[G[akt][i]]) {
      oj[G[akt][i]] = akt;
      uru[i] = true;
      dfs(G[akt][i], G, odw, oj, pre, wlk, gora, sum);
    } else {
      if (G[akt][i] != oj[akt] && pre[G[akt][i]] < pre[akt]) cykl = G[akt][i];
    }
  }
  wlk[akt] = 1;
  for (int i = 0; i < G[akt].size(); ++i)
    if (uru[i]) wlk[akt] += wlk[G[akt][i]];
  if (cykl == -1) return;
  int t = akt;
  while (t != oj[cykl]) {
    gora[t] = cykl;
    t = oj[t];
  }
  sum[cykl] = 1;
}
void dfs2(int akt, vector<vector<int> >& G, vector<bool>& odw,
          vector<int>& sum) {
  odw[akt] = true;
  for (int i = 0; i < G[akt].size(); ++i) {
    if (!odw[G[akt][i]]) {
      sum[G[akt][i]] += sum[akt];
      dfs2(G[akt][i], G, odw, sum);
    }
  }
}
bool Przodek(int a, int b, vector<int>& pre, vector<int>& wlk) {
  return (pre[b] >= pre[a] && pre[b] <= pre[a] + wlk[a] - 1);
}
int LCA(int a, int b, vector<vector<int> >& P, vector<int>& pre,
        vector<int>& wlk) {
  if (Przodek(a, b, pre, wlk)) return a;
  if (Przodek(b, a, pre, wlk)) return b;
  for (int i = 16; i >= 0; --i) {
    int x = P[i][a];
    if (!Przodek(x, b, pre, wlk)) a = x;
  }
  return P[0][a];
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > G(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<bool> odw(n, false);
  vector<int> oj(n), pre(n), wlk(n), gora(n, -1), sum(n, 0);
  oj[0] = -1;
  dfs(0, G, odw, oj, pre, wlk, gora, sum);
  for (int i = 0; i < n; ++i) odw[i] = false;
  dfs2(0, G, odw, sum);
  vector<vector<int> > P(17, vector<int>(n));
  P[0][0] = 0;
  for (int i = 1; i < n; ++i) P[0][i] = oj[i];
  for (int i = 1; i < 17; ++i)
    for (int j = 0; j < n; ++j) P[i][j] = P[i - 1][P[i - 1][j]];
  vector<int> pot2(n + 1);
  pot2[0] = 1;
  for (int i = 1; i <= n; ++i) pot2[i] = (pot2[i - 1] * 2) % MOD;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    int lca = LCA(a, b, P, pre, wlk);
    if (lca == b) swap(a, b);
    int il = 0;
    if (lca == a) {
      il = sum[b] - (a != 0 ? sum[oj[a]] : 0);
      if (gora[a] != -1 && gora[a] != a) ++il;
    } else {
      il = sum[a] + sum[b] - sum[lca] - (lca != 0 ? sum[oj[lca]] : 0);
      if (gora[lca] != -1 && gora[lca] != lca) ++il;
    }
    cout << pot2[il] << endl;
  }
  return 0;
}
