#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int inf = 1e18;   const long long int N = 1e5 + 5;   const long long int M = N;   const long long int LG = 19;   long long int n, m;   long long int tim = 0, grp = 1;   long long int u[N], v[N], storecomp[N];   long long int level[N];   bool vis[N], vis2[N], isBridge[M];   long long int tin[N], tout[N], minAncestor[N];   queue<long long int> Q[N];   vector<pair<long long int, long long int> > g[N];   vector<long long int> tree[N], vertices[N];   long long int parent[LG][N];   void dfs(long long int k, long long int par) {     vis[k] = 1;     tin[k] = ++tim;     minAncestor[k] = tin[k];     for (auto it : g[k]) {       if (it.first == par) continue;       if (vis[it.first]) {         minAncestor[k] = min(minAncestor[k], tin[it.first]);         continue;       }       dfs(it.first, k);       minAncestor[k] = min(minAncestor[k], minAncestor[it.first]);       if (minAncestor[it.first] > tin[k]) isBridge[it.second] = 1;     }     tout[k] = tim;   }   void dfs2(long long int k) {     long long int comp = grp;     Q[comp].push(k);     vis2[k] = 1;     while (!Q[comp].empty()) {       long long int u = Q[comp].front();       Q[comp].pop();       vertices[comp].push_back(u);       storecomp[u] = comp;       for (auto it : g[u]) {         long long int v = it.first;         long long int edgeidx = it.second;         if (vis2[v]) continue;         if (isBridge[edgeidx]) {           grp++;           tree[comp].push_back(grp);           tree[grp].push_back(comp);           dfs2(v);         } else {           Q[comp].push(v);           vis2[v] = 1;         }       }     }   }   void dfs3(long long int v, long long int par, long long int lvl) {     tin[v] = ++tim;     parent[0][v] = par;     level[v] = lvl;     for (auto &u : tree[v]) {       if (u == par) continue;       dfs3(u, v, lvl + 1);     }     tout[v] = tim;   }   bool is_ancestor(long long int u, long long int v) {     return (tin[u] <= tin[v] and tout[u] >= tout[v]);   }   void precompute() {     for (long long int i = 1; i < LG; i++) {       for (long long int j = 1; j <= n; j++) {         if (parent[i - 1][j]) {           parent[i][j] = parent[i - 1][parent[i - 1][j]];         }       }     }   }   long long int __lca(long long int u, long long int v) {     if (level[u] < level[v]) swap(u, v);     long long int diff = level[u] - level[v];     for (long long int i = LG - 1; i >= 0; i--) {       if ((1 << i) & diff) {         u = parent[i][u];       }     }     if (u == v) return u;     for (long long int i = LG - 1; i >= 0; i--) {       if (parent[i][u] and parent[i][u] != parent[i][v]) {         u = parent[i][u];         v = parent[i][v];       }     }     return parent[0][u];   }   long long int dist(long long int u, long long int v) {     return level[u] + level[v] - 2 * level[__lca(u, v)];   }   void HyperBeast() {     cin >> n >> m;     for (long long int i = 1; i <= m; i++) {       cin >> u[i] >> v[i];       g[u[i]].push_back({v[i], i});       g[v[i]].push_back({u[i], i});     }     dfs(1, 0);     dfs2(1);     tim = 0;     dfs3(1, 1, 1);     precompute();     long long int k;     cin >> k;     for (long long int i = 1; i <= k; i++) {       long long int u, v;       cin >> u >> v;       cout << dist(storecomp[u], storecomp[v]) <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int T = 1;     while (T--) {       HyperBeast();       cout <<   n ;     }   }