(* Enter your code here. Read input from STDIN. Print output to STDOUT *){$mode objfpc} uses math; var t,n,m:integer; a,b,k,f,res:array[0..100000] of integer; it,lazy:array[1..2,0..400000] of integer; procedure sort(l,r: longint); var i,j,x,y: longint; begin i:=l; j:=r; x:=b[random(r-l+1)+l]; repeat while b[i]j) then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; y:=b[i]; b[i]:=b[j]; b[j]:=y; y:=k[i]; k[i]:=k[j]; k[j]:=y; inc(i); dec(j); end; until i>j; if l j) then exit; if (u <= i) and (j <= v) then begin inc(it[k,xo]); inc(lazy[k,xo]); exit; end; mid:=(i+j) div 2; down(k,xo); increase(k,u,v,i,mid,xo*2); increase(k,u,v,mid+1,j,xo*2+1); it[k,xo]:=max(it[k,xo*2] , it[k,xo*2+1]); end; function query(u,v,i,j,xo:integer):integer; var mid:integer; begin if (v < i) or (u > j) then exit(0); if (u <= i) and (j <= v) then exit(max(it[1,xo] , it[2,xo])); mid:=(i+j) div 2; down(1,xo); down(2,xo); result:=max(query(u,v,i,mid,xo*2) , query(u,v,mid+1,j,xo*2+1)); it[1,xo]:=max(it[1,xo*2] , it[1,xo*2+1]); it[2,xo]:=max(it[2,xo*2] , it[2,xo*2+1]); end; procedure update(o,w,i,j,xo:integer); var mid:integer; begin if i = j then begin it[1,xo]:=w; it[2,xo]:=w; exit; end; mid:=(i+j) div 2; down(1,xo); down(2,xo); if o <= mid then update(o,w,i,mid,xo*2) else update(o,w,mid+1,j,xo*2+1); it[1,xo]:=max(it[1,xo*2] , it[1,xo*2+1]); it[2,xo]:=max(it[2,xo*2] , it[2,xo*2+1]); end; procedure solve; var i,j:integer; o:char; begin fillchar(it,sizeof(it),0); fillchar(lazy,sizeof(lazy),0); readln(m,n); for i:=1 to n do res[i]:=m+1; for i:=1 to n do begin read(o); if (o = 'E') or (o = 'C') then k[i]:=1 else k[i]:=2; if i < n then read(o); end; readln; for i:=1 to n do read(a[i]); for i:=1 to n do read(b[i]); sort(1,n); //for i:=1 to n do writeln(k[i],' ',a[i],' ',b[i]); j:=1; for i:=1 to m do begin while (j <= n) and (b[j] <= i) do begin if a[j] <= b[j] then increase(k[j],1,a[j],1,m,1); inc(j); end; f[i]:=query(1,i,1,m,1); ///if i = 5 then writeln(f[i],' ',it[2,1]); res[f[i]]:=min(res[f[i]] , i); update(i,f[i],1,m,1); end; for i:=n-1 downto 1 do res[i]:=min(res[i] , res[i+1]); for i:=1 to n do if res[i] = m+1 then write('-1 ') else write(res[i],' '); writeln; end; begin { assign(input,'a.inp'); reset(input);} read(t); while t > 0 do begin dec(t); solve; end; end.