#include <bits/stdc++.h>
struct edge {
  int to;
  int next;
  int num;
} e[3][100010 * 10];
int box[3][100010], cnt[3];
void init() {
  memset(box, -1, sizeof(box));
  memset(cnt, 0, sizeof(cnt));
}
void add(int from, int to, int num, int t) {
  e[t][cnt[t]].to = to;
  e[t][cnt[t]].num = num;
  e[t][cnt[t]].next = box[t][from];
  box[t][from] = cnt[t]++;
}
int pre[100010];
int low[100010];
int bcnt = 0;
int cnt0;
void bridge_search(int now, int fa) {
  int t;
  int v, w;
  low[now] = pre[now] = ++cnt0;
  for (t = box[0][now]; t + 1; t = e[0][t].next) {
    v = e[0][t].to;
    if (v == fa) continue;
    if (!pre[v]) {
      bridge_search(v, now);
      if (low[v] < low[now]) low[now] = low[v];
    } else {
      if (low[now] > pre[v]) low[now] = pre[v];
    }
  }
}
int Bridge(int n) {
  int i;
  cnt0 = 0;
  memset(pre, 0, sizeof(pre));
  memset(low, 0, sizeof(low));
  bcnt = 0;
  for (i = 1; i <= n; i++) {
    if (!pre[i]) {
      bridge_search(i, 0);
    }
  }
  return bcnt;
}
int vis[100010];
int circle[100010];
int dist[100010];
void solve(int n) {
  memset(vis, 0, sizeof(vis));
  memset(circle, 0, sizeof(circle));
  int i;
  for (i = 1; i <= n; i++) {
    vis[low[i]]++;
    if (vis[low[i]] > 2) circle[low[i]] = 1;
  }
  for (i = 1; i <= n; i++) {
    int t, v;
    for (t = box[0][i]; t + 1; t = e[0][t].next) {
      v = e[0][t].to;
      if (low[i] != low[v]) {
        add(low[i], low[v], 0, 1);
        add(low[v], low[i], 0, 1);
      }
    }
  }
}
void dfs(int now, int deep) {
  if (circle[now])
    dist[now] = deep + 1;
  else
    dist[now] = deep;
  vis[now] = 1;
  int t, v;
  for (t = box[1][now]; t + 1; t = e[1][t].next) {
    v = e[1][t].to;
    if (!vis[v]) {
      dfs(v, dist[now]);
    }
  }
}
int f[100010];
void finit(int n) {
  int i;
  for (i = 0; i <= n; i++) f[i] = i;
}
int find(int x) {
  if (x == f[x]) return x;
  return f[x] = find(f[x]);
}
int ans[100010];
void lca(int now) {
  f[now] = now;
  vis[now] = 1;
  int t, v, x;
  for (t = box[1][now]; t + 1; t = e[1][t].next) {
    v = e[1][t].to;
    if (!vis[v]) {
      lca(v);
      f[v] = now;
    }
  }
  for (t = box[2][now]; t + 1; t = e[2][t].next) {
    v = e[2][t].to, x = e[2][t].num;
    if (vis[v] == 2) {
      int tt = find(v);
      ans[x] = dist[now] + dist[v] - 2 * dist[tt];
      if (circle[tt]) ans[x]++;
    }
  }
  vis[now] = 2;
}
long long quick(int num) {
  long long summ = 1, zi = 2;
  while (num) {
    if (num % 2) summ = (summ * zi) % 1000000007;
    zi = (zi * zi) % 1000000007;
    num /= 2;
  }
  return summ;
}
int main() {
  int n, m, k, x, y;
  scanf("%d%d", &n, &m);
  int i;
  init();
  for (i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    add(x, y, 0, 0);
    add(y, x, 0, 0);
  }
  Bridge(n);
  solve(n);
  memset(vis, 0, sizeof(vis));
  dfs(1, 0);
  memset(vis, 0, sizeof(vis));
  memset(ans, 0, sizeof(ans));
  scanf("%d", &k);
  for (i = 1; i <= k; i++) {
    scanf("%d%d", &x, &y);
    if (low[x] == low[y]) {
      ans[i] = 1;
    } else {
      add(low[x], low[y], i, 2);
      add(low[y], low[x], i, 2);
    }
  }
  lca(1);
  int j, sum = 1;
  for (i = 1; i <= k; i++) {
    printf("%I64d\n", quick(ans[i]));
  }
  return 0;
}
