#include <bits/stdc++.h>
using namespace std;
const int N = 100005, M = 700005, mod = 1000000007, K = 18;
long long qpow(long long a, long long b) {
  long long c = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) c = c * a % mod;
  return c;
}
struct Graph {
  int h[N], p[M], v[M], cnt, pos[N], fa[N][19], num[N];
  int blg[N], sk[N], ins[N], dfn[N], low[N], bcc, n;
  long long dis[N];
  int ts, vis[M], top, dep[N], id[N];
  Graph() {
    cnt = 1;
    bcc = 0;
    ts = 0;
    top = 0;
  }
  void add(int a, int b) {
    p[++cnt] = h[a];
    v[cnt] = b;
    h[a] = cnt;
  }
  void tarjan(int x) {
    int i;
    dfn[x] = low[x] = ++ts;
    sk[top++] = x;
    ins[x] = 1;
    for (i = h[x]; i; i = p[i]) {
      if (vis[i]) continue;
      vis[i] = vis[i ^ 1] = 1;
      if (!dfn[v[i]]) {
        tarjan(v[i]);
        low[x] = min(low[x], low[v[i]]);
      } else if (ins[v[i]])
        low[x] = min(low[x], dfn[v[i]]);
    }
    if (low[x] == dfn[x]) {
      num[++bcc] = 0;
      do {
        i = sk[--top];
        ins[i] = 0;
        blg[i] = bcc;
        num[bcc]++;
      } while (i != x);
      num[bcc] = num[bcc] > 1;
    }
  }
  void build_from(const Graph &g) {
    for (int i = 1; i <= g.n; ++i)
      for (int j = g.h[i]; j; j = g.p[j])
        if (g.blg[i] != g.blg[g.v[j]]) add(g.blg[i], g.blg[g.v[j]]);
  }
  void dfs(int x, int f, int *data) {
    int i;
    pos[x] = ++ts;
    id[ts] = x;
    fa[x][0] = f;
    dep[x] = dep[f] + 1;
    dis[x] = dis[f] + data[x];
    for (i = 1; i <= K; ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1];
    for (i = h[x]; i; i = p[i])
      if (v[i] != f) dfs(v[i], x, data);
  }
  int lca(int x, int y) {
    if (dep[x] < dep[y]) swap(x, y);
    int t = dep[x] - dep[y], i;
    for (i = 0; i <= K; ++i)
      if ((1 << i) & t) x = fa[x][i];
    for (i = K; i >= 0; --i)
      if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
    return x == y ? x : fa[x][0];
  }
} g, ng;
long long query(int a, int b) {
  a = g.blg[a];
  b = g.blg[b];
  int c = ng.lca(a, b);
  return ng.dis[a] + ng.dis[b] - 2 * ng.dis[c] + g.num[c];
}
int main() {
  int n, m, i, q, a, b;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; ++i) scanf("%d%d", &a, &b), g.add(a, b), g.add(b, a);
  g.n = n;
  g.tarjan(1);
  ng.build_from(g);
  ng.dfs(1, 0, g.num);
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &a, &b);
    printf("%I64d\n", qpow(2, query(a, b)));
  }
  return 0;
}
