#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, m, q, dfn[N], low[N], col[N], cnt, w, fa[N][21], sum[N], de[N];
int tot, first[N], nxt[N * 2], point[N * 2], fb[N * 2];
vector<int> e[N];
inline void add(int &a, int b) {
  a = ((a + b >= 1000000007) ? a + b - 1000000007 : a + b);
}
inline void del(int &a, int b) {
  a = ((a - b < 0) ? a - b + 1000000007 : a - b);
}
inline void mul(int &a, int b) { a = 1ll * a * b % 1000000007; }
inline int m_pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) mul(ans, a);
    b >>= 1;
    mul(a, a);
  }
  return ans;
}
inline int read() {
  int f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
inline void add_edge(int x, int y) {
  nxt[++tot] = first[x];
  first[x] = tot;
  point[tot] = y;
}
void dfs(int x, int in) {
  dfn[x] = low[x] = ++cnt;
  for (int i = first[x]; i != -1; i = nxt[i]) {
    int u = point[i];
    if (i == in || i == (in ^ 1)) continue;
    if (!dfn[u]) {
      dfs(u, i);
      low[x] = min(low[x], low[u]);
      if (low[u] > dfn[x]) fb[i] = fb[i ^ 1] = 1;
    } else
      low[x] = min(low[x], dfn[u]);
  }
}
void dfs1(int x, int c) {
  col[x] = c;
  cnt++;
  for (int i = first[x]; i != -1; i = nxt[i]) {
    int u = point[i];
    if (col[u] || fb[i]) continue;
    dfs1(u, c);
  }
}
void dfs2(int x, int father) {
  fa[x][0] = father;
  for (int i = 0; i < (int)e[x].size(); i++) {
    int u = e[x][i];
    if (u == fa[x][0]) continue;
    de[u] = de[x] + 1;
    sum[u] += sum[x];
    dfs2(u, x);
  }
}
inline int lca(int a, int b) {
  if (de[a] > de[b]) swap(a, b);
  for (int i = 20; i >= 0; i--)
    if (de[fa[b][i]] >= de[a]) b = fa[b][i];
  if (a == b) return a;
  for (int i = 20; i >= 0; i--)
    if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i];
  return fa[a][0];
}
signed main() {
  tot = -1;
  memset(first, -1, sizeof(first));
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs(1, -1);
  for (int i = 1; i <= n; i++)
    if (!col[i]) cnt = 0, dfs1(i, ++w), sum[w] = (cnt > 1);
  for (int i = 0; i <= tot; i++) {
    if (!fb[i]) continue;
    e[col[point[i]]].push_back(col[point[i ^ 1]]);
  }
  dfs2(1, 1);
  for (int j = 1; j <= 20; j++)
    for (int i = 1; i <= w; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  q = read();
  while (q--) {
    int x = col[read()], y = col[read()];
    int LCA = lca(x, y), ans = sum[x] + sum[y] - sum[LCA];
    if (LCA != 1) ans -= sum[fa[LCA][0]];
    printf("%d\n", m_pow(2, ans));
  }
}
