#include <bits/stdc++.h>
using namespace std;
inline long long Min(long long x, long long y) { return x < y ? x : y; }
inline long long QuickPow(long long x, long long y) {
  long long Res = 1, Temp = x;
  while (y) {
    if (y & 1) Res = Res * Temp % 1000000007;
    Temp = Temp * Temp % 1000000007;
    y /= 2;
  }
  return Res;
}
inline void read(long long &x) {
  x = 0;
  long long f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
vector<long long> G[100005], NG[100005];
long long Dfn[100005], Low[100005], Cnt, Bel[100005], Col, Size[100005];
stack<long long> S;
bool InStack[100005];
void Tarjan(long long x, long long Pre) {
  Dfn[x] = Low[x] = ++Cnt;
  S.push(x);
  InStack[x] = 1;
  int l = G[x].size();
  for (register int i = 0; i < l; ++i) {
    long long to = G[x][i];
    if (to == Pre) continue;
    if (!Dfn[to]) {
      Tarjan(to, x);
      Low[x] = Min(Low[x], Low[to]);
    } else if (InStack[to])
      Low[x] = Min(Low[x], Dfn[to]);
  }
  if (Dfn[x] == Low[x]) {
    Col++;
    long long u;
    do {
      u = S.top();
      S.pop();
      InStack[u] = 0;
      Bel[u] = Col;
      Size[Col]++;
    } while (u != x);
  }
}
bool Vis[100005];
void Link(long long x) {
  Vis[x] = 1;
  int l = G[x].size();
  for (register int i = 0; i < l; ++i) {
    long long to = G[x][i];
    if (Bel[x] != Bel[to]) NG[Bel[x]].push_back(Bel[to]);
    if (Vis[to]) continue;
    Link(to);
  }
}
long long Dep[100005], Qz[100005], f[100005][20];
void Build(long long x, long long Pre) {
  Dep[x] = Dep[Pre] + 1;
  if (Size[x] > 1)
    Qz[x] = Qz[Pre] + 1;
  else
    Qz[x] = Qz[Pre];
  f[x][0] = Pre;
  for (register int i = 1; i < 20; ++i) f[x][i] = f[f[x][i - 1]][i - 1];
  int l = NG[x].size();
  for (register int i = 0; i < l; ++i) {
    long long to = NG[x][i];
    if (to == Pre) continue;
    Build(to, x);
  }
}
inline void Adjust(long long &u, long long Tar) {
  for (register int i = 19; i >= 0; --i)
    if (Dep[f[u][i]] >= Tar) u = f[u][i];
}
inline long long LCA(long long u, long long v) {
  if (Dep[u] > Dep[v])
    Adjust(u, Dep[v]);
  else if (Dep[v] > Dep[u])
    Adjust(v, Dep[u]);
  if (u == v) return (u + v) / 2;
  for (register int i = 19; i >= 0; --i)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
int main() {
  long long n, m;
  read(n);
  read(m);
  for (register int i = 1; i <= m; ++i) {
    long long u, v;
    read(u);
    read(v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (register int i = 1; i <= n; ++i)
    if (!Dfn[i]) Tarjan(i, i);
  for (register int i = 1; i <= n; ++i)
    if (!Vis[i]) Link(i);
  Build(1, 0);
  long long q;
  read(q);
  while (q--) {
    long long u, v;
    read(u);
    read(v);
    u = Bel[u], v = Bel[v];
    long long Mid = LCA(u, v);
    long long Len = (Qz[u] + Qz[v] - Qz[Mid] * 2);
    if (Size[Mid] > 1) Len++;
    printf("%lld\n", QuickPow(2ll, Len));
  }
  return 0;
}
