#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) x.begin() , x.end() #define fi first #define se second #define pb push_back #define umax( x , y ) x = max( x , (y) ) #define umin( x , y ) x = min( x , (y) ) #define For( i , a ) for(int i=1;i<=a;i++) #define ort (b+s)/2 #define y2 asrwjaelkf #define y1 asseopirwjaelkf #define set multiset using namespace std; inline int read() { int res = 0 ;int neg ; while(true){char ch = getchar();if(ch>='0' && ch<='9' || ch=='-'){if(ch=='-') neg = -1;else neg = 1 , res = ch-'0';break;} } while(true){char ch = getchar();if(ch>='0' && ch<='9') res*=10 , res+=ch-'0';else break;} return res*neg; } typedef long long Lint; typedef double db; typedef pair ii; typedef pair id; typedef pair dii; typedef pair iii; typedef pair i4; const int maxn = 101020; const int maxm = 10000020; const int MOd = 1e9; const int K = 300; int n; struct segment_tree { int lazy[maxn*3]; int segment[maxn*3]; void push( int k ) { if( lazy[k] ) { if( k < n ) { lazy[k+k] += lazy[k]; lazy[k+k+1] += lazy[k]; } segment[k] += lazy[k]; lazy[k] = 0; } } int merge( int a, int b ) { if( a == -1 ) return b; if( b == -1 ) return a; return max( a, b ); } void up( int k, int b, int s, int x, int y ) { push( k ); if( x > s || b > y ) return; if( x <= b && s <= y ) { lazy[k]++; push( k ); return; } up( k+k, b, ort, x, y ); up( k+k+1, ort+1, s, x, y ); segment[k] = merge( segment[k+k], segment[k+k+1] ); } int find( int k, int b, int s, int x, int y ) { push( k ); if( x > s || b > y ) return -1; if( x <= b && s <= y ) return segment[k]; return merge( find( k+k, b, ort, x, y ), find( k+k+1, ort+1, s, x, y ) ); } void eq( int x, int y ) { int k = x+n; segment[k] = y; for(k>>=1;k;k>>=1) segment[k] = merge( segment[k+k], segment[k+k+1] ); } }s[2]; iii ar[maxn]; bool comp( const iii &a, const iii &b ) { return a.se.se < b.se.se; } int ans[maxn], b, a; void solve() { scanf("%d %d",&b,&a); for(int i=1;i<=a;i++) for(int j=1;j<=b;j++) n++; n = 1; while( n < b+1 ) n <<= 1; for(int i=1;i r ) continue; int tp = 0; if( ar[i].fi == 'D' || ar[i].fi == 'M' ) tp = 1; //printf("before up !tp(%d) = %d\n",!tp,s[!tp].find( 1, 0, n-1, 0, l-1 )); //printf("before up tp(%d) = %d\n",tp,s[tp].find( 1, 0, n-1, 0, l-1 )); s[!tp].up( 1, 0, n-1, 0, l-1 ); //printf("afore up !tp(%d) = %d\n",!tp,s[!tp].find( 1, 0, n-1, 0, l-1 )); //printf("afore up tp(%d) = %d\n",tp,s[tp].find( 1, 0, n-1, 0, l-1 )); //printf("asd %d\n",s[!tp].find( 1, 0, n-1, 0, l-1 )); int val = s[!tp].find( 1, 0, n-1, 0, r-1 ); while( last < val ) { ans[++last] = r + 1; } //printf("asd %d, %d %d --> %d\n",tp,l,r,val); s[tp].eq( r, val ); } for(int i=1;i<=a;i++) { if( i > last ) ans[i] = -1; printf("%d ",ans[i]); } printf("\n"); } int main() { //freopen("asd.in","r",stdin); //freopen("out.txt","w",stdout); int nn; scanf("%d",&nn); while( nn-- ) solve(); return 0; }