#include <bits/stdc++.h>
using namespace std;
const int k = 17;
int n, number[100111], low[100111], num;
vector<int> adj[100111], ke[100111];
int reg[100111], nreg, val[100111], P[100111][18], L[100111][18], depth[100111];
stack<int> st;
vector<pair<int, int> > edges;
void dfs1(int u, int p) {
  st.push(u);
  number[u] = low[u] = ++num;
  for (int i = 0, _n = (adj[u].size()); i < _n; i++) {
    int v = adj[u][i];
    if (v == p || reg[v]) continue;
    if (number[v])
      low[u] = min(low[u], number[v]);
    else {
      dfs1(v, u);
      low[u] = min(low[u], low[v]);
    }
  }
  if (number[u] == low[u]) {
    nreg++;
    int v, size = 0;
    do {
      v = st.top();
      st.pop();
      reg[v] = nreg;
      size++;
    } while (v != u);
    if (size > 1)
      val[nreg] = 1;
    else
      val[nreg] = 0;
  }
}
void dfs2(int u, int p, int lvl) {
  P[u][0] = p;
  L[u][0] = val[u];
  depth[u] = lvl;
  for (int i = 0, _n = (ke[u].size()); i < _n; i++) {
    int v = ke[u][i];
    if (v == p) continue;
    dfs2(v, u, lvl + 1);
  }
}
void buildLCA() {
  num = nreg = 0;
  for (int i = (1), _b = (n); i <= _b; i++) number[i] = low[i] = reg[i] = 0;
  dfs1(1, 0);
  for (int i = 0, _n = (edges.size()); i < _n; i++) {
    int u = reg[edges[i].first], v = reg[edges[i].second];
    if (u != v) {
      ke[u].push_back(v);
      ke[v].push_back(u);
    }
  }
  dfs2(1, 0, 0);
  for (int j = (1), _b = (k); j <= _b; j++) {
    for (int i = (1), _b = (nreg); i <= _b; i++) {
      P[i][j] = P[P[i][j - 1]][j - 1];
      L[i][j] = L[P[i][j - 1]][j - 1] + L[i][j - 1];
    }
  }
}
int get(int u, int v) {
  int res = 0;
  if (depth[u] < depth[v]) swap(u, v);
  if (depth[u] > depth[v]) {
    for (int j = (k), _b = (0); j >= _b; j--)
      if (depth[u] - (1 << j) >= depth[v]) {
        res += L[u][j];
        u = P[u][j];
      }
  }
  if (u == v) return res + val[u];
  for (int j = (k), _b = (0); j >= _b; j--) {
    if (P[u][j] != P[v][j]) {
      res += L[u][j] + L[v][j];
      u = P[u][j];
      v = P[v][j];
    }
  }
  return res + val[P[u][0]] + val[u] + val[v];
}
int power(int n) {
  if (n == 0) return 1;
  if (n == 1) return 2;
  int res = power(n / 2);
  res = (res * (long long)res) % 1000000007;
  if (n % 2 == 1) res = (res * 2LL) % 1000000007;
  return res % 1000000007;
}
int main() {
  int m, u, v;
  scanf("%d %d", &n, &m);
  while (m--) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
    edges.push_back(make_pair(u, v));
  }
  buildLCA();
  scanf("%d", &m);
  while (m--) {
    scanf("%d %d", &u, &v);
    printf("%d\n", power(get(reg[u], reg[v])));
  }
  return 0;
}
