#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Int(T &n) {
  n = 0;
  int f = 1;
  int ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
template <typename T>
T gcd(T a, T b) {
  return !b ? a : gcd(b, a % b);
}
template <typename T>
inline void umin(T &a, T b) {
  a = a < b ? a : b;
}
template <typename T>
inline void umax(T &a, T b) {
  a = a > b ? a : b;
}
template <typename T, typename W>
inline void Int(T &x, W &y) {
  Int(x), Int(y);
}
template <typename T, typename W, typename Q>
inline void Int(T &x, W &y, Q &z) {
  Int(x, y), Int(z);
}
const int N = 1e5 + 7;
const int inf = 1e9 + 7;
const int magic = 20;
int lev[N];
int par[N][25];
int cycleID[N];
int cycleCnt[N];
vector<int> g[N];
vector<int> t[N];
void dfs_squeeze(int u, int p = 0) {
  cycleID[u] = -1;
  for (int v : g[u]) {
    if (lev[v] == 0) {
      lev[v] = lev[u] + 1;
      dfs_squeeze(v, u);
      if (cycleID[v] != -1 && cycleID[v] != v) {
        cycleID[u] = cycleID[v];
      }
    } else if (lev[u] > lev[v] && v != p) {
      cycleID[u] = v;
    }
  }
}
void dfs_lca(int u, int p = 0) {
  par[u][0] = p;
  for (int i = 1; i <= magic; i++) {
    par[u][i] = par[par[u][i - 1]][i - 1];
  }
  cycleCnt[u] = (cycleID[u] != -1) + cycleCnt[p];
  for (int i = 0; i < t[u].size(); i++) {
    int v = t[u][i];
    if (v != p) {
      lev[v] = lev[u] + 1;
      dfs_lca(v, u);
    }
  }
}
int GetLCA(int a, int b) {
  if (lev[a] < lev[b]) swap(a, b);
  int dis = lev[a] - lev[b];
  for (int i = magic; i >= 0; i--) {
    if (dis & (1 << i)) a = par[a][i];
  }
  for (int i = magic; i >= 0; i--) {
    if (par[a][i] != par[b][i]) {
      a = par[a][i], b = par[b][i];
    }
  }
  return a == b ? a : par[a][0];
}
int solve() {
  int n, m;
  Int(n, m);
  vector<pair<int, int>> edges;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    Int(u, v);
    g[u].push_back(v);
    g[v].push_back(u);
    edges.push_back({u, v});
  }
  lev[1] = 1;
  dfs_squeeze(1);
  for (auto [u, v] : edges) {
    u = (~cycleID[u] ? cycleID[u] : u);
    v = (~cycleID[v] ? cycleID[v] : v);
    if (u != v) {
      t[u].push_back(v);
      t[v].push_back(u);
    }
  }
  memset(lev, 0, sizeof lev);
  dfs_lca(~cycleID[1] ? cycleID[1] : 1);
  vector<int> pw(N, 1);
  for (int i = 1; i <= n; ++i) {
    pw[i] = pw[i - 1] * 2;
    if (pw[i] >= 1000000007LL) {
      pw[i] -= 1000000007LL;
    }
  }
  int q;
  Int(q);
  while (q--) {
    int u, v;
    Int(u, v);
    u = (~cycleID[u] ? cycleID[u] : u);
    v = (~cycleID[v] ? cycleID[v] : v);
    int lca = GetLCA(u, v);
    int dist =
        cycleCnt[u] + cycleCnt[v] - cycleCnt[par[lca][0]] - cycleCnt[lca];
    printf("%d\n", pw[dist]);
  }
  return 0;
}
int main() {
  int tests = 1, CaseNo = 0;
  while (tests--) {
    solve();
  }
  return 0;
}
