program Game;

var
  T, P, C, M, i, j, B, W: Integer;
  Col: Integer;
  NN: array [1..100, 1..100] of Integer; { Num[Guess, Color] }
  CC: array [1..100, 1..10] of Integer; { Color[Guess, Position] }
  BB: array [1..100] of Integer; { Black[Guess] }
  VV: array [1..100] of Integer; { Black+White[Guess] }
  
  SC: array [1..10] of Integer; { SelectedColor[Position] }
  SCC: array [1..100] of Integer; { SelectedColorCount[Color] }
  
function Analyse(PPP: Integer): Boolean;
  var
    BBB, VVV, i, j, KKK: Integer;
  begin
    KKK := P + 1 - PPP;
    for j := 1 to M do begin
      BBB := 0;
      VVV := 0;
      for i := 1 to PPP - 1 do if SC[i] = CC[j, i] then Inc(BBB);
      for i := 1 to C do begin
        if SCC[i] > NN[j, i] then begin
	  Inc(VVV, NN[j, i]);
	end else begin
	  Inc(VVV, SCC[i]);
	end;
      end;
      
      if (BB[j] < BBB) or (BB[j] > BBB + KKK)
      or (VV[j] < VVV) or (VV[j] > VVV + KKK) then begin
        Analyse := False;
	Exit;
      end;
    end;

    if PPP > P then begin
      Analyse := True;
      Exit;
    end;
    
    for i := 1 to C do begin
      SC[PPP] := i;
      Inc(SCC[i]);
      if Analyse(PPP + 1) then begin
        Analyse := True;
        Exit;
      end;
      Dec(SCC[i]);
    end;
    
    Analyse := False;
  end;

begin
  ReadLn(T);
  while (T > 0) do begin
    Dec(T);
    FillChar(NN, SizeOf(NN), 0);
    ReadLn(P, C, M);
    for i := 1 to M do begin
      for j := 1 to P do begin
        Read(Col);
	Inc(NN[i, Col]);
	CC[i, j] := Col;
      end;
      ReadLn;
      ReadLn(B, W);
      BB[i] := B;
      VV[i] := B + W;
    end;
    for i := 1 to C do SCC[i] := 0;
    if Analyse(1) then begin
      Write(SC[1]);
      for j := 2 to P do begin
        Write(' ', SC[j]);
      end;
      WriteLn;
    end else begin
      WriteLn('You are cheating!');
    end;
  end;
end.