#include <bits/stdc++.h>
using namespace std;
long long n, m, q, lw[100010], din[100010], tp[100010], val[100010],
    ddp[100010], dp[100010], f[100010][32], cnt = 0;
bool vis[100010];
map<long long, long long> mp;
vector<long long> vt[100010], bri, vt2[100010], sz[100010];
long long ksm(long long x, long long y) {
  if (y == 0) {
    return 1;
  }
  long long ret = ksm(x, y >> 1);
  ret = (ret * ret) % 1000000007;
  if (y % 2 == 1) {
    return (ret * x) % 1000000007;
  }
  return ret;
}
void dfs(long long x, long long lst) {
  long long i;
  vis[x] = true;
  lw[x] = din[x] = ++cnt;
  for (i = 0; i < vt[x].size(); i++) {
    if (vt[x][i] != lst) {
      if (vis[vt[x][i]]) {
        lw[x] = min(lw[x], din[vt[x][i]]);
      } else {
        dfs(vt[x][i], x);
        lw[x] = min(lw[x], lw[vt[x][i]]);
      }
    }
  }
  if (din[x] == lw[x] && x != 0) {
    bri.push_back(min(x, lst) * n + max(x, lst));
    mp[min(x, lst) * n + max(x, lst)] = 1;
  }
  return;
}
void dfs2(long long x) {
  long long i;
  vis[x] = true;
  tp[x] = cnt;
  sz[cnt].push_back(x);
  for (i = 0; i < vt[x].size(); i++) {
    if (vis[vt[x][i]] || mp[min(x, vt[x][i]) * n + max(x, vt[x][i])] == 1) {
      continue;
    }
    dfs2(vt[x][i]);
  }
  return;
}
void dfs3(long long x, long long lst, long long d) {
  long long i;
  dp[x] = d;
  if (lst != -1) {
    ddp[x] += ddp[lst];
  }
  for (i = 0; i < 20; i++) {
    f[x][i + 1] = f[f[x][i]][i];
  }
  for (i = 0; i < vt2[x].size(); i++) {
    if (vt2[x][i] != lst) {
      f[vt2[x][i]][0] = x;
      dfs3(vt2[x][i], x, d + 1);
    }
  }
  return;
}
long long glca(long long x, long long y) {
  long long i;
  if (dp[x] < dp[y]) {
    swap(x, y);
  }
  for (i = 20; i >= 0; i--) {
    if (dp[f[x][i]] >= dp[y]) {
      x = f[x][i];
    }
    if (x == y) {
      return x;
    }
  }
  for (i = 20; i >= 0; i--) {
    if (f[y][i] != f[x][i]) {
      x = f[x][i];
      y = f[y][i];
    }
  }
  return f[x][0];
}
int main() {
  long long i, x, y, z;
  scanf("%lld%lld", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%lld%lld", &x, &y);
    x--;
    y--;
    vt[x].push_back(y);
    vt[y].push_back(x);
  }
  dfs(0, -1);
  memset(vis, false, sizeof(vis));
  cnt = 0;
  for (i = 0; i < n; i++) {
    if (!vis[i]) {
      dfs2(i);
      cnt++;
    }
  }
  for (i = 0; i < bri.size(); i++) {
    x = bri[i] / n;
    y = bri[i] % n;
    x = tp[x];
    y = tp[y];
    vt2[x].push_back(y);
    vt2[y].push_back(x);
  }
  for (i = 0; i < cnt; i++) {
    if (sz[i].size() <= 1) {
      val[i] = 0;
    } else {
      val[i] = 1;
    }
    ddp[i] = val[i];
  }
  dfs3(0, -1, 0);
  scanf("%lld", &q);
  for (i = 0; i < q; i++) {
    scanf("%lld%lld", &x, &y);
    x--;
    y--;
    x = tp[x];
    y = tp[y];
    z = glca(x, y);
    printf("%lld\n", ksm((long long)2, ddp[x] + ddp[y] - 2 * ddp[z] + val[z]));
  }
  return 0;
}
