func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using i3 = pair<int, ii>;   using li = pair<ll, int>;   using lii = pair<ll, ii>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vii = vector<ii>;   using vli = vector<li>;   using vpll = vector<pll>;   using vi3 = vector<i3>;   using vlii = vector<lii>;   const int N = 2e5 + 5, L = 20;   const ll INF = 1e17 + 7, mod = 1e9 + 7;   const double eps = 1e-9, PI = acos(-1);   int n, m;   vector<ii> adj[N];   vector<int> tree[N];   int down[N], level[N];   int cycleId[N];   int to[N][L];   int dep[N];   int cact[N];   void dfs(int u, int p) {     cycleId[u] = u;     level[u] = 1 + level[p];     for (ii A : adj[u]) {       int v = A.second;       int e = A.first;       if (cycleId[v] == 0) {         dfs(v, u);       } else if (v != p) {         if (level[v] < level[u])           cycleId[u] = e;         else           down[u]++;       }     }     for (ii A : adj[u]) {       int v = A.second;       if (v == p) continue;       if ((cycleId[v] != v) && (down[v] == 0)) {         cycleId[u] = cycleId[v];       }     }   }   void dfsTree(int u, int p) {     to[u][0] = p;     dep[u] = 1 + dep[p];     for (int i = 1; i < L; i++) {       to[u][i] = to[to[u][i - 1]][i - 1];     }     for (int v : tree[u]) {       if (v != p) {         cact[v] += cact[u];         dfsTree(v, u);       }     }   }   int jump(int u, int k) {     for (int i = 0; i < L; i++)       if (k & (1 << i)) u = to[u][i];     return u;   }   int LCA(int u, int v) {     if (u == v) return u;     if (dep[u] < dep[v]) swap(u, v);     u = jump(u, dep[u] - dep[v]);     if (u == v) return u;     for (int i = L - 1; i >= 0; i--) {       if (to[u][i] != to[v][i]) {         u = to[u][i];         v = to[v][i];       }     }     return to[u][0];   }   ll pow_mod(ll a, ll b) {     ll ret = 1ll;     a %= mod;     for (; b; ret = ret * (b & 1 ? a : 1ll) % mod, a = a * a % mod, b >>= 1ll)       ;     return ret;   }   ll calc(int u, int v) {     ll A = cact[u];     ll B = cact[v];     int lca = LCA(u, v);     ll C = cact[lca];     return pow_mod(2, A + B - 2 * C + (lca > n));   }   void solve(int testCase) {     scanf( %d %d , &n, &m);     vii edges;     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back({i + n + 1, v});       adj[v].push_back({i + n + 1, u});       edges.push_back({u, v});     }     level[1] = 0;     dfs(1, 0);     for (pair<int, int> E : edges) {       int u = cycleId[E.first];       int v = cycleId[E.second];       if (u != v) {         tree[u].push_back(v);         tree[v].push_back(u);       }     }     for (int i = 1; i <= n; i++) {       cact[cycleId[i]] = (cycleId[i] != i);     }     dfsTree(cycleId[1], 0);     int q;     scanf( %d , &q);     while (q--) {       int u, v;       scanf( %d %d , &u, &v);       printf( %lld n , calc(cycleId[u], cycleId[v]));     }   }   int main() {     int t = 1;     for (int testCase = 1; testCase <= t; testCase++) {       solve(testCase);     }     return 0;   }   