#include <bits/stdc++.h>
using namespace std;
const int nmax = 100100;
vector<int> g1[nmax];
vector<int> g2[nmax];
int par[nmax][20];
int level[nmax];
int have[nmax];
int f[nmax];
bool iscomplex[nmax];
bool used[nmax];
int p[nmax];
stack<int> st;
int find(int v) {
  if (p[v] == v) return v;
  return p[v] = find(p[v]);
}
void unite(int v, int u) {
  v = find(v);
  u = find(u);
  if (rand() & 1) {
    p[v] = u;
  } else {
    p[u] = v;
  }
}
const int mod = 1000000007;
void dfs1(int v, int prev) {
  used[v] = true;
  st.push(v);
  for (int(i) = 0; (i) < (int((g1[v]).size())); ++(i)) {
    int to = g1[v][i];
    if (!used[to]) {
      dfs1(to, v);
    } else if (to != prev && !iscomplex[f[to]]) {
      int last;
      do {
        last = st.top();
        st.pop();
        f[last] = v;
      } while (last != to);
      iscomplex[v] = true;
    }
  }
  if (!st.empty() && st.top() == v) st.pop();
}
void dfs2(int v, int prev) {
  used[v] = true;
  level[v] = level[prev] + 1;
  par[v][0] = prev;
  for (int(i) = 0; (i) < (19); ++(i)) par[v][i + 1] = par[par[v][i]][i];
  have[v] = have[prev] + iscomplex[v];
  for (int(i) = 0; (i) < (int((g2[v]).size())); ++(i)) {
    int to = g2[v][i];
    if (!used[to]) dfs2(to, v);
  }
}
int lca(int v, int u) {
  if (level[v] < level[u]) swap(v, u);
  for (int i = 20; i--;)
    if (level[v] - (1 << i) >= level[u]) v = par[v][i];
  if (u == v) return v;
  for (int i = 20; i--;)
    if (par[v][i] != par[u][i]) {
      v = par[v][i];
      u = par[u][i];
    }
  return par[v][0];
}
int r[nmax][2];
int binpow(long long x, long long n, int mod) {
  long long a = 1;
  while (n) {
    if (n & 1) a = a * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return a;
}
int main() {
  int n, m, k;
  scanf("%d%d", &n, &m);
  int x, y;
  for (int(i) = 0; (i) < (m); ++(i)) {
    scanf("%d%d", &x, &y);
    --x, --y;
    g1[x].push_back(y);
    g1[y].push_back(x);
    r[i][0] = x;
    r[i][1] = y;
  }
  for (int(i) = 0; (i) < (n); ++(i)) {
    f[i] = i;
    p[i] = i;
  }
  memset((used), 0, sizeof(used));
  dfs1(0, -1);
  for (int(i) = 0; (i) < (m); ++(i)) {
    x = r[i][0];
    y = r[i][1];
    x = f[x];
    y = f[y];
    if (find(x) != find(y)) {
      unite(x, y);
      g2[x].push_back(y);
      g2[y].push_back(x);
    }
  }
  memset((used), 0, sizeof(used));
  dfs2(f[0], f[0]);
  int q, t;
  scanf("%d", &q);
  for (int(i) = 0; (i) < (q); ++(i)) {
    scanf("%d%d", &x, &y);
    x = f[x - 1];
    y = f[y - 1];
    t = lca(x, y);
    int ans = have[x] + have[y] - 2 * have[t] + iscomplex[t];
    printf("%d\n", binpow(2, ans, mod));
  }
  return 0;
}
