#include <bits/stdc++.h>
using namespace std;
class IO {
  static const int bufSize = 1 << 18;
  char inBuf[bufSize], outBuf[bufSize];
  char *ip1 = inBuf, *ip2 = inBuf;
  int goodReadBit = 0, op1 = -1, op2 = bufSize - 1;
  template <typename T>
  __inline__ __attribute__((always_inline)) void __RI(T& x) {
    int ch = gc(), neg = 1;
    x = 0;
    for (; !(isdigit(ch) || ch == '-' || ch == EOF); ch = gc())
      ;
    if (ch == EOF) {
      goodReadBit = 0;
      return;
    }
    if (ch == '-') neg = -1, ch = gc();
    for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - 48) * neg;
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) void __RC(T& x) {
    unsigned char ch;
    while (isspace(ch = gc()))
      ;
    x = ch;
  }
  __inline__ __attribute__((always_inline)) void __RS(string& x) {
    char ch;
    x.clear();
    for (ch = gc(); isspace(ch); ch = gc())
      ;
    if (ch == EOF) {
      goodReadBit = 0;
      return;
    }
    for (; !isspace(ch); ch = gc()) x.push_back(ch);
  }

 public:
  __inline__ __attribute__((always_inline)) int gc() {
    return ip1 == ip2 && (ip2 = (ip1 = inBuf) + fread(inBuf, 1, bufSize, stdin),
                          ip1 == ip2)
               ? EOF
               : *ip1++;
  }
  __inline__ __attribute__((always_inline)) IO& R(char& x) {
    __RC(x);
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& R(unsigned char& x) {
    __RC(x);
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& R(string& x) {
    __RS(x);
    return (*this);
  }
  template <typename T1, typename T2>
  __inline__ __attribute__((always_inline)) IO& R(pair<T1, T2>& x) {
    R(x.first), R(x.second);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& R(vector<T>& x) {
    for (auto& i : x) R(i);
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& RA(T* a, int n) {
    for (int i = 0; i < n; ++i) R(a[i]);
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& R(T& x, Args&... args) {
    R(x), R(args...);
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& RA(T* a, int n, Args... args) {
    for (int i = 0; i < n; ++i) RA(a[i], args...);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& R(T& x) {
    static_assert(is_integral<T>::value, "Unsupported types");
    if (is_integral<T>::value) __RI(x);
    return (*this);
  }

 private:
  char space = ' ';
  template <typename T>
  __inline__ __attribute__((always_inline)) void __WI(T x) {
    static char buf[64];
    static int len = -1;
    if (x >= 0) {
      do {
        buf[++len] = x % 10 + 48, x /= 10;
      } while (x);
    } else {
      pc('-');
      do {
        buf[++len] = -(x % 10) + 48, x /= 10;
      } while (x);
    }
    while (len >= 0) {
      pc(buf[len]), --len;
    }
  }

 public:
  __inline__ __attribute__((always_inline)) void pc(const char& x) {
    if (op1 == op2) flush();
    outBuf[++op1] = x;
  }
  __inline__ __attribute__((always_inline)) void flush() {
    fwrite(outBuf, 1, op1 + 1, stdout), op1 = -1;
  }
  __inline__ __attribute__((always_inline)) IO& W(const char& x) {
    pc(x);
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& W(const char* x) {
    while (*x != '\0') pc(*(x++));
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& W(const string& x) {
    W(x.c_str());
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& W(const vector<T>& x) {
    for (auto& i : x) WS(i);
    WL();
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& WL() {
    W('\n');
    return (*this);
  }
  template <typename T1, typename T2>
  __inline__ __attribute__((always_inline)) IO& W(const pair<T1, T2>& x) {
    WS(x.first), W(x.second);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& WL(const T& x) {
    W(x), W('\n');
    return (*this);
  }
  __inline__ __attribute__((always_inline)) IO& WS() {
    W(' ');
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& WS(const T& x) {
    W(x), W(space);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& WA(T* a, int n) {
    for (int i = 0; i < n; i++) WS(a[i]);
    WL();
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& W(const T& x,
                                                  const Args&... args) {
    W(x), W(space), W(args...);
    return (*this);
  }
  template <typename... Args>
  __inline__ __attribute__((always_inline)) IO& WL(const Args&... args) {
    W(args...), W('\n');
    return (*this);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) IO& WA(T* a, int n, Args... args) {
    for (int i = 0; i < n; i++) WA(a[i], args...);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& W(const T& x) {
    static_assert(is_integral<T>::value, "Unsupported types");
    if (is_integral<T>::value) __WI(x);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& operator>>(T& x) {
    R(x);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& operator<<(const T& x) {
    W(x);
    return (*this);
  }
  IO() {}
} io;
void EXIT(int code) { io.flush(), exit(code); }
const int8_t INFC = 0x3f;
const int16_t INFS = 0x3f3f;
const int32_t INF = 0x3f3f3f3f;
const int64_t INFL = 0x3f3f3f3f3f3f3f3fLL;
const int MAXN = 3e5;
const int MOD = 1e9 + 7;
vector<int> G[MAXN];
unordered_set<int> nG[MAXN];
struct UF {
  int par[MAXN];
  void init(int n) {
    for (int i = 0; i < n; i++) par[i] = i;
  }
  int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
  void unite(int x, int y) {
    if (find(x) == find(y)) return;
    par[x] = y;
  }
} uf;
namespace BiConnected {
int dfn[MAXN], low[MAXN], vis[MAXN], order = 0;
void dfs(int u, int p) {
  dfn[u] = order++;
  low[u] = dfn[u];
  vis[u] = 1;
  for (int v : G[u]) {
    if (v == p) continue;
    if (vis[v])
      low[u] = min(low[u], dfn[v]);
    else {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if (dfn[u] >= low[v]) uf.unite(u, v);
    }
  }
}
}  // namespace BiConnected
namespace HLD {
int parent[MAXN], depth[MAXN], heavy[MAXN], top[MAXN], dfsIn[MAXN],
    dfsOut[MAXN];
int order = 0;
void init() { memset(heavy, -1, sizeof(heavy)); }
int dfs(int u, int p, int dep) {
  parent[u] = p;
  depth[u] = dep;
  int maxSizeC = 0, size = 1;
  for (auto v : G[u]) {
    if (v == p) continue;
    auto sizeC = dfs(v, u, dep + 1);
    size += sizeC;
    if (sizeC > maxSizeC) maxSizeC = sizeC, heavy[u] = v;
  }
  return size;
}
void decompose(int u, int t) {
  top[u] = t, dfsIn[u] = order++;
  if (heavy[u] != -1) decompose(heavy[u], t);
  for (auto v : G[u]) {
    if (v == parent[u] || v == heavy[u]) continue;
    decompose(v, v);
  }
  dfsOut[u] = order;
}
int lca(int u, int v) {
  while (top[u] != top[v]) {
    if (depth[top[u]] > depth[top[v]])
      u = parent[top[u]];
    else
      v = parent[top[v]];
  }
  return depth[u] < depth[v] ? u : v;
}
}  // namespace HLD
struct SegTree {
  int n;
  vector<int> node, lazy;
  SegTree(vector<int> v) {
    int s = int(v.size());
    n = 1;
    while (n < s) {
      n <<= 1;
    }
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, -1);
    for (int i = 0; i < s; i++) {
      node[i + n - 1] = v[i];
    }
    for (int i = n - 2; i >= 0; i--) {
      node[i] = node[i * 2 + 1] + node[i * 2 + 2];
    }
  }
  inline void push(int k, int l, int r) {
    if (lazy[k] != -1) {
      node[k] = lazy[k];
      if (r - l > 1) {
        lazy[(k << 1) + 1] = lazy[k] >> 1;
        lazy[(k << 1) + 2] = lazy[k] >> 1;
      }
      lazy[k] = -1;
    }
  }
  void set(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    push(k, l, r);
    if (b <= l || r <= a) {
      return;
    }
    if (a <= l && r <= b) {
      lazy[k] = (r - l) * x;
      push(k, l, r);
    } else {
      set(a, b, x, (k << 1) + 1, l, ((l + r) >> 1));
      set(a, b, x, (k << 1) + 2, ((l + r) >> 1), r);
      node[k] = node[(k << 1) + 1] + node[(k << 1) + 2];
    }
  }
  int query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    push(k, l, r);
    if (b <= l || r <= a) {
      return 0;
    }
    if (a <= l && r <= b) {
      return node[k];
    }
    int vl = query(a, b, (k << 1) + 1, l, ((l + r) >> 1));
    int vr = query(a, b, (k << 1) + 2, ((l + r) >> 1), r);
    return vl + vr;
  }
};
int qpow(int64_t a, int b, int MOD) {
  int64_t ans = 1;
  for (; b; b >>= 1) {
    if (b & 1) ans = (a * ans) % MOD;
    a = (a * a) % MOD;
  }
  return ans;
}
int doubled[MAXN];
int main() {
  int n, m;
  io >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    io >> x >> y;
    --x, --y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  uf.init(n);
  BiConnected::dfs(0, -1);
  for (int u = 0; u < n; u++)
    for (auto v : G[u])
      if (uf.find(u) != uf.find(v))
        nG[uf.find(u)].insert(uf.find(v));
      else
        doubled[uf.find(u)] = 1;
  for (int i = 0; i < n; i++) G[i].assign(nG[i].begin(), nG[i].end());
  int root = uf.find(0);
  HLD::init();
  HLD::dfs(root, root, 0);
  HLD::decompose(root, root);
  vector<int> tmp(n);
  for (int i = 0; i < n; i++)
    if (doubled[i]) tmp[HLD::dfsIn[i]] = 1;
  SegTree segTree(tmp);
  int q;
  io >> q;
  while (q--) {
    int x, y;
    io >> x >> y;
    --x, --y;
    if (uf.find(x) == uf.find(y)) {
      io.WL(2);
      continue;
    }
    auto f = [&](int x) {
      int res = 0;
      while (1) {
        res += segTree.query(HLD::dfsIn[HLD::top[x]], HLD::dfsIn[x] + 1);
        if (HLD::top[x] == root) break;
        x = HLD::parent[HLD::top[x]];
      }
      return res;
    };
    int z = HLD::lca(uf.find(x), uf.find(y));
    int p = f(uf.find(x)) + f(uf.find(y)) - 2 * f(z) + doubled[z];
    io.WL(qpow(2, p, MOD));
  }
  EXIT(0);
}
