#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int pre[maxn], sta[maxn], low[maxn], n, m, dfn, top, bcc, bel[maxn];
vector<int> edge[maxn];
vector<int> BCC[maxn];
vector<int> nedge[maxn];
int nn, f[20][maxn], cnt[20][maxn], vis[maxn], dep[maxn], height, ts[maxn];
long long ans, h[maxn];
void Init() {
  long long Mod = 1000000000 + 7;
  h[0] = 1LL;
  for (int i = 1; i <= n; i++) h[i] = h[i - 1] * 2 % Mod;
  return;
}
void Dfs(int x, int fa) {
  low[x] = pre[x] = ++dfn;
  sta[++top] = x;
  for (int i = 0; i < (int)edge[x].size(); i++) {
    int v = edge[x][i];
    if (v != fa) {
      if (pre[v] == 0) {
        Dfs(v, x);
        if (low[v] >= pre[x]) {
          bcc++;
          BCC[bcc].clear();
          int w;
          do {
            w = sta[top--];
            BCC[bcc].push_back(w);
          } while (w != v);
          BCC[bcc].push_back(x);
        }
        if (low[v] < low[x]) low[x] = low[v];
      } else {
        if (pre[v] < low[x]) low[x] = pre[v];
      }
    }
  }
  return;
}
void Bl(int u) {
  if (bel[u] == 0) bel[u] = ++nn;
  vis[u] = 1;
  for (int i = 0; i < (int)edge[u].size(); i++) {
    int v = edge[u][i];
    if (vis[v]) continue;
    if (bel[v] == 0) bel[v] = ++nn;
    if (bel[v] != bel[u]) {
      nedge[bel[v]].push_back(bel[u]);
      nedge[bel[u]].push_back(bel[v]);
    }
    Bl(v);
  }
  return;
}
void Ddfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  f[0][u] = fa;
  if (ts[fa] > 2) cnt[0][u] = 1;
  for (int i = 0; i < (int)nedge[u].size(); i++) {
    int v = nedge[u][i];
    if (v == fa) continue;
    Ddfs(v, u);
  }
  return;
}
int LCA(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  for (int i = height; i >= 0; i--)
    if (((dep[y] - dep[x]) >> i) & 1) {
      y = f[i][y];
    }
  if (x == y) return x;
  for (int i = height; i >= 0; i--)
    if (f[i][x] != f[i][y]) {
      x = f[i][x];
      y = f[i][y];
    }
  return f[0][x];
}
int Get(int x, int k) {
  int temp = 0;
  for (int i = height; i >= 0; i--)
    if ((k >> i) & 1) {
      temp += cnt[i][x];
      x = f[i][x];
    }
  return temp;
}
int main() {
  scanf("%d %d", &n, &m);
  Init();
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  Dfs(1, 0);
  int rt = 1;
  for (int i = 1; i <= bcc; i++) {
    if ((int)BCC[i].size() < 3) continue;
    nn++;
    for (int j = 0; j < (int)BCC[i].size(); j++) {
      bel[BCC[i][j]] = nn;
    }
    rt = BCC[i][0];
    ts[nn] = (int)BCC[i].size();
  }
  Bl(rt);
  while ((1 << (height + 1)) < nn) height++;
  Ddfs(1, 0);
  for (int j = 1; (1 << j) < nn; j++)
    for (int i = 1; i <= nn; i++) {
      f[j][i] = f[j - 1][f[j - 1][i]];
      cnt[j][i] = cnt[j - 1][i] + cnt[j - 1][f[j - 1][i]];
    }
  int k;
  scanf("%d", &k);
  while (k--) {
    int x, y, temp;
    scanf("%d %d", &x, &y);
    x = bel[x];
    y = bel[y];
    if (x == y)
      ans = 2;
    else {
      int z = LCA(x, y);
      temp = Get(x, dep[x] - dep[z]) + Get(y, dep[y] - dep[z]);
      if (ts[z] > 2) temp--;
      if (ts[x] > 2) temp++;
      if (ts[y] > 2) temp++;
      ans = h[temp];
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
