#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long INF = 1e9;
inline long long bpow(long long t, long long n) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) ans = (ans * t) % mod;
    t = (t * t) % mod, n >>= 1;
  }
  return ans;
}
int n, m;
vector<int> vec[MAX_N], vec2[MAX_N], cycledges[MAX_N];
int type[MAX_N], par[MAX_N];
int num[MAX_N], cnt = 1;
pair<int, int> edges[MAX_N];
void dfs(int v, int p = 0) {
  type[v] = true;
  for (int u : vec[v]) {
    if (u == p) continue;
    if (!type[u])
      par[u] = v, dfs(u, v);
    else if (type[u] == 1) {
      par[u] = v;
      int curv = u;
      cycledges[cnt].push_back(curv), num[curv] = cnt;
      curv = par[curv];
      while (curv != u) {
        cycledges[cnt].push_back(curv);
        num[curv] = cnt;
        curv = par[curv];
      }
      cnt++;
    }
  }
  type[v] = 2;
}
int vcnt[MAX_N];
const int maxL = 18;
int lca[MAX_N][maxL];
int h[MAX_N];
int t[MAX_N];
void lcadfs(int v, int par = 0) {
  vcnt[v] = vcnt[par] + (cycledges[v].size() > 0);
  t[v] = 1;
  lca[v][0] = par;
  for (int i = 1; i < maxL; i++) lca[v][i] = lca[lca[v][i - 1]][i - 1];
  for (int u : vec2[v])
    if (u != par) h[u] = h[v] + 1, lcadfs(u, v), t[v] += t[u];
}
int get_a(int v, int k) {
  for (int i = 0; i < maxL; i++)
    if ((k >> i) & 1) v = lca[v][i];
  return v;
}
int LCA(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  v = get_a(v, h[v] - h[u]);
  if (v == u) return v;
  for (int i = maxL - 1; i >= 0; i--)
    if (lca[v][i] != lca[u][i]) v = lca[v][i], u = lca[u][i];
  return lca[v][0];
}
int power2[MAX_N];
void inp() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    edges[i] = {a, b};
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
}
void pre() {
  power2[0] = 1;
  for (int i = 1; i < MAX_N; i++) power2[i] = (power2[i - 1] * 2) % mod;
}
void make_tree() {
  for (int i = 1; i <= n; i++)
    if (!num[i]) num[i] = cnt++;
  for (int i = 1; i <= m; i++) {
    int v = edges[i].first, u = edges[i].second;
    v = num[v], u = num[u];
    if (v != u) vec2[v].push_back(u), vec2[u].push_back(v);
  }
}
int solve(int v, int u) {
  v = num[v], u = num[u];
  int l = LCA(v, u);
  int ans = vcnt[v] + vcnt[u] - 2 * vcnt[l] + (cycledges[l].size() > 0);
  return power2[ans];
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(0);
  pre();
  inp();
  dfs(1);
  make_tree();
  lcadfs(1);
  int q;
  cin >> q;
  while (q--) {
    int v, u;
    cin >> v >> u;
    cout << solve(v, u) << '\n';
  }
}
