#include <bits/stdc++.h>
using namespace std;
const int max_n = 1000 * 100 + 10, max_l = 20, M = 1e9 + 7;
vector<int> v[max_n], V[max_n];
int c[max_n], dad[max_n], par[max_n][max_l];
bool check[max_n], D[max_n];
int cnt[max_n], val[max_n], po[max_n], h[max_n], H[max_n];
void DFS(int u, int p = 0) {
  check[u] = true;
  for (auto i : V[u]) {
    if (!check[i]) {
      dad[i] = u;
      H[i] = H[u] + 1;
      DFS(i, u);
    } else if (i != p && H[i] < H[u]) {
      int x = u;
      while (x != i) {
        c[x] = i;
        x = dad[x];
      }
    }
  }
}
inline int get_par(int u, int p) {
  for (int i = 0; i < max_l; i++)
    if ((p >> i) & 1) u = par[u][i];
  return u;
}
void dfs(int u, int p = 0) {
  val[u] += D[u];
  for (auto i : v[u])
    if (i != p) {
      par[i][0] = u;
      for (int j = 1; j < max_l; j++) par[i][j] = par[par[i][j - 1]][j - 1];
      val[i] = val[u];
      h[i] = h[u] + 1;
      dfs(i, u);
    }
}
int lca(int x, int y) {
  if (h[x] > h[y]) swap(x, y);
  y = get_par(y, h[y] - h[x]);
  if (x == y) return x;
  for (int i = max_l - 1; i >= 0; i--)
    if (par[x][i] != par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  return par[x][0];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    V[x].push_back(y);
    V[y].push_back(x);
  }
  for (int i = 0; i < n; i++) c[i] = i;
  DFS(0);
  for (int i = 0; i < n; i++) {
    cnt[c[i]]++;
    for (auto j : V[i])
      if (c[i] != c[j]) v[c[i]].push_back(c[j]);
  }
  for (int i = 0; i < n; i++)
    if (cnt[i] > 1) D[i] = true;
  dfs(0);
  po[0] = 1;
  for (int i = 1; i <= n; i++) po[i] = (po[i - 1] * 2) % M;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    x = c[x];
    y = c[y];
    int z = lca(x, y);
    cout << po[val[x] + val[y] - 2 * val[z] + D[z]] << '\n';
  }
}
