#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
const int MOD = 1e9 + 7;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
int n, m, q, tot, cnt, Index, a[M], f[M];
int dfn[M], low[M], in[M], col[M], pd[M];
int dep[M], fa[M][20], sum[M], pw[M];
stack<int> s;
vector<int> g[M];
struct EDGE {
  int v, nxt;
} e[2 * M];
void dfs(int u, int p) {
  dfn[u] = low[u] = ++Index;
  in[u] = 1;
  s.push(u);
  for (int i = f[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == p) continue;
    if (!dfn[v]) {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
    } else if (in[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    cnt++;
    int v = 0;
    do {
      v = s.top();
      s.pop();
      col[v] = cnt;
      in[v] = 0;
    } while (v != u);
  }
}
void dfs1(int u, int p) {
  fa[u][0] = p;
  dep[u] = dep[p] + 1;
  sum[u] = sum[p] + (pd[u] > 1);
  for (int i = 1; i < 20; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int i = 0; i < g[u].size(); i++)
    if (!dep[g[u][i]]) dfs1(g[u][i], u);
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 19; i >= 0; i--)
    if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (fa[u][i] ^ fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
int qkpow(int a, int b) {
  int r = 1;
  while (b > 0) {
    if (b & 1) r = 1ll * r * a % MOD;
    a = 1ll * a * a % MOD;
    b >>= 1;
  }
  return r;
}
signed main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    e[++tot] = EDGE{v, f[u]}, f[u] = tot;
    e[++tot] = EDGE{u, f[v]}, f[v] = tot;
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) dfs(i, 0);
  for (int i = 1; i <= n; i++) {
    int u = col[i];
    pd[u]++;
    for (int j = f[i]; j; j = e[j].nxt) {
      int v = col[e[j].v];
      if (u == v) continue;
      g[u].push_back(v);
    }
  }
  dfs1(1, 0);
  q = read();
  pw[0] = 1;
  for (int i = 1; i <= n; i++) pw[i] = pw[i - 1] * 2 % MOD;
  while (q--) {
    int u = col[read()], v = col[read()], t = lca(u, v);
    int tmp = sum[u] + sum[v] - 2 * sum[t] + (pd[t] > 1);
    printf("%d\n", pw[tmp]);
  }
  return 0;
}
