This page is still under construction.

Parts of this page are still being built. What you see may change.

ADOM

Time limit1sMemory limit128 MB

Summary
For each board, remove every wall tile that the hero at the center of P cannot see within visibility radius r, given that walls block line of sight.
Level

Medium7 of 10

Topics
Geometry, Brute force, Implementation
Solved
No attempts yet

Problem

A roguelike game draws its world with ASCII characters: every tile is a square, and the map shows the walls of buildings and the hero. We must compute what the hero can see.

The visibility model is realistic: an object hidden behind a wall is not shown, and the hero can only perceive objects within a maximum distance, the visibility radius rr. In this simplified version the only objects on the map are the square walls of buildings.

Given the map, determine which walls the hero can see.

Input

The first line contains the number of test cases TT (1≤T≤100)(1 \le T \le 100).

The first line of each test case contains three integers nn, mm, rr (1≤n,m,r≤100)(1 \le n, m, r \le 100): the height of the board, the width of the board, and the hero's visibility radius.

The next nn lines contain mm characters each and describe the board: . is an empty tile, X is a wall, and P is the hero's position. Each board contains exactly one P.

Output

For each test case, output the board with every wall (X) that the hero cannot see replaced by .. Print the TT boards in order, separating consecutive boards with a single blank line.

Visibility is defined as follows.

  • A wall X completely fills its square tile, and there is no gap between two adjacent walls.
  • The hero's observation point is exactly the center of the tile containing P.
  • A wall is considered visible if there exists a point QQ in its square such that (1) the straight-line distance from the observation point to QQ is at most rr, and (2) the open segment from the observation point to QQ does not pass through the interior of any other wall. In other words, a wall is visible if even its smallest fragment is visible.
  • Because each wall fills its tile completely and adjacent walls leave no gap, a line of sight cannot pass through a point where two walls meet only at a single corner.

Examples4

  1. Example 1

    Input
    3
    3 3 2
    XXX
    XPX
    XXX
    7 10 10
    .......X..
    ..........
    .......X..
    P.X.XXX...
    ..........
    ...X......
    ..........
    7 10 6
    .......X..
    ..........
    ......X...
    P.......X.
    ..........
    ...X......
    ..........
    
    Expected output
    .X.
    XPX
    .X.
    
    .......X..
    ..........
    ..........
    P.X.......
    ..........
    ...X......
    ..........
    
    ..........
    ..........
    ......X...
    P.........
    ..........
    ...X......
    ..........
    
  2. Example 2

    Input
    1
    2 2 3
    P.
    ..
    
    Expected output
    P.
    ..
    
  3. Example 3

    Input
    1
    5 5 3
    X...X
    .....
    ..P..
    .....
    X...X
    
    Expected output
    X...X
    .....
    ..P..
    .....
    X...X
    
  4. Example 4

    Input
    1
    3 3 5
    X.X
    .P.
    X.X
    
    Expected output
    X.X
    .P.
    X.X