#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<int> g[100500], G[100500];
char used[100500];
vector<int> ord;
int kc = 0;
int comp[100500];
char cl[100500];
int tin[100500];
int tout[100500];
char u[100500];
int timer = 0;
int st = 0;
int up[100500][20];
int h[100500];
int ph[100500];
int s[100500];
void cond(int v, int p = 0) {
  if (used[v]) {
    if (comp[v]) return;
    cl[kc] = 1;
    kc++;
    while (ord.size() > 0) {
      comp[ord.back()] = kc;
      if (ord.back() == v) {
        ord.pop_back();
        break;
      }
      ord.pop_back();
    }
    return;
  }
  used[v] = 1;
  ord.push_back(v);
  for (int i = 0; i < g[v].size(); ++i) {
    if (g[v][i] == p) continue;
    cond(g[v][i], v);
  }
  if (ord.size() > 0 && ord.back() == v) ord.pop_back();
}
void dfs(int v, int p = 0) {
  tin[v] = timer;
  timer++;
  up[v][0] = p;
  for (int i = 1; i <= st; ++i) {
    up[v][i] = up[up[v][i - 1]][i - 1];
  }
  h[v] += h[p];
  if (cl[v]) h[v]++;
  for (int i = 0; i < G[v].size(); ++i) {
    if (G[v][i] == p) continue;
    dfs(G[v][i], v);
  }
  tout[v] = timer;
  timer++;
}
bool upper(int x, int y) {
  if (tin[x] <= tin[y] && tout[x] >= tout[y])
    return true;
  else
    return false;
}
int lca(int x, int y) {
  if (upper(x, y)) return x;
  if (upper(y, x)) return y;
  for (int i = st; i >= 0; i--) {
    if (!upper(up[x][i], y)) x = up[x][i];
  }
  return up[x][0];
}
int getAns(int x, int y) {
  int v = lca(x, y);
  int ret = h[x] - h[v] + h[y] - h[v];
  if (cl[v]) ret++;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  while ((1 << st) <= n) st++;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cond(0);
  for (int i = 0; i < n; ++i) {
    if (comp[i] == 0) {
      kc++;
      comp[i] = kc;
    }
  }
  for (int i = 0; i < n; ++i) comp[i]--;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < g[i].size(); ++j)
      if (comp[i] != comp[g[i][j]]) G[comp[i]].push_back(comp[g[i][j]]);
  }
  dfs(0);
  cin >> k;
  s[0] = 1;
  for (int i = 1; i <= n; ++i) {
    s[i] = s[i - 1] * 2;
    s[i] %= 1000000007;
  }
  for (int i = 0; i < k; ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    int w = getAns(comp[x], comp[y]);
    cout << s[w] << endl;
  }
  return 0;
}
