#include <bits/stdc++.h>
using namespace std;
int read();
const int N = 200005, P = 1000000007;
int n, m, ic;
struct Edge {
  int v, nxt;
} e[N << 1];
int fir[N], o = 1;
void add(int u, int v) {
  e[++o] = (Edge){v, fir[u]};
  fir[u] = o;
}
vector<int> to[N];
void link(int x, int y) {
  to[x].push_back(y);
  to[y].push_back(x);
}
int dfn[N], low[N], now, sta[N], top, pw[N], mk[N], bl[N], f[N];
bool isbg[N << 1];
void Tarjan(int u, int ie) {
  dfn[u] = low[u] = ++now;
  sta[++top] = u;
  for (int i = fir[u], v; i; i = e[i].nxt) {
    v = e[i].v;
    if (!dfn[v]) {
      Tarjan(v, i);
      low[u] = min(low[u], low[v]);
      if (dfn[u] < low[v]) isbg[i] = isbg[i ^ 1] = 1;
    } else if (i ^ (ie ^ 1))
      low[u] = min(low[u], dfn[v]);
  }
}
int tot;
void dfs3(int u) {
  bl[u] = ic;
  ++tot;
  for (int i = fir[u], v; i; i = e[i].nxt) {
    v = e[i].v;
    if (isbg[i] || bl[v]) continue;
    dfs3(v);
  }
}
void dccwork() {
  for (int(i) = (1); (i) <= (n); ++(i))
    if (!bl[i]) {
      ++ic;
      tot = 0;
      dfs3(i);
      if (tot > 1) f[bl[i]] = 1;
    }
  for (int i = 2; i <= o; i += 2)
    if (bl[e[i].v] ^ bl[e[i ^ 1].v]) link(bl[e[i].v], bl[e[i ^ 1].v]);
}
int sz[N], son[N], tp[N], dep[N], fa[N];
void dfs(int u) {
  sz[u] = 1;
  for (int v : to[u])
    if (v != fa[u]) {
      f[v] += f[u];
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs(v);
      sz[u] += sz[v];
      if (sz[son[u]] < sz[v]) son[u] = v;
    }
}
void dfs2(int u, int t) {
  tp[u] = t;
  if (son[u]) dfs2(son[u], t);
  for (int v : to[u])
    if (v != son[u] && v != fa[u]) dfs2(v, v);
}
int getlca(int x, int y) {
  while (tp[x] ^ tp[y]) {
    if (dep[tp[x]] < dep[tp[y]]) swap(x, y);
    x = fa[tp[x]];
  }
  return dep[x] < dep[y] ? x : y;
}
int cnt(int x, int y, int z = 0) {
  z = getlca(x, y);
  return f[x] + f[y] - f[z] - f[fa[z]];
}
int main() {
  n = read(), m = read();
  for (int i = 1, x, y; i <= m; ++i)
    x = read(), y = read(), add(x, y), add(y, x);
  Tarjan(1, 0);
  dccwork();
  dfs(1);
  dfs2(1, 1);
  pw[0] = 1;
  for (int(i) = (1); (i) <= (n); ++(i)) pw[i] = (pw[i - 1] << 1) % P;
  int Q = read();
  for (int i = 1, x, y; i <= Q; ++i) {
    x = read(), y = read();
    printf("%d\n", pw[cnt(bl[x], bl[y])]);
  }
  return 0;
}
inline int read() {
  register int x = 0, f = 1;
  register char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f * x;
}
