#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int N = s.size(); vector P(N); stack st; st.push(0); vector> Graph(N/2+1); for(int i=0,time=1; i depth(N); vector> par(n,vector(20,-1)),cost(n,vector(20)); { auto dfs = [&](auto dfs,int pos,int dep) -> void { depth.at(pos) = dep; int s = Graph.at(pos).size(); for(int i=0; i> M(n); for(int i=0; i> Q; while(Q--){ int u,v; cin >> u >> v,u--,v--; u = P.at(u),v = P.at(v); if(u == v){cout << "0\n"; continue;} if(depth.at(u) < depth.at(v)) swap(u,v); int answer = 0,diff = depth.at(u)-depth.at(v); for(int i=0; diff; i++){ if(diff&(1<