#include <bits/stdc++.h>
const int N = 100010;
const int D = 21;
const int mod = 1e9 + 7;
int S[N], top;
int scc[N], pre[N], sccno, dfs_clock;
int cycle[N];
std::vector<int> G[N], LY[N];
int dfs(int u, int f) {
  int lowu = pre[u] = ++dfs_clock;
  S[top++] = u;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v == f) continue;
    if (!pre[v]) {
      lowu = std::min(lowu, dfs(v, u));
    } else if (!scc[v]) {
      lowu = std::min(lowu, pre[v]);
    }
  }
  if (lowu == pre[u]) {
    for (int v = -1; v != u;) {
      v = S[--top];
      scc[v] = sccno;
      cycle[sccno]++;
    }
    sccno++;
  }
  return lowu;
}
int shortcut[D][N], dep[N], cnt[N];
int *fa = shortcut[0];
void dfs(int u) {
  cnt[u] = cycle[u] > 2 ? 1 : 0;
  if (~fa[u]) cnt[u] += cnt[fa[u]];
  pre[u] = 1;
  for (int i = 0; i < LY[u].size(); i++) {
    int v = LY[u][i];
    if (pre[v]) continue;
    dep[v] = dep[u] + 1;
    fa[v] = u;
    dfs(v);
  }
}
int get_lca(int a, int b) {
  if (dep[a] < dep[b]) std::swap(a, b);
  for (int i = D - 1; ~i; i--)
    if (dep[a] - dep[b] >> i & 1) a = shortcut[i][a];
  if (a == b) return a;
  for (int i = D - 1; ~i; i--)
    if (shortcut[i][a] != shortcut[i][b]) {
      a = shortcut[i][a];
      b = shortcut[i][b];
    }
  return fa[a];
}
int dsu[N];
int find(int x) { return x == dsu[x] ? x : dsu[x] = find(dsu[x]); }
int pow_mod(long long x, int bit) {
  long long ret = 1;
  while (bit) {
    if (bit & 1) ret = ret * x % mod;
    x = x * x % mod;
    bit >>= 1;
  }
  return ret;
}
int main() {
  int n, m, u, v, q;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) dsu[i] = i;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
    dsu[find(u)] = find(v);
  }
  for (int i = 0; i < n; i++)
    if (!pre[i]) {
      dfs(i, -1);
    }
  for (int u = 0; u < n; u++) {
    for (int i = 0; i < G[u].size(); i++) {
      v = G[u][i];
      if (scc[v] != scc[u]) LY[scc[u]].push_back(scc[v]);
    }
    std::sort(LY[scc[u]].begin(), LY[scc[u]].end());
    LY[scc[u]].erase(unique(LY[scc[u]].begin(), LY[scc[u]].end()),
                     LY[scc[u]].end());
  }
  memset(pre, 0, sizeof pre);
  for (int u = 0; u < sccno; u++)
    if (!pre[u]) {
      dep[u] = 0;
      fa[u] = -1;
      dfs(u);
    }
  for (int i = 1; i < D; i++)
    for (int u = 0; u < sccno; u++) {
      int &res = shortcut[i][u];
      res = shortcut[i - 1][u];
      if (~res) res = shortcut[i - 1][res];
    }
  scanf("%d", &q);
  for (int _ = 0; _ < q; _++) {
    scanf("%d%d", &u, &v);
    u--, v--;
    if (find(u) != find(v))
      puts("0");
    else {
      u = scc[u], v = scc[v];
      int lca = get_lca(u, v);
      int num = cnt[u] + cnt[v] - 2 * cnt[lca] + (cycle[lca] > 2 ? 1 : 0);
      printf("%d\n", pow_mod(2, num));
    }
  }
  return 0;
}
