#include <bits/stdc++.h>
using namespace std;
int cntc = 0;
int timer = 0;
vector<int> v[100005];
vector<int> vnew[100005];
int power[100005];
int subtree[100005];
int color[100005];
int p[100005];
int cnum[100005];
bool isinc[100005];
bool isac[100005];
int up[100005][17];
int tin[100005];
int tout[100005];
void markc(int node, int j) {
  cntc++;
  isac[cntc] = 1;
  while (p[j] != node) {
    cnum[node] = cntc;
    isinc[node] = 1;
    node = p[node];
  }
}
void dfs(int node) {
  color[node] = 1;
  for (int j : v[node]) {
    if (color[j] == 1 && p[node] != j) {
      markc(node, j);
    }
    if (color[j] == 0) {
      p[j] = node;
      dfs(j);
    }
  }
  color[node] = 2;
}
void precalc() {
  power[0] = 1;
  for (int i = 1; i <= 100000; i++) {
    power[i] = (power[i - 1] + power[i - 1]) % 1000000007;
  }
}
void dfstree(int node, int prev) {
  tin[node] = timer++;
  subtree[node] = subtree[prev] + (isac[node] ? 1 : 0);
  up[node][0] = prev;
  for (int i = 1; i < 17; i++) {
    up[node][i] = up[up[node][i - 1]][i - 1];
  }
  for (int j : vnew[node]) {
    if (j != prev) {
      dfstree(j, node);
    }
  }
  tout[node] = timer++;
}
bool isancestor(int x, int y) { return tin[x] <= tin[y] && tout[x] >= tout[y]; }
int lca(int x, int y) {
  if (isancestor(x, y)) return x;
  if (isancestor(y, x)) return y;
  for (int i = 16; i >= 0; i--) {
    if (up[x][i] != 0 && !isancestor(up[x][i], y)) {
      x = up[x][i];
    }
  }
  return up[x][0];
}
int query(int x, int y) {
  int z = lca(x, y);
  return subtree[x] + subtree[y] - subtree[z] - subtree[up[z][0]];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs(1);
  for (int i = 1; i <= n; i++) {
    if (!isinc[i]) {
      cnum[i] = ++cntc;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j : v[i]) {
      int c1 = cnum[i];
      int c2 = cnum[j];
      if (c1 != c2) {
        vnew[c1].push_back(c2);
      }
    }
  }
  dfstree(1, 0);
  precalc();
  int q, x, y;
  cin >> q;
  while (q) {
    cin >> x >> y;
    x = cnum[x];
    y = cnum[y];
    cout << power[query(x, y)] << '\n';
    q--;
  }
  return 0;
}
