#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmin(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, const T &b) {
  if (b > a) a = b;
}
const int inf = 1e9 + 10;
const int maxn = 1e5 + 10;
const long long mod = 1e9 + 7;
vector<int> g[maxn], ng[maxn];
int n, m, k, pa[maxn], num[maxn], totcir = 0, cnt = 0, id[maxn];
vector<int> cir[maxn];
map<pair<int, int>, int> Map;
int parent[20][maxn], dep[maxn], ans[maxn];
long long p2[maxn];
void dfs(int x) {
  for (int i = 0; i < g[x].size(); i++) {
    int to = g[x][i];
    if (!num[to]) {
      pa[to] = x;
      num[to] = ++cnt;
      dfs(to);
    } else if (to != pa[x] && num[to] < num[x]) {
      int now = x;
      vector<int> v;
      while (now != to) {
        v.push_back(now);
        now = pa[now];
      }
      v.push_back(to);
      for (int j = 0; j < v.size(); j++) {
        id[v[j]] = totcir;
      }
      cir[totcir] = v;
      ++totcir;
    }
  }
}
void dfs(int x, int p, int d) {
  parent[0][x] = p;
  dep[x] = d;
  for (int i = 0; i < ng[x].size(); i++) {
    int to = ng[x][i];
    if (to == p) continue;
    dfs(to, x, d + 1);
  }
}
void get_lca() {
  for (int k = 0; k + 1 < 20; k++) {
    for (int i = 0; i < totcir; i++) {
      if (parent[k][i] == -1)
        parent[k + 1][i] = -1;
      else
        parent[k + 1][i] = parent[k][parent[k][i]];
    }
  }
}
int lca(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  for (int k = 0; k < 20; k++) {
    if ((dep[u] - dep[v]) >> k & 1) {
      v = parent[k][v];
    }
  }
  if (u == v) return u;
  for (int k = 19; k >= 0; k--) {
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}
void dfs(int x, int fa) {
  if ((int)cir[x].size() >= 2) {
    ans[x]++;
  }
  for (int i = 0; i < ng[x].size(); i++) {
    int to = ng[x][i];
    if (to == fa) continue;
    ans[to] += ans[x];
    dfs(to, x);
  }
}
int main() {
  for (int i = 0; i < maxn; i++) num[i] = 0, id[i] = -1;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  num[0] = ++cnt;
  pa[0] = -1;
  dfs(0);
  for (int i = 0; i < n; i++)
    if (id[i] == -1) {
      id[i] = totcir;
      cir[totcir].push_back(i);
      ++totcir;
    }
  for (int x = 0; x < n; x++) {
    for (int i = 0; i < g[x].size(); i++) {
      int to = g[x][i];
      if (Map.find(make_pair(id[x], id[to])) != Map.end()) continue;
      if (id[x] != id[to]) {
        ng[id[x]].push_back(id[to]);
        ng[id[to]].push_back(id[x]);
        Map[make_pair(id[x], id[to])] = Map[make_pair(id[to], id[x])] = 1;
      }
    }
  }
  dfs(0, -1, 0);
  get_lca();
  dfs(0, -1);
  p2[0] = 1;
  for (int i = 1; i < maxn; i++) p2[i] = p2[i - 1] * 2ll % mod;
  scanf("%d", &k);
  for (int t = 0; t < k; t++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    int r = lca(id[u], id[v]);
    int sum = ans[id[u]] + ans[id[v]] - 2 * ans[r];
    if (cir[r].size() >= 2) sum++;
    printf("%d\n", p2[sum]);
  }
  return 0;
}
