#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 1e9 + 7, l = 22;
int n, m, k, h[N], cnt[N], par[N][l + 1], mp[N];
long long two[N];
vector<int> adj[N], stk;
bool mark[N], seen[N];
void DFScy(int v, int p = 0) {
  if (seen[v]) {
    while (stk.back() != v) {
      mp[stk.back()] = v;
      stk.pop_back();
    }
    mark[v] = 1;
    return;
  }
  stk.push_back(v);
  seen[v] = 1;
  for (int i = 0; i < adj[v].size(); i++)
    if (p != adj[v][i] && mp[adj[v][i]] != v) DFScy(adj[v][i], v);
  if (stk.size() && stk.back() == v) stk.pop_back();
}
void DFS(int v) {
  v = mp[v];
  cnt[v] = cnt[par[v][0]] + mark[v];
  h[v] = h[par[v][0]] + 1;
  for (int i = 0; i < adj[v].size(); i++)
    if (mp[adj[v][i]] != par[v][0] && mp[adj[v][i]] != v) {
      par[adj[v][i]][0] = v;
      DFS(adj[v][i]);
    }
}
int LCA(int x, int y) {
  if (h[y] > h[x]) swap(x, y);
  for (int i = l - 1; i >= 0; i--)
    if (h[par[x][i]] >= h[y]) x = par[x][i];
  if (x == y) return x;
  for (int i = l - 1; i >= 0; i--)
    if (par[x][i] != par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  return par[x][0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    mp[x] = x;
    mp[y] = y;
  }
  DFScy(1);
  two[0] = 1;
  for (int i = 1; i <= n; i++) {
    two[i] = (two[i - 1] * 2) % M;
    if (mp[i] != i)
      for (int j = 0; j < adj[i].size(); j++)
        if (mp[adj[i][j]] != mp[i]) adj[mp[i]].push_back(adj[i][j]);
  }
  h[0] = -1;
  DFS(1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < l; j++) par[i][j] = par[par[i][j - 1]][j - 1];
  cin >> k;
  while (k--) {
    int x, y;
    cin >> x >> y;
    x = mp[x];
    y = mp[y];
    int v = LCA(x, y);
    long long ans = two[cnt[x] + cnt[y] - 2 * cnt[v] + mark[v]];
    cout << ans << endl;
  }
  return 0;
}
