#include <bits/stdc++.h>
using std::cerr;
using std::endl;
const int N = 3e5 + 10, P = 1e9 + 7;
int n, m, q, pow2[N];
std::vector<int> G[N], T[N];
int dfn[N], low[N], num, stk[N], top, cnt, tag[N], bel[N];
void tarjan(int x, int fa) {
  dfn[x] = low[x] = ++num;
  stk[++top] = x;
  for (int y : G[x]) {
    if (y == fa) continue;
    if (!low[y]) {
      tarjan(y, x);
      low[x] = std::min(low[x], low[y]);
      if (low[y] >= dfn[x]) {
        if (low[y] > dfn[x]) {
          --top;
        } else {
          ++cnt;
          for (int z = 0; z != y; --top) {
            z = stk[top];
            bel[z] = cnt;
          }
          bel[x] = cnt;
        }
      }
    } else
      low[x] = std::min(low[x], dfn[y]);
  }
}
int dad[N][20], val[N], dep[N], vis[N];
void dfs(int x, int fa) {
  dad[x][0] = fa, dep[x] = dep[fa] + 1;
  val[x] = val[fa] + (x > n);
  for (int i = 1; i <= 19; ++i) dad[x][i] = dad[dad[x][i - 1]][i - 1];
  for (int y : T[x])
    if (y != fa) dfs(y, x);
}
inline int get_lca(int x, int y) {
  if (dep[x] < dep[y]) std::swap(x, y);
  for (int i = 19; ~i; --i)
    if (dep[dad[x][i]] >= dep[y]) x = dad[x][i];
  if (x == y) return x;
  for (int i = 19; ~i; --i)
    if (dad[x][i] != dad[y][i]) x = dad[x][i], y = dad[y][i];
  return dad[x][0];
}
inline int query(int x, int y) {
  int lca = get_lca(x, y);
  int ret = val[x] + val[y] - val[lca] * 2;
  ret += (lca > n);
  return ret;
}
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  std::cin >> n >> m;
  for (int i = pow2[0] = 1; i <= n; ++i) pow2[i] = pow2[i - 1] * 2 % P;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    std::cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) bel[i] = i;
  cnt = n;
  tarjan(1, 0);
  for (int x = 1; x <= n; ++x) {
    for (int y : G[x]) {
      int nx = bel[x], ny = bel[y];
      if (nx != ny) {
        T[nx].push_back(ny);
      }
    }
  }
  dfs(bel[1], 0);
  std::cin >> q;
  while (q--) {
    int x, y;
    std::cin >> x >> y;
    x = bel[x], y = bel[y];
    int cnt = query(x, y);
    std::cout << pow2[cnt] << '\n';
  }
  return 0;
}
