#include <bits/stdc++.h>
using namespace std;
int p[100005];
void make() { memset(p, 255, sizeof(p)); }
int find(int x) {
  int px, i;
  for (px = x; p[px] != -1; px = p[px])
    ;
  while (x != px) {
    i = p[x];
    p[x] = px;
    x = i;
  }
  return px;
}
void unio(int x, int y) { p[find(y)] = find(x); }
struct Nod {
  int b, nxt;
  void init(int b, int nxt) {
    this->b = b;
    this->nxt = nxt;
  }
};
struct Tarjan {
  int n;
  Nod bufT[2 * 100005];
  int lenT;
  int ET[100005];
  Nod bufQ[2 * 400005];
  int lenQ;
  int EQ[100005];
  int V[2 * 100005], route[100005];
  int ans[400005];
  char vis[100005];
  int val[100005], sum[100005];
  void init(int n) {
    this->n = n;
    lenT = 0;
    memset(ET, 255, sizeof(ET));
    lenQ = 0;
    memset(EQ, 255, sizeof(EQ));
  }
  void addEdge(int a, int b, int v) {
    bufT[lenT].init(b, ET[a]);
    V[lenT] = v;
    ET[a] = lenT++;
    bufT[lenT].init(a, ET[b]);
    V[lenT] = v;
    ET[b] = lenT++;
  }
  void addQuery(int a, int b) {
    bufQ[lenQ].init(b, EQ[a]);
    EQ[a] = lenQ++;
    bufQ[lenQ].init(a, EQ[b]);
    EQ[b] = lenQ++;
  }
  void dfs(int a) {
    vis[a] = 1;
    for (int i = ET[a]; i != -1; i = bufT[i].nxt) {
      if (vis[bufT[i].b]) continue;
      route[bufT[i].b] = route[a] + V[i];
      dfs(bufT[i].b);
      unio(a, bufT[i].b);
    }
    vis[a] = 2;
    for (int i = EQ[a]; i != -1; i = bufQ[i].nxt) {
      if (vis[bufQ[i].b] == 2) {
        ans[i / 2] = find(bufQ[i].b);
      }
    }
  }
  void bfs(int st) {
    memset(vis, 0, sizeof(vis));
    queue<int> q;
    q.push(st);
    sum[st] = val[st];
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      vis[u] = true;
      for (int i = ET[u]; i != -1; i = bufT[i].nxt) {
        int b = bufT[i].b;
        if (!vis[b]) {
          q.push(b);
          sum[b] = sum[u] + val[b];
        }
      }
    }
  }
  void solve(int root) {
    route[root] = 0;
    make();
    memset(vis, 0, sizeof(vis));
    dfs(root);
  }
} tar;
struct BCC {
  int n, Time, cntChild, nBcc;
  int color[100005], dfn[100005], low[100005], pred[100005];
  int id[100005], tot[100005];
  vector<int> adj[100005];
  set<int> ArtPt;
  set<pair<int, int> > ArtEd;
  void init(int n) {
    this->n = n;
    for (int i = 0; i < n; i++) adj[i].clear();
  }
  void addEdge(int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  void dfs(int u) {
    color[u] = 1;
    low[u] = dfn[u] = ++Time;
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      if (color[v] == 0) {
        pred[v] = u;
        dfs(v);
        low[u] = min(low[u], low[v]);
        if (low[v] > dfn[u]) {
          ArtEd.insert(make_pair(u, v));
          ArtEd.insert(make_pair(v, u));
        }
        if (pred[u] == -1) {
          cntChild++;
          if (cntChild == 2) {
            ArtPt.insert(u);
          }
        } else if (low[v] >= dfn[u]) {
          ArtPt.insert(u);
        }
      } else if (pred[u] != v) {
        low[u] = min(low[u], dfn[v]);
      }
    }
  }
  void solve() {
    nBcc = 0;
    Time = 0;
    cntChild = 0;
    memset(pred, -1, sizeof(pred));
    memset(color, 0, sizeof(color));
    memset(id, -1, sizeof(id));
    memset(tot, 0, sizeof(tot));
    ArtPt.clear();
    ArtEd.clear();
    for (int i = 0; i < n; i++)
      if (color[i] == 0) dfs(i);
    for (int i = 0; i < n; i++) {
      if (id[i] == -1) {
        id[i] = nBcc;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
          int u = q.front();
          q.pop();
          tot[nBcc]++;
          for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j];
            if (id[v] == -1 && ArtEd.find(make_pair(u, v)) == ArtEd.end()) {
              id[v] = nBcc;
              q.push(v);
            }
          }
        }
        nBcc++;
      }
    }
  }
} bcc;
const long long mod = 1000000007;
long long quickPow(long long p, int x) {
  long long ret = 1;
  for (; x; x >>= 1) {
    if (x & 1) ret = ret * p % mod;
    p = p * p % mod;
  }
  return ret;
}
vector<pair<int, int> > query;
int main(int argc, char const *argv[]) {
  int n, m, q;
  scanf("%d%d", &n, &m);
  bcc.init(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    bcc.addEdge(a, b);
  }
  bcc.solve();
  tar.init(bcc.nBcc);
  for (int u = 0; u < n; u++) {
    int a = bcc.id[u];
    for (int i = 0; i < bcc.adj[u].size(); i++) {
      int v = bcc.adj[u][i];
      int b = bcc.id[v];
      if (bcc.ArtEd.find(make_pair(u, v)) != bcc.ArtEd.end() && a < b) {
        tar.addEdge(a, b, 0);
      }
    }
  }
  for (int i = 0; i < bcc.nBcc; i++) tar.val[i] = (bcc.tot[i] > 2);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    query.push_back(make_pair(a, b));
    tar.addQuery(bcc.id[a], bcc.id[b]);
  }
  tar.solve(0);
  tar.bfs(0);
  for (int i = 0; i < q; i++) {
    int anc = tar.ans[i];
    int a = bcc.id[query[i].first], b = bcc.id[query[i].second];
    if (a == b) {
      cout << 2 << endl;
    } else {
      int cnt = tar.sum[a] + tar.sum[b] - 2 * tar.sum[anc] + tar.val[anc];
      long long ret = quickPow(2, cnt);
      cout << ret << endl;
    }
  }
  return 0;
}
