#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f, mod = 1000000007;
const double pi = 3.1415926535897932, eps = 1e-6;
void chmax(int &x, int y) {
  if (x < y) x = y;
}
void chmin(int &x, int y) {
  if (x > y) x = y;
}
int n, m, k, pa[19][100005], low[100005], dep[100005], Dep[100005], num_cc,
    idx[100005], sum[19][100005], cnt[100005], pw2[100010];
bool vis[100005];
vector<int> v[100005], w[100005];
stack<int> ss;
void dfs(int x, int fa) {
  vis[x] = 1;
  low[x] = dep[x];
  ss.push(x);
  for (int(i) = (0); (i) < (v[x].size()); (i)++) {
    int to = v[x][i];
    if (to == fa) continue;
    bool h = vis[to];
    if (!h) dep[to] = dep[x] + 1, dfs(to, x);
    if (h)
      low[x] = min(low[x], dep[to]);
    else
      low[x] = min(low[x], low[to]);
  }
  if (low[x] == dep[x]) {
    num_cc++;
    while (!ss.empty()) {
      int h = ss.top();
      idx[h] = num_cc;
      ss.pop();
      if (h == x) break;
    }
  }
}
void dfs2(int x, int fa) {
  pa[0][x] = fa;
  for (int(i) = (0); (i) < (w[x].size()); (i)++) {
    int to = w[x][i];
    if (to == fa) continue;
    Dep[to] = Dep[x] + 1;
    dfs2(to, x);
  }
}
int up(int x, int y) {
  for (int(i) = (18); (i) >= (0); (i)--)
    if ((1 << i) & y) x = pa[i][x];
  return x;
}
int lca(int x, int y) {
  if (Dep[x] < Dep[y]) swap(x, y);
  x = up(x, Dep[x] - Dep[y]);
  if (x == y) return x;
  for (int(i) = (18); (i) >= (0); (i)--)
    if (pa[i][x] != pa[i][y]) x = pa[i][x], y = pa[i][y];
  return pa[0][x];
}
int getsum(int x, int y) {
  int ret = 0;
  for (int(i) = (18); (i) >= (0); (i)--)
    if ((1 << i) & y) {
      ret += sum[i][x];
      x = pa[i][x];
    }
  return ret;
}
int main() {
  pw2[0] = 1;
  for (int(i) = (1); (i) <= (100005); (i)++) pw2[i] = pw2[i - 1] * 2 % mod;
  scanf("%d%d", &n, &m);
  for (int(i) = (1); (i) <= (m); (i)++) {
    int t1, t2;
    scanf("%d%d", &t1, &t2);
    v[t1].push_back(t2);
    v[t2].push_back(t1);
  }
  dfs(1, 0);
  for (int(i) = (1); (i) <= (n); (i)++) cnt[idx[i]]++;
  for (int(i) = (1); (i) <= (n); (i)++) {
    for (int(j) = (0); (j) < (v[i].size()); (j)++) {
      int to = v[i][j];
      int u = idx[i], V = idx[to];
      if (u == V) continue;
      w[u].push_back(V);
    }
  }
  dfs2(1, 0);
  for (int(i) = (1); (i) <= (18); (i)++)
    for (int(j) = (1); (j) <= (num_cc); (j)++)
      pa[i][j] = pa[i - 1][pa[i - 1][j]];
  for (int(i) = (1); (i) <= (num_cc); (i)++) sum[0][i] = (cnt[i] > 1);
  for (int(i) = (1); (i) <= (18); (i)++)
    for (int(j) = (1); (j) <= (num_cc); (j)++)
      sum[i][j] = sum[i - 1][j] + sum[i - 1][pa[i - 1][j]];
  scanf("%d", &k);
  for (int(i) = (1); (i) <= (k); (i)++) {
    int t1, t2;
    scanf("%d%d", &t1, &t2);
    t1 = idx[t1];
    t2 = idx[t2];
    int l = lca(t1, t2);
    int re = getsum(t1, Dep[t1] - Dep[l] + 1) + getsum(t2, Dep[t2] - Dep[l]);
    printf("%d\n", pw2[re]);
  }
  return 0;
}
