#include <bits/stdc++.h>
using namespace std;
const int N = 100003;
int n, m, num, dfn[N], low[N], fa[N];
vector<int> e[N], re[N], tmp;
pair<int, int> sav[N];
int one[N];
int findfa(int x) {
  if (fa[x] == x)
    return x;
  else
    return fa[x] = findfa(fa[x]);
}
void getunion(int x, int y) {
  int u = findfa(x);
  int v = findfa(y);
  if (u != v) fa[u] = v, one[v] = 1;
}
void dfs(int x, int last) {
  low[x] = dfn[x] = ++num;
  for (int i = 0; i < e[x].size(); i++) {
    int now = e[x][i];
    if (!dfn[now])
      dfs(now, x);
    else if (now != last)
      low[x] = min(low[x], dfn[now]);
  }
  if (low[x] <= dfn[last]) getunion(x, last);
  low[last] = min(low[last], low[x]);
}
void rebuild() {
  for (int i = 1; i <= n; i++) re[i].clear();
  for (int i = 1; i <= m; i++) {
    int x = findfa(sav[i].first);
    int y = findfa(sav[i].second);
    re[x].push_back(y);
    re[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    sort(re[i].begin(), re[i].end());
    tmp.clear();
    tmp = re[i];
    re[i].clear();
    for (int j = 0; j < tmp.size(); j++)
      if ((j == 0 || tmp[j] != tmp[j - 1]) && tmp[j] != i)
        re[i].push_back(tmp[j]);
  }
}
const long long mmm = 1e9 + 7;
int bfn[N], fbfn[N], first_appear[N];
int way[2 * N], sum[N], cnt, st[2 * N][20];
queue<int> q;
bool vis[N];
long long pow2[N];
void lca_bfs() {
  while (q.size()) q.pop();
  memset(vis, 0, sizeof(vis));
  q.push(findfa(1));
  num = 0;
  while (q.size()) {
    int ori = q.front();
    q.pop();
    bfn[ori] = ++num;
    fbfn[num] = ori;
    vis[ori] = true;
    for (int i = 0; i < re[ori].size(); i++) {
      int nex = re[ori][i];
      if (!vis[nex]) q.push(nex);
    }
  }
}
void lca_dfs(int x, int last) {
  way[++cnt] = bfn[x];
  for (int i = 0; i < re[x].size(); i++) {
    int y = re[x][i];
    if (y == last) continue;
    sum[y] = sum[x] + one[y];
    lca_dfs(y, x);
    way[++cnt] = bfn[x];
  }
}
void pre() {
  memset(first_appear, 0, sizeof(first_appear));
  pow2[0] = 1;
  for (int i = 1; i <= num; i++) pow2[i] = pow2[i - 1] * 2 % mmm;
  for (int i = 1; i <= cnt; i++) {
    int bfsn = way[i];
    if (!first_appear[bfsn]) first_appear[bfsn] = i;
    st[i][0] = way[i];
  }
  for (int j = 1; (1 << j) <= cnt; j++)
    for (int i = 1; i <= cnt - (1 << j) + 1; i++)
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
long long qu(int x, int y) {
  int xx = first_appear[bfn[findfa(x)]];
  int yy = first_appear[bfn[findfa(y)]];
  if (xx > yy) swap(xx, yy);
  int k = 0;
  while (yy - xx + 1 >= (1 << (k + 1))) k++;
  int lca = min(st[xx][k], st[yy - (1 << k) + 1][k]);
  return pow2[sum[findfa(x)] + sum[findfa(y)] - 2 * sum[fbfn[lca]] +
              one[fbfn[lca]]];
}
int main() {
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 1; i <= n; i++) e[i].clear();
    for (int i = 1; i <= m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      e[x].push_back(y);
      e[y].push_back(x);
      sav[i] = make_pair(x, y);
    }
    memset(dfn, 0, sizeof(dfn));
    memset(one, 0, sizeof(one));
    for (int i = 1; i <= n; i++) fa[i] = i;
    num = 0;
    dfs(1, 0);
    rebuild();
    lca_bfs();
    sum[findfa(1)] = one[findfa(1)];
    cnt = 0;
    lca_dfs(findfa(1), 0);
    pre();
    int k;
    scanf("%d", &k);
    for (int i = 1; i <= k; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      cout << qu(x, y) << endl;
    }
  }
  return 0;
}
