#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 20, MAX2 = 22;
int n, m, T[MAX], co[MAX], L[MAX], vist[MAX];
int Pa1[MAX][MAX2];
int sum1[MAX][MAX2];
int head[MAX], nxt[MAX << 1], to[MAX << 1], H, ent;
int headr[MAX], nxtr[MAX << 1], tor[MAX << 1], entr;
pair<int, int> eds[MAX];
void addr(int a, int b) {
  tor[entr] = b, nxtr[entr] = headr[a], headr[a] = entr++;
  tor[entr] = a, nxtr[entr] = headr[b], headr[b] = entr++;
}
void add(int a, int b) {
  to[ent] = b, nxt[ent] = head[a], head[a] = ent++;
  to[ent] = a, nxt[ent] = head[b], head[b] = ent++;
}
int ccn, C[MAX];
void dfsC(int v) {
  vist[v] = 1;
  for (int i = headr[v]; ~i; i = nxtr[i]) {
    int u = tor[i];
    if (vist[u] == 0) {
      T[u] = v, L[u] = L[v] + 1;
      dfsC(u);
    } else if (L[u] < L[v] && u != T[v]) {
      int tmp = v;
      while (tmp != u) C[tmp] = ccn, tmp = T[tmp];
      C[u] = ccn++;
    }
  }
}
int slot;
unordered_map<int, int> mm;
void dfs(int v, int p, int level) {
  if (level > H) H = level;
  L[v] = level;
  for (int i = head[v]; ~i; i = nxt[i]) {
    int u = to[i];
    if (u != p) {
      T[u] = v;
      dfs(u, v, level + 1);
    }
  }
}
void preprocessmm() {
  for (int i = 1; i <= n; i++) {
    for (int j = 0; 1 << j <= n; j++) Pa1[i][j] = -1;
  }
  for (int i = 1; i <= n; i++) {
    sum1[i][0] = co[i];
    Pa1[i][0] = T[i];
  }
  for (int j = 1; 1 << j <= n; j++) {
    for (int i = 1; i <= n; i++) {
      if (Pa1[i][j - 1] != -1) {
        int i2 = Pa1[i][j - 1];
        sum1[i][j] = sum1[i][j - 1] + sum1[i2][j - 1];
        Pa1[i][j] = Pa1[Pa1[i][j - 1]][j - 1];
      } else
        sum1[i][j] = sum1[i][j - 1];
    }
  }
}
int lca1mm(int u, int v, int &su) {
  int log, i;
  su = 0;
  if (L[u] < L[v]) swap(u, v);
  if (!L[u]) {
    su = co[u];
    return u;
  }
  for (log = 0; 1 << log <= L[u]; log++)
    ;
  log--;
  for (i = log; i >= 0; i--) {
    if (L[u] - (1 << i) >= L[v]) {
      su += sum1[u][i];
      u = Pa1[u][i];
    }
  }
  if (u == v) {
    su += co[u];
    return u;
  }
  for (i = log; i >= 0; i--) {
    if (Pa1[u][i] != -1 && Pa1[u][i] != Pa1[v][i]) {
      su += sum1[u][i];
      su += sum1[v][i];
      u = Pa1[u][i], v = Pa1[v][i];
    }
  }
  su += co[u] + co[v] + co[T[u]];
  return T[u];
}
const long long MOD = 1000000007;
long long powMod(long long a, long long b) {
  if (b == 0)
    return 1;
  else {
    long long tmp = powMod(a, b / 2);
    if (b % 2 == 0)
      return tmp * tmp % MOD;
    else
      return tmp * tmp % MOD * a % MOD;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  memset(headr, -1, sizeof(headr)), entr = 0;
  for (int i = (1); i <= (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    eds[i] = {a, b};
    addr(a, b);
  }
  memset(C, -1, sizeof(C)), ccn = 0, memset(vist, 0, sizeof(vist));
  T[1] = -1, L[1] = 0;
  dfsC(1);
  slot = 1;
  for (int i = (1); i <= (n); ++i) {
    if (C[i] == -1) mm[i] = slot++;
  }
  memset(head, -1, sizeof(head)), ent = 0;
  for (int i = (1); i <= (m); ++i) {
    int a = eds[i].first, b = eds[i].second;
    int at = C[a] == -1 ? mm[a] : slot + C[a];
    int bt = C[b] == -1 ? mm[b] : slot + C[b];
    if (at == bt)
      continue;
    else
      add(at, bt);
  }
  n = slot - 1 + ccn;
  dfs(1, -1, 0);
  memset(co, 0, sizeof(co));
  for (int i = (0); i <= (ccn - 1); ++i) co[slot + i] = 1;
  preprocessmm();
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    int sum;
    int xn = C[x] == -1 ? mm[x] : slot + C[x];
    int yn = C[y] == -1 ? mm[y] : slot + C[y];
    lca1mm(xn, yn, sum);
    printf("%lld\n", powMod(2, sum));
  }
  return 0;
}
