#include <bits/stdc++.h>
using namespace std;
inline void in(int &x) {
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
int n, m, dfn[100005], dfsc, low[100005], stac[100005], top, tag[100005], tagc,
    sz[100005], dp[100005], fa[18][100005], dep[100005], q;
vector<int> v[100005], new_v[100005];
inline void chmin(int &x, int y) { x = x < y ? x : y; }
void tarjan(int from, int f) {
  dfn[from] = ++dfsc;
  low[from] = dfsc;
  stac[top++] = from;
  for (int i = 0; i < v[from].size(); ++i) {
    int to = v[from][i];
    if (to == f) continue;
    if (!dfn[to]) {
      tarjan(to, from);
      chmin(low[from], low[to]);
    } else
      chmin(low[from], dfn[to]);
  }
  if (low[from] == dfn[from]) {
    ++tagc;
    while (stac[top] != from) {
      tag[stac[top - 1]] = tagc;
      ++sz[tagc];
      --top;
    }
  }
}
void dfs(int from, int f) {
  dep[from] = dep[f] + 1;
  dp[from] = dp[f] + (sz[from] > 1);
  fa[0][from] = f;
  for (int i = 0; i < new_v[from].size(); ++i) {
    int to = new_v[from][i];
    if (to == f) continue;
    dfs(to, from);
  }
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int del = dep[x] - dep[y];
  for (int i = 0; del >> i; ++i)
    if ((del >> i) & 1) x = fa[i][x];
  if (x == y) return x;
  for (int i = 17; i >= 0; --i)
    if (fa[i][x] != fa[i][y]) x = fa[i][x], y = fa[i][y];
  return fa[0][x];
}
inline int ksm(int x, int p) {
  int ret = 1;
  while (p) {
    if (p & 1) ret = 1LL * ret * x % 1000000007;
    p >>= 1;
    x = 1LL * x * x % 1000000007;
  }
  return ret;
}
int main() {
  in(n);
  in(m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    in(x);
    in(y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  tarjan(1, 0);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < v[i].size(); ++j) {
      int to = v[i][j];
      if (tag[i] != tag[to]) new_v[tag[i]].push_back(tag[to]);
    }
  }
  dfs(1, 0);
  for (int i = 1; i < 18; ++i)
    for (int j = 1; j <= tagc; ++j) fa[i][j] = fa[i - 1][fa[i - 1][j]];
  in(q);
  while (q--) {
    int x, y;
    in(x);
    in(y);
    x = tag[x];
    y = tag[y];
    int lca = LCA(x, y);
    printf("%d\n", ksm(2, dp[x] + dp[y] - (dp[lca] << 1) + (sz[lca] > 1)));
  }
  return 0;
}
