#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)5e5 + 5;
const long long MOD = (long long)1e9 + 7;
vector<long long> g[N];
bool used[N];
long long cycle[N], id;
bool flag[N * 2];
long long pr[N];
long long h[N];
struct Tree {
  vector<vector<long long>> G;
  vector<vector<long long>> p;
  vector<long long> cnt;
  vector<long long> tin, tout;
  long long tiktak = 0;
  long long root;
  set<long long> list;
  Tree(long long n) {
    p.resize(n * 2 + 1);
    tin.resize(n * 2 + 1, 0);
    tout.resize(n * 2 + 1, 0);
    cnt.resize(n * 2 + 1, 0);
    for (auto& to : p) {
      to.resize(25);
    }
    G.resize(n * 2 + 1);
    root = cycle[1];
    for (long long i = 1; i <= n; i++) {
      for (long long to : g[i]) {
        if (cycle[to] != cycle[i]) {
          long long a = cycle[i];
          long long b = cycle[to];
          G[a].push_back(b);
        }
      }
    }
  }
  void precalc(long long v, long long par) {
    cnt[v] = cnt[par] + (long long)flag[v];
    p[v][0] = par;
    tin[v] = ++tiktak;
    for (long long i = 1; i <= 20; i++) {
      p[v][i] = p[p[v][i - 1]][i - 1];
    }
    for (long long to : G[v]) {
      if (to != par) {
        precalc(to, v);
      }
    }
    tout[v] = tiktak;
  }
  bool parent(long long a, long long b) {
    return tin[a] <= tin[b] && tout[b] <= tout[a];
  }
  long long lca(long long a, long long b) {
    if (parent(a, b)) {
      return a;
    }
    if (parent(b, a)) {
      return b;
    }
    for (long long i = 20; i >= 0; i--) {
      if (!parent(p[a][i], b)) {
        a = p[a][i];
      }
    }
    return p[a][0];
  }
  long long add(long long a, long long b) {
    return ((a % MOD) + (b % MOD)) % MOD;
  }
  long long mult(long long a, long long b) {
    return ((a % MOD) * (b % MOD)) % MOD;
  }
  long long pw(long long a, long long b) {
    if (b == 0) {
      return 1;
    }
    if (b % 2) {
      return mult(a, pw(a, b - 1));
    } else {
      long long x = pw(a, b / 2);
      return mult(x, x);
    }
  }
  long long divide(long long a, long long b) { return mult(a, pw(b, MOD - 2)); }
  long long get(long long a, long long b) {
    long long res =
        divide(mult(pw(2, cnt[a]), pw(2, cnt[b])), pw(2, cnt[lca(a, b)] * 2));
    if (flag[lca(a, b)]) {
      res = mult(res, 2);
    }
    return res;
  }
};
void dfs(long long v, long long par = -1) {
  pr[v] = par;
  used[v] = 1;
  h[v] = (par == -1 ? 1 : h[par] + 1);
  for (long long to : g[v]) {
    if (to == par) {
      continue;
    }
    if (!used[to]) {
      dfs(to, v);
    }
    if (!cycle[v] && h[v] > h[to]) {
      id++;
      long long fn = v;
      while (fn != to) {
        cycle[fn] = id;
        fn = pr[fn];
      }
      cycle[to] = id;
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  id = n + 1;
  for (long long i = 1; i <= m; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  for (long long i = 1; i <= n; i++) {
    if (!cycle[i]) {
      cycle[i] = i;
    } else {
      flag[cycle[i]] = 1;
    }
  }
  Tree t(n);
  t.precalc(t.root, t.root);
  long long Q;
  cin >> Q;
  while (Q--) {
    long long a, b;
    cin >> a >> b;
    a = cycle[a];
    b = cycle[b];
    cout << t.get(a, b) << endl;
  }
}
