#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long powm(long long a, long long p, long long m) {
  long long r = 1 % m;
  while (p) {
    if (p & 1) r = r * a % m;
    p >>= 1;
    a = a * a % m;
  }
  return r;
}
int n, m, k, a, b, uses[100000], cnt = 0, type[100000], ccnt[100000],
                                 in[100000], out[100000], timer = 0,
                                 up[100000][21];
vector<int> lst[100000], path, lst2[100000];
void dfs(int v, int p) {
  if (uses[v] == -1) {
    type[cnt] = 1;
    uses[v] = ++cnt;
    for (int i = path.size() - 1; path[i] != v; --i) uses[path[i]] = cnt;
  } else if (uses[v] == 0) {
    uses[v] = -1;
    path.push_back(v);
    for (int i = 0; i < (lst[v].size()); ++i)
      if (lst[v][i] != p) dfs(lst[v][i], v);
    if (uses[v] == -1) uses[v] = ++cnt;
    path.pop_back();
  }
}
void dfs2(int v, int p, int c) {
  in[v] = timer++;
  ccnt[v] = c + type[v];
  up[v][0] = p;
  for (int i = 1; i <= 20; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (int i = 0; i < (lst2[v].size()); ++i)
    if (lst2[v][i] != p) dfs2(lst2[v][i], v, ccnt[v]);
  out[v] = timer++;
}
bool upper(int i, int j) { return in[i] <= in[j] && out[j] <= out[i]; }
int lca(int i, int j) {
  if (upper(i, j)) return i;
  if (upper(j, i)) return j;
  for (int k = 20; k >= 0; --k)
    if (!upper(up[i][k], j)) i = up[i][k];
  return up[i][0];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (m); ++i) {
    scanf("%d%d", &a, &b);
    lst[a - 1].push_back(b - 1);
    lst[b - 1].push_back(a - 1);
  }
  dfs(0, 0);
  for (int i = 0; i < (n); ++i) uses[i]--;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (lst[i].size()); ++j)
      if (uses[lst[i][j]] != uses[i]) lst2[uses[i]].push_back(uses[lst[i][j]]);
  dfs2(0, 0, 0);
  scanf("%d", &k);
  for (int i = 0; i < (k); ++i) {
    scanf("%d%d", &a, &b);
    a = uses[a - 1], b = uses[b - 1];
    int tmp = lca(a, b);
    printf("%d\n",
           (int)powm(2, ccnt[a] + ccnt[b] - 2 * ccnt[tmp] + type[tmp], mod));
  }
  return 0;
}
