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
nadstratosfer: 2019-03-02 14:59:45

Print no blanklines between cases as opposed to what samples imply. Kudos to Zukow for explaining the amiguous statement, I'm here to solve problems not guess my way through riddles.

Last edit: 2019-03-02 15:06:53
photon_: 2017-11-27 19:55:00

easy implementation. Got AC with only 34 lines of code C++ :)

Siddharth Singh: 2016-07-09 09:04:27

Nice Problem.
Tedious Implementation.
lasted 359 lines of C++ (i use a 27 line template :P )

xpshekhar: 2015-12-25 00:13:46

those who found difficult to understand
for ex-2
after day 1,the situation will be like
WWAG
WAGW
AGWA

after day 2,
WWWA
WWAG
WAGW

:.Mohib.:: 2015-06-08 14:31:19

Easy one ;)

(^_^): 2013-04-03 09:12:30

Accepted on first try. Simple question below comments really helped alot

张翼德: 2012-12-19 05:32:12

simple ad-hoc :/

Artur Laskowski: 2012-10-29 21:42:13

Could anybody help my with my program?
7958699 I don't know why my program don't pass the test?
Could author or sb else tell me where it have some misteake?

Last edit: 2012-10-30 17:04:00
Prakhar Jain: 2011-12-12 12:52:00

so much time wasted due to silly mistakes
....but finally AC...:)

:D: 2011-10-02 10:43:34

No, that's incorrect.

There are four battles being waged instantly: W-A, W-A, A-G, A-G. Wood wins both, so it takes upper-right and lower-left corners and defends the upper-left. Axe defeats Grass so it takes lower-right fields, despite loosing both initial outposts, since fights are played out instantly. So after one turn we have:

WW
WA

And after second turn there is of course only Wood.

If you still don't understand, explain in detail how you got your results.


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