#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MM = 1e5 + 5, LOG = 18;
int N, M, P[MM][LOG], cnt[MM][LOG], lev[MM];
vector<int> G[MM];
int inCyc[MM], endC[MM];
bool vis[MM];
int cxx = 0;
long long powmod(long long a1, long long b1, long long modx = mod) {
  long long res = 1;
  a1 %= modx;
  for (; b1; b1 >>= 1) {
    if (b1 & 1) res = res * a1 % modx;
    a1 = (a1 * a1) % modx;
  }
  return res;
}
void dfs(int cur, int par) {
  if (par != -1) {
    lev[cur] = lev[par] + 1;
  }
  vis[cur] = 1;
  P[cur][0] = par;
  for (auto u : G[cur]) {
    if (!vis[u]) {
      dfs(u, cur);
    } else if (u != par && lev[u] < lev[cur]) {
      endC[u] = 1;
      int icur = cur;
      inCyc[icur] = 1;
      while (icur != u) {
        icur = P[icur][0];
        inCyc[icur] = 1;
      }
    }
  }
}
void pre() {
  dfs(0, -1);
  for (int i = 0; i < N; i++) {
    cnt[i][0] = endC[i];
  }
  for (int L = 1; L < LOG; L++) {
    for (int i = 0; i < N; i++) {
      if (P[i][L - 1] != -1) {
        cnt[i][L] = cnt[P[i][L - 1]][L - 1] + cnt[i][L - 1];
        P[i][L] = P[P[i][L - 1]][L - 1];
      }
    }
  }
}
int kthAbov(int u, int k) {
  if (k <= 0) return u;
  for (int i = LOG - 1; i >= 0; i--) {
    if (k & (1 << i)) {
      u = P[u][i];
    }
  }
  return u;
}
int lca(int u, int v) {
  if (lev[u] < lev[v]) {
    swap(u, v);
  }
  u = kthAbov(u, lev[u] - lev[v]);
  if (u == v) {
    return u;
  }
  for (int L = LOG - 1; L >= 0; L--) {
    if (P[u][L] != P[v][L]) {
      u = P[u][L];
      v = P[v][L];
    }
  }
  return P[u][0];
}
int getIn(int u, int k) {
  int ret = 0;
  for (int i = LOG - 1; i >= 0; i--) {
    if (k & (1 << i)) {
      ret += cnt[u][i];
      u = P[u][i];
    }
  }
  return ret;
}
int crax(int u, int v) {
  if (u == v) {
    return 0;
  }
  int kuk = getIn(u, lev[u] - lev[v] + 1);
  if (endC[v]) {
    kuk--;
  }
  return kuk;
}
long long obelo(int d, int u) { return kthAbov(d, lev[d] - lev[u] - 1); }
long long solve(int u, int v) {
  int w = lca(u, v);
  return crax(u, w) + crax(v, w) + (inCyc[w]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  pre();
  int K;
  cin >> K;
  while (K--) {
    int u, v;
    cin >> u >> v;
    cout << powmod(2, solve(u - 1, v - 1)) << '\n';
  }
  return 0;
}
