#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline T gcd(T a, T b) {
  return __gcd(a, b);
}
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
long long modpow(long long a, long long n, long long temp) {
  long long res = 1, y = a;
  while (n > 0) {
    if (n & 1) res = (res * y) % temp;
    y = (y * y) % temp;
    n /= 2;
  }
  return res % temp;
}
long long getbit(long long j, long long i) { return ((i >> (j - 1ll)) & 1ll); }
long long ison(long long mask, long long pos) { return (mask & (1 << pos)); }
long long cbit(long long n) {
  long long k = 0;
  while (n) n &= (n - 1), k++;
  return k;
}
long long nbit(long long n) {
  long long k = 0;
  while (n) n /= 2, k++;
  return k;
}
long long mod = 1e9 + 7;
int sgn(long long x) { return x < 0 ? -1 : !!x; }
const double eps = 1e-7;
const double pi = acos(-1.0);
inline void inc(long long &x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
}
inline void dec(long long &x, long long y) {
  x -= y;
  if (x < 0) x += mod;
}
inline void chmax(long long &x, long long y) {
  if (y > x) x = y;
}
inline void mulm(long long &x, long long y) {
  x *= y;
  if (x >= mod) x -= mod;
}
long long xo(long long i) {
  if ((i & 3) == 0) return i;
  if ((i & 3) == 1) return 1;
  if ((i & 3) == 2) return i + 1;
  return 0;
}
vector<pair<long long, long long> > edges;
vector<long long> adj[100005], comp[100005];
stack<long long> st;
long long n, num, nreg;
long long reg[100005], numb[100005], low[100005], val[100005], p[100005][18],
    l[100005][18], depth[100005];
void dfs1(long long u, long long p) {
  st.push(u);
  numb[u] = low[u] = ++num;
  for (long long i = 0; i < adj[u].size(); i++) {
    long long v = adj[u][i];
    if (v == p || reg[v]) continue;
    if (numb[v])
      low[u] = min(low[u], numb[v]);
    else {
      dfs1(v, u);
      low[u] = min(low[u], low[v]);
    }
  }
  if (numb[u] == low[u]) {
    nreg++;
    long long v, sz = 0;
    do {
      v = st.top();
      st.pop();
      reg[v] = nreg;
      sz++;
    } while (v != u);
    if (sz > 1)
      val[nreg]++;
    else
      val[nreg] = 0;
  }
}
void dfs2(long long u, long long pa, long long lvl) {
  p[u][0] = pa;
  l[u][0] = val[u];
  depth[u] = lvl;
  for (long long i = 0; i < comp[u].size(); i++) {
    long long v = comp[u][i];
    if (v == pa) continue;
    dfs2(v, u, lvl + 1ll);
  }
}
void build() {
  num = nreg = 0;
  for (long long i = 1; i <= n; i++) numb[i] = low[i] = reg[i] = 0;
  dfs1(1, 0);
  for (long long i = 0; i < edges.size(); i++) {
    long long u = reg[edges[i].first];
    long long v = reg[edges[i].second];
    if (u != v) comp[u].push_back(v), comp[v].push_back(u);
  }
  dfs2(1, -1, 0);
  for (long long j = 1; j <= 17; j++) {
    for (long long i = 1; i <= nreg; i++) {
      p[i][j] = p[p[i][j - 1]][j - 1];
      l[i][j] = l[p[i][j - 1]][j - 1] + l[i][j - 1];
    }
  }
}
long long sol(long long u, long long v) {
  long long res = 0;
  if (depth[u] < depth[v]) swap(u, v);
  if (depth[u] > depth[v]) {
    for (long long j = 17; j >= 0; j--) {
      if (depth[u] - (1ll << j) >= depth[v]) res += l[u][j], u = p[u][j];
    }
  }
  if (u == v) return res + val[u];
  for (long long j = 17; j >= 0; j--) {
    if (p[u][j] != p[v][j]) {
      res += l[u][j] + l[v][j];
      u = p[u][j], v = p[v][j];
    }
  }
  return res + val[p[u][0]] + val[u] + val[v];
}
int main() {
  long long m;
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  while (m--) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    edges.push_back(make_pair(u, v));
  }
  build();
  long long q;
  cin >> q;
  while (q--) {
    long long u, v;
    cin >> u >> v;
    cout << modpow(2ll, sol(reg[u], reg[v]), mod) << endl;
  }
}
