#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9, MOD = INF + 7;
const long long N = 1e5 + 20, M = 2e1 + 2;
pair<long long, long long> edg[N];
vector<pair<long long, long long> > g[N];
vector<long long> dg[N], rdg[N], t[N], fn;
bool mark[N], markEdg[N], cyc[N];
long long comp[N], lvl[N], par[M][N], cnt[N];
void direct(long long v) {
  mark[v] = true;
  for (pair<long long, long long> &p : g[v]) {
    if (!markEdg[p.second]) dg[v].push_back(p.first), rdg[p.first].push_back(v);
    markEdg[p.second] = true;
    if (!mark[p.first]) direct(p.first);
  }
}
void dfsScc(long long v) {
  mark[v] = true;
  for (long long u : dg[v])
    if (!mark[u]) dfsScc(u);
  fn.push_back(v);
}
void sfdScc(long long v, long long c) {
  comp[v] = c;
  bool flag = false;
  for (long long u : rdg[v])
    if (!comp[u]) sfdScc(u, c), flag = true;
  cyc[c] = flag;
}
void dfsLca(long long v, long long p = 0, long long h = 0) {
  lvl[v] = h, par[0][v] = p;
  for (long long i = 1; i < M; i++) par[i][v] = par[i - 1][par[i - 1][v]];
  for (long long u : t[v])
    if (u != p) dfsLca(u, v, h + 1);
}
long long getPar(long long v, long long h) {
  for (long long i = 0; i < M; i++)
    if (h & (1 << i)) v = par[i][v];
  return v;
}
long long lca(long long v, long long u) {
  if (lvl[v] < lvl[u]) swap(v, u);
  v = getPar(v, lvl[v] - lvl[u]);
  if (v == u) return v;
  for (long long i = M - 1; i >= 0; i--)
    if (par[i][v] != par[i][u]) v = par[i][v], u = par[i][u];
  return par[0][v];
}
void dfs(long long v, long long p = 0) {
  cnt[v] = cyc[v] + cnt[p];
  for (long long u : t[v])
    if (u != p) dfs(u, v);
}
long long power(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long v, u;
    cin >> v >> u;
    g[v].push_back(make_pair(u, i));
    g[u].push_back(make_pair(v, i));
    edg[i] = make_pair(v, u);
  }
  direct(1);
  for (long long i = 1; i <= n; i++) mark[i] = false;
  for (long long i = 1; i <= n; i++)
    if (!mark[i]) dfsScc(i);
  reverse(fn.begin(), fn.end());
  long long c = 0;
  for (long long i : fn)
    if (!comp[i]) sfdScc(i, ++c);
  for (long long i = 1; i <= m; i++) {
    long long v = comp[edg[i].first], u = comp[edg[i].second];
    if (v == u) continue;
    t[v].push_back(u);
    t[u].push_back(v);
  }
  dfsLca(1);
  dfs(1);
  long long k;
  cin >> k;
  while (k--) {
    long long a, b, c;
    cin >> a >> b;
    a = comp[a];
    b = comp[b];
    c = lca(a, b);
    cout << power(2, cnt[a] + cnt[b] - 2 * cnt[c] + cyc[c]) << "\n";
  }
  return 0;
}
