int find(int x){
    if (x != fa[x])
        fa[x] = find(fa[x]);
    return fa[x];
}

void tarjan(int u){
    vis[u] = 1;
    for(int i = head[u]; i; i = e[i].nxt){
        int v = e[i].v, w = e[i].c;
        if (!vis[v]){
            dis[v] = dis[u] + w;
            tarjan(v);
            fa[v] = u;
        }
    }
    for(int i = 0; i < query[u].size(); i++){
        int v = query[u][i];
        int id = query_id[u][i];
        if (vis[y]){
            int lca = find(v);
            ans[id] = dis[u] + dis[v] - 2 * dis[lca];
        }
    }
}