#include <bits/stdc++.h>
using namespace std;
const int MD = 1e9 + 7;
const int N = 101000, M = 201000;
int n, m;
int rch[M], trch[M], nxt[M], tnxt[M];
int hd[N], thd[N];
int dg, tdg;
void addtedge(int a, int b) {
  trch[tdg] = b;
  tnxt[tdg] = thd[a];
  thd[a] = tdg++;
  trch[tdg] = a;
  tnxt[tdg] = thd[b];
  thd[b] = tdg++;
}
void addedge(int a, int b) {
  rch[dg] = b;
  nxt[dg] = hd[a];
  hd[a] = dg++;
  rch[dg] = a;
  nxt[dg] = hd[b];
  hd[b] = dg++;
}
int lw[N], dfn[N];
int tm;
int stk[N];
int tp;
int clr[N], clrsz[N];
int clrcnt;
void tarjan(int u, int p) {
  lw[u] = dfn[u] = ++tm;
  stk[tp++] = u;
  for (int i = thd[u]; i != -1; i = tnxt[i]) {
    int v = trch[i];
    if (v == p) continue;
    if (!dfn[v]) {
      tarjan(v, u);
      lw[u] = min(lw[u], lw[v]);
    } else
      lw[u] = min(dfn[v], lw[u]);
  }
  if (lw[u] == dfn[u]) {
    do {
      clrsz[clrcnt]++;
      clr[stk[tp - 1]] = clrcnt;
      tp--;
    } while (stk[tp] != u);
    clrcnt++;
  }
}
int c2[N];
int hlhvy[N];
int hlp[N], hld[N], hlsz[N];
int hlc[N], hlhd[N];
void dfs(int u) {
  hlsz[u] = 1;
  if (clrsz[u] > 2) c2[u] = 1;
  if (hlp[u] != -1) c2[u] += c2[hlp[u]];
  for (int i = hd[u]; i != -1; i = nxt[i]) {
    int v = rch[i];
    if (v == hlp[u]) continue;
    hlp[v] = u;
    hld[v] = hld[u] + 1;
    dfs(v);
    hlsz[u] += hlsz[v];
    if (hlhvy[u] == -1 || hlsz[v] > hlsz[hlhvy[u]]) hlhvy[u] = v;
  }
}
void heavylight() {
  memset(hlhvy, -1, sizeof(hlhvy));
  hlp[0] = -1;
  hld[0] = 1;
  dfs(0);
  int c = 0;
  for (int i = 0; i < clrcnt; i++)
    if (hlp[i] == -1 || hlhvy[hlp[i]] != i) {
      for (int k = i; k != -1; k = hlhvy[k]) {
        hlc[k] = c;
        hlhd[k] = i;
      }
      c++;
    }
}
int lca(int x, int y) {
  while (hlc[x] != hlc[y]) {
    if (hld[hlhd[x]] < hld[hlhd[y]])
      y = hlp[hlhd[y]];
    else
      x = hlp[hlhd[x]];
  }
  return hld[x] > hld[y] ? y : x;
}
int quickpow(int n, int m) {
  int ret = 1;
  while (m) {
    if (m & 1) ret = (int)((long long)ret * n % MD);
    m >>= 1;
    n = (int)((long long)n * n % MD);
  }
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  int a, b;
  memset(thd, -1, sizeof(thd));
  memset(hd, -1, sizeof(hd));
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    addtedge(a, b);
  }
  tarjan(1, 0);
  for (int i = 1; i <= n; i++)
    for (int j = thd[i]; j != -1; j = tnxt[j])
      if (clr[i] < clr[trch[j]]) addedge(clr[i], clr[trch[j]]);
  heavylight();
  int k, x, y;
  scanf("%d", &k);
  while (k--) {
    scanf("%d%d", &x, &y);
    x = clr[x];
    y = clr[y];
    int z = lca(x, y);
    int cc = c2[x] + c2[y] - 2 * c2[z];
    if (clrsz[z] > 2) cc += 1;
    printf("%d\n", quickpow(2, cc));
  }
  return 0;
}
