#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 15;
const int maxm = 1e6 + 15;
const int mod = 1e9 + 7;
struct Edge {
  int to, next;
} edge[maxm];
int head[maxn], dfn[maxn], bccno[maxn], low[maxn];
int ecnt, cnt, bcnt;
void add(int u, int v) {
  edge[ecnt].to = v;
  edge[ecnt].next = head[u];
  head[u] = ecnt++;
}
void init() {
  ecnt = 0;
  memset(dfn, 0, sizeof dfn);
  memset(head, -1, sizeof head);
}
stack<int> Stack;
void tarjan(int fa, int u) {
  dfn[u] = low[u] = ++cnt;
  Stack.push(u);
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (!dfn[v]) {
      tarjan(u, v);
      low[u] = min(low[u], low[v]);
    } else if (v != fa)
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    int v;
    bcnt++;
    do {
      v = Stack.top();
      Stack.pop();
      bccno[v] = bcnt;
    } while (v != u);
  }
}
long long quickMod(long long y) {
  long long res = 1, x = 2;
  while (y) {
    if (y & 1) res = res * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return res;
}
int w[maxn], x[maxn], y[maxn];
namespace hld {
int son[maxn], par[maxn], size[maxn], top[maxn];
int tid[maxn], dep[maxn], c[maxn], tot, n;
void init(int _n) {
  n = _n, tot = 0;
  memset(tid, 0, sizeof tid);
  memset(c, 0, sizeof c);
}
void dfs1(int u, int fa, int depth = 0) {
  par[u] = fa;
  dep[u] = depth;
  size[u] = 1;
  son[u] = 0;
  int maxx = 0;
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (v == fa) continue;
    dfs1(v, u, depth + 1);
    size[u] += size[v];
    if (size[v] > maxx) {
      maxx = size[v];
      son[u] = v;
    }
  }
}
int lowbit(int x) { return x & -x; }
void Add(int x, int y) {
  for (; x <= n; x += lowbit(x)) c[x] += y;
}
void dfs2(int u, int acs) {
  tid[u] = ++tot, top[u] = acs;
  if (w[u]) Add(tot, 1);
  if (!son[u]) return;
  dfs2(son[u], acs);
  for (int i = head[u]; ~i; i = edge[i].next) {
    int v = edge[i].to;
    if (tid[v]) continue;
    dfs2(v, v);
  }
}
int sum(int x) {
  int res = 0;
  for (; x; x -= lowbit(x)) res += c[x];
  return res;
}
int query(int u, int v) {
  int f1 = top[u], f2 = top[v], res = 0;
  while (f1 != f2) {
    if (dep[f1] < dep[f2]) swap(f1, f2), swap(u, v);
    res += sum(tid[u]) - sum(tid[f1] - 1);
    u = par[f1], f1 = top[u];
  }
  if (dep[u] > dep[v]) swap(u, v);
  return res += sum(tid[v]) - sum(tid[u] - 1);
}
}  // namespace hld
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  init();
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    add(u, v);
    add(v, u);
    x[i] = u, y[i] = v;
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(0, i);
  for (int i = 1; i <= n; i++) w[bccno[i]]++;
  for (int i = 1; i <= bcnt; i++) w[i] = (w[i] == 1 ? 0 : 1);
  ecnt = 0;
  memset(head, -1, sizeof head);
  for (int i = 1; i <= m; i++) {
    int u = bccno[x[i]], v = bccno[y[i]];
    if (u == v) continue;
    add(u, v), add(v, u);
  }
  int k;
  scanf("%d", &k);
  hld::init(n);
  hld::dfs1(1, 0), hld::dfs2(1, 1);
  while (k--) {
    int u, v;
    scanf("%d %d", &u, &v);
    long long ans = quickMod(hld::query(bccno[u], bccno[v]));
    if (ans >= mod) ans -= mod;
    printf("%d\n", ans);
  }
  return 0;
}
