#include #include using namespace std; using ll=long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int ttt; cin>>ttt; while(ttt--){ int n; cin>>n; vector p(n); for(int i=0;i>p[i]; int l=-1; for(int i=0;ip[(l+n/2-1)%n])f^=1; if(p[(l+n/2)%n]>p[(l+n-1)%n])f^=1; if(f)cout<<(l+n/2)%n<