#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int mod = 1e9 + 7;
struct dou {
  int x, y;
} e[maxn];
vector<int> g[maxn], ed[maxn], scc[maxn];
int ch[maxn], all, cscc, low[maxn], num[maxn], p[maxn], dep[maxn];
long long ex[maxn];
bool che[maxn], db[maxn];
stack<int> st;
int pa[maxn][20], c[maxn][20];
void DFS(int s) {
  st.push(s);
  ch[s] = 1;
  low[s] = num[s] = ++all;
  int u;
  for (int i = 0; i < g[s].size(); ++i) {
    if (che[g[s][i]]) continue;
    che[g[s][i]] = true;
    u = e[g[s][i]].x + e[g[s][i]].y - s;
    if (ch[u] == 1)
      low[s] = min(low[s], num[u]);
    else {
      DFS(u);
      low[s] = min(low[s], low[u]);
    }
  }
  if (low[s] == num[s]) {
    ++cscc;
    while (st.top() != s) {
      scc[cscc].push_back(st.top());
      p[st.top()] = cscc;
      st.pop();
    }
    scc[cscc].push_back(st.top());
    p[st.top()] = cscc;
    st.pop();
  }
}
void build() {
  int s, u;
  for (int i = 1; i <= cscc; ++i) {
    if (scc[i].size() > 1) db[i] = true;
    for (int j = 0; j < scc[i].size(); ++j) {
      s = scc[i][j];
      for (int k = 0; k < g[s].size(); ++k) {
        u = e[g[s][k]].x + e[g[s][k]].y - s;
        if (p[u] != i) ed[i].push_back(p[u]);
      }
    }
  }
}
void bDFS(int s, int d) {
  ch[s] = 1;
  dep[s] = d;
  if (db[s]) c[s][0] = 1;
  for (int i = 1; i < 19; ++i) {
    pa[s][i] = pa[pa[s][i - 1]][i - 1];
    c[s][i] = c[s][i - 1] + c[pa[s][i - 1]][i - 1];
  }
  int u;
  for (int i = 0; i < ed[s].size(); ++i) {
    u = ed[s][i];
    if (ch[u]) continue;
    pa[u][0] = s;
    bDFS(u, d + 1);
  }
}
int calcu(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  int res = 0, y = dep[a] - dep[b];
  for (int i = 0; 1 << i <= y; ++i) {
    if ((y >> i) & 1) {
      res += c[a][i];
      a = pa[a][i];
    }
  }
  for (int i = 18; i >= 0; --i) {
    if (pa[a][i] != pa[b][i]) {
      res += c[a][i] + c[b][i];
      a = pa[a][i];
      b = pa[b][i];
    }
  }
  if (a != b)
    res += c[a][0] + c[b][0] + c[pa[a][0]][0];
  else
    res += c[a][0];
  return ex[res];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> e[i].x >> e[i].y;
    g[e[i].x].push_back(i);
    g[e[i].y].push_back(i);
  }
  DFS(1);
  build();
  memset(ch, 0, sizeof(ch));
  bDFS(1, 1);
  ex[0] = 1;
  for (int i = 1; i <= n; ++i) ex[i] = ex[i - 1] * 2 % mod;
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> x >> y;
    x = p[x];
    y = p[y];
    cout << calcu(x, y) << '\n';
  }
  return 0;
}
