#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 100;
int n, m, q;
vector<int> adj[maxn];
int mark[maxn];
int path[maxn], plen = 0;
int cyc[maxn];
int par[maxn][18], dep[maxn];
int sum[maxn];
int ans[maxn];
void dfs(int v, int par) {
  if (mark[v]) return;
  mark[v] = 1;
  path[plen++] = v;
  cyc[v] = -1;
  for (int i = 0, _n = (int)((int((adj[v]).size()))); i < _n; i++) {
    int u = adj[v][i];
    dfs(u, v);
    if (mark[u] == 1 && u != par) {
      for (int k = (int)(plen), _x = (int)(0); k-- > _x;) {
        cyc[path[k]] = u;
        if (path[k] == u) break;
        for (int j = 0, _n = (int)((int((adj[path[k]]).size()))); j < _n; j++)
          adj[u].push_back(adj[path[k]][j]);
      }
    }
  }
  plen--;
  mark[v] = 2;
}
void dfs2(int v, int parent) {
  v = (cyc[v] == -1 ? v : cyc[v]);
  if (mark[v]) return;
  mark[v] = 1;
  if (v != 0) dep[v] = dep[parent] + 1;
  sum[v] = sum[parent] + (cyc[v] != -1 ? 1 : 0);
  par[v][0] = parent;
  for (int i = (int)(1), _n = (int)(18); i < _n; i++)
    par[v][i] = par[par[v][i - 1]][i - 1];
  for (int i = 0, _n = (int)((int((adj[v]).size()))); i < _n; i++) {
    int u = adj[v][i];
    if (cyc[u] == v) continue;
    dfs2(u, v);
  }
}
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  for (int i = (int)(18), _x = (int)(0); i-- > _x;)
    if (dep[par[y][i]] >= dep[x]) y = par[y][i];
  if (x == y) return x;
  for (int i = (int)(18), _x = (int)(0); i-- > _x;)
    if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i];
  return par[x][0];
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0, _n = (int)(m); i < _n; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(0, -1);
  memset(mark, 0, sizeof mark);
  dfs2(0, 0);
  ans[0] = 1;
  for (int i = (int)(1), _n = (int)(maxn); i < _n; i++)
    ans[i] = ans[i - 1] * 2 % 1000000007;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    if (cyc[x] != -1) x = cyc[x];
    if (cyc[y] != -1) y = cyc[y];
    int g = lca(x, y);
    int r = sum[x] + sum[y] - 2 * sum[g] + (cyc[g] != -1 ? 1 : 0);
    cout << ans[r] << endl;
  }
  {
    int _;
    cin >> _;
  }
  return 0;
}
