1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define ROF(i, a, b) for (int i = (a); i >= (b); --i) #define all(x) x.begin(),x.end() #define CLR(i,a) memset(i,a,sizeof(i)) #define fi first #define se second #define pb push_back #define SZ(a) ((int) a.size())
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef __int128 i128; typedef pair<ll,ll> pll; typedef array<ll,3> arr; typedef double DB; typedef pair<DB,DB> pdd; typedef pair<ll,bool> plb; constexpr ll MAXN=static_cast<ll>(1e2)+10,INF=static_cast<ll>(5e18)+3;
ll N,M,T;
ll cnt[28]; char ingre[4]={'L','I','T'};
inline bool cmp(const char &a,const char &b){ return cnt[a-'A']<cnt[b-'A']; }
inline void solve(){ cin>>N; vector<char> s; for(int i=0;i<=26;++i){ cnt[i]=0; } FOR(i,1,N){ char a; cin>>a; s.pb(a); ++cnt[a-'A']; } bool canOper=false; for(int i=0;i<(int)s.size()-1;++i){ if(s[i]!=s[i+1]){ canOper=true; } } if(!canOper){ cout<<-1<<"\n"; return; } bool haveAns=false; vector<ll> ans; for(int i=1;i<=2*N+1;++i){ if(cnt['L'-'A']==cnt['I'-'A'] && cnt['L'-'A']==cnt['T'-'A']){ haveAns=true; break; } bool hasOp=false; sort(ingre,ingre+3,cmp); for(int i=0;i<3;++i){ char obj=ingre[i]; for(int i=0;i<(int)s.size()-1;++i){ if(s[i]!=s[i+1]){ if(s[i]!=obj && s[i+1]!=obj){ s.insert(s.begin()+i+1,obj); ans.pb(i); ++cnt[obj-'A']; hasOp=true; } if(hasOp){ break; } } } if(hasOp){ break; } } } #ifdef LOCAL for(int i=0;i<s.size();++i){ cerr<<s[i]; } cerr<<"\n"; cerr<<"T:"<<cnt['T'-'A']<<"\n"; cerr<<"I:"<<cnt['I'-'A']<<"\n"; cerr<<"L:"<<cnt['L'-'A']<<"\n"; #endif if(haveAns){ cout<<ans.size()<<'\n'; for(int i=0;i<ans.size();++i){ cout<<ans[i]+1<<"\n"; } }else{ cout<<-1<<"\n"; } }
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>T; while(T--){ solve(); } return 0; }
|