WAGE - Wood, Axe and Grass

no tags 

Danny has created a new civilization on a 2D grid. At the outset each grid location may be occupied by one of three life forms: Woods, Axe, or Grass. Each day, differing life forms occupying horizontally or vertically adjacent grid locations wage war. In each war, Woods always defeat Axe, Axe always defeat Grass, and Grass always defeat Woods. At the end of the day, the winner expands its territory to include the loser's grid position. The loser vacates the position. Determine the territory occupied by each life form after n days.

Input

The first line of input contains t, the number of test cases. Each test case begins with three integers not greater than 100: r and c, the number of rows and columns in the grid, and n. The grid is represented by the r lines that follow, each with c characters. Each character in the grid is W, A, or G, indicating that it is occupied by Woods, Axe, or Grass respectively.

Output

For each test case, print the grid as it appears at the end of the nth day.

Example

Input:
2
3 3 1
WWW
WAW
WWW
3 4 2
WAGW
AGWA
GWAG

Output:
WWW
WWW
WWW
WWWA
WWAG
WAGW

hide comments
Aamir Khan: 2011-10-01 19:39:28

What would be the answer in case
2 2 1
WA
AG

If we consider that battle occurs instantly then also there are two output possible

WW
AA

or

WA
WA

Ajey Golsangi: 2011-09-18 13:38:47

I got a WA due to 'knight'. Please don't leave an empty line b/w outputs.

Santiago Palacio: 2011-04-13 18:49:29

@cegprakash i believe none of them is correct, the "battles" occurs insantly, ergo, it will be
WW
GA
But i'm not 100% sure, i've not made the program yet.

edit
----
i did de problem, and it's exactly as i said.

Last edit: 2011-04-24 06:23:16
cegprakash: 2011-04-09 11:44:23

consider this case
2 2 1
WA
WG



woods can defeat axe in the first step and becomes
WW
WG
further grass beats wood and so
WG
GG
is a possible solution

(or)
axe can defeat grass first
WA
WA
and then woods can defeat axes
WW
WW

which one is correct?

Knight: 2011-03-23 08:01:44

Egor is right !!!
Leave an empty line between the output for successive test cases.
Is misleading statement :-) THANX EGOR :)

:D: 2011-03-23 08:01:44

N seems to be "small".

Egor: 2011-03-23 08:01:44

Don't print newline between output testcases!

Oleg: 2011-03-23 08:01:44

What range n has ?


Added by:Infinity
Date:2011-03-21
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ADA95 ASM32 ASM64 BASH CLPS CLOJURE LISP sbcl LISP clisp D ERL FSHARP FORTRAN GO ICON ICK LUA NEM NICE OCAML PIKE PRLG-swi SCM guile SCM qobi ST TCL WHITESPACE
Resource:Own