就当做模板了
#include <iostream>
#include <cstdio>using namespace std;
const int maxn=500010;char s[maxn];
int minxp(int len){ int i=0,j=1,k=0; while(i<len&&j<len&&k<len) { int t=s[(i+k)%len]-s[(j+k)%len]; if(t==0) k++; else { if(t>0) i+=k+1; else j+=k+1; if(i==j) j++; k=0; } } return min(i,j);}int main(){ int ca,len; cin>>ca; while(ca--) { cin>>len>>s; int s1=minxp(len); cout<<s1<<endl; } return 0;}