#include #include #include #include using namespace std; priority_queueq; char s[4000010]; int main() { int cas; scanf("%d",&cas); while (cas--) { scanf("%s",s+1); while (!q.empty()) q.pop(); int n=strlen(s+1); int last=0; for (int i=1;i<=n;i++) { if (s[i]=='^') q.push(i-last),last=i; } q.push(n+1-last); if (last==0) { printf("%d\n",n+1); continue; } int ans=0; for (int i=21;i>=0;i--) { int tmp=1<=tmp) { for (int j=i;j>=0;j--) { ans+=1<