program party;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var a:array[1..10,1..10] of shortint;
    kol,u,v,q,w,e,r,t,b1,g1,k1:longint;
    b,g:array[1..10] of boolean;
    res:array[1..10,1..10] of longint;
    cp:char;
procedure p(d, y ,x:longint);
var i,j,k,l,m,n:longint;
begin
   if d=0 then
   begin
      inc(res[y,x]);
      exit;
   end;
   for i:=1 to b1 do
      for j:=1 to g1 do
         if (b[i])and(g[j])and(a[i,j]=1) then
         begin
            b[i]:=false;
            g[j]:=false;
            a[i,j]:=0;
            p(d-1, i, j);
            b[i]:=true;
            g[j]:=true;
            a[i,j]:=1;
         end;

end;


begin
  reset(input,'party.in');
  readln(q);
  for u:=1 to q do
  begin
     fillchar(a,sizeof(a),0);
     fillchar(res,sizeof(res),0);
     readln(b1,g1,k1);
     for w:=1 to b1 do
     begin
        for e:=1 to g1 do
        begin
           read(cp);
           if cp='Y' then a[w,e]:=1;
        end;
        readln;
     end;

     fillchar(b,sizeof(b),0);
     fillchar(g,sizeof(g),0);
     for w:=1 to b1 do b[w]:=true;
     for w:=1 to g1 do g[w]:=true;
     
     kol:=0;
     p(k1, 1,1);
     kol := 0;
     for w:=1 to b1 do
         for e:= 1 to g1 do
           kol := kol+res[w,e];
   if k1<>1 then writeln(kol div (2*k1)) else writeln(kol);

  end;

end.
