#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using ll=long long; void IO(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main(){ IO(); ll t; cin>>t; while(t--){ ll n; cin>>n; vector p(n); for(ll i=0;i>p[i]; p[i]--; } fenwick_tree bit(n); bit.add(p[0],1); deque dq; dq.push_back(p[0]); ll x=0; for(ll i=1;ivr){ dq.push_back(p[i]); x+=vr; }else{ if(p[i]