#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int mod = 1e9 + 7;
int low[maxn], dfn[maxn], belo[maxn];
int top, Time, ctot;
int st[maxn];
int n, m;
int cnt[maxn];
struct Edge {
  int u, v, vis, next;
} g[maxn << 1];
int head[maxn], E;
void add(int s, int t) {
  g[E] = (Edge){s, t, 0, head[s]};
  head[s] = E++;
}
void dfs(int u) {
  int v;
  st[++top] = u;
  low[u] = dfn[u] = ++Time;
  for (int i = head[u]; ~i; i = g[i].next) {
    if (g[i].vis) continue;
    g[i].vis = g[i ^ 1].vis = 1;
    v = g[i].v;
    if (!dfn[v]) {
      dfs(v);
      low[u] = min(low[u], low[v]);
    } else
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    ctot++;
    do {
      cnt[ctot]++;
      v = st[top--];
      belo[v] = ctot;
    } while (v != u);
  }
}
vector<int> G[maxn];
void bcc(int n) {
  int i;
  for (i = 1; i <= n; i++)
    if (!dfn[i]) dfs(i);
  for (int i = 0; i < E; i += 2) {
    int x = belo[g[i].u], y = belo[g[i].v];
    if (x != y) {
      G[x].push_back(y);
      G[y].push_back(x);
    }
  }
  for (i = 1; i <= ctot; i++)
    if (cnt[i] >= 2)
      cnt[i] = 1;
    else
      cnt[i] = 0;
}
int dep[maxn], p[maxn][22];
int val[maxn];
void DFS(int u, int fa) {
  dep[u] = dep[fa] + 1;
  p[u][0] = fa;
  val[u] = val[fa] + cnt[u];
  int i;
  dfn[u] = 1;
  for (i = 1; i < 18; i++) p[u][i] = p[p[u][i - 1]][i - 1];
  for (i = 0; i < (int)G[u].size(); i++) {
    int v = G[u][i];
    if (v == fa) continue;
    val[v] += val[u];
    DFS(v, u);
  }
}
int find(int a, int k) {
  int i;
  for (i = 0; i < 18; i++)
    if (k & (1 << i)) a = p[a][i];
  return a;
}
int lca(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  if (dep[a] < dep[b]) b = find(b, dep[b] - dep[a]);
  if (a != b) {
    for (int i = 18; i >= 0; i--)
      if (p[a][i] != p[b][i]) a = p[a][i], b = p[b][i];
    a = p[a][0], b = p[b][0];
  }
  return a;
}
long long two[100005];
int main() {
  ios::sync_with_stdio(false);
  two[0] = 1;
  for (int i = 1; i <= 100000; i++) two[i] = (two[i - 1] << 1) % mod;
  memset(head, -1, sizeof(head));
  cin >> n >> m;
  while (m--) {
    int x, y;
    cin >> x >> y;
    add(x, y);
    add(y, x);
  }
  bcc(n);
  cin >> m;
  int j;
  DFS(1, 0);
  while (m--) {
    int x, y;
    cin >> x >> y;
    x = belo[x], y = belo[y];
    int u = lca(x, y);
    cout << two[val[x] + val[y] - 2 * val[u] + cnt[u]] << endl;
  }
  return 0;
}
