Desperately Seeking Santa Find Santa and his reindeer in a crowded scene.

Input

Input will be on STDIN and will be a variable number of lines of characters of equal, but variable, length.
If Santa (represented by the character S) is in the scene, his sack of presents (represented by the character P) will be in one of the positions adjacent to him (horizontally, vertically or diagonally). His reindeer (each represented by the character R) will all be within the 5x5 square surrounding him. If an S appears in the scene that does not have a sack of presents, or is not accompanied by at least 4 reindeer, then it is not Santa.

Output

The scene cleared of all obfuscation (all non-Santa, non-presents, non-reindeer characters replaced with a space), showing Santa, his sack of presents, and his reindeer - all other characters should be replaced with spaces. If Santa and his reindeer are not in the scene, output it unchanged. It is guaranteed that there will only be one solution, so there will never be more than one valid Santa and he will never be carrying more than one sack of presents.

Examples

In these examples I'm just using the * character to make it easy to see the S, P, and R characters, but your program should be able to handle any ascii character from ! to ` (33 to 96). I've left out lower case characters and above to avoid confusion.

Input:

***********
***********
***********
*****R*****
******P****
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********


Output: (ignore dots, they're to force the page to show the blank lines)

.           
.          
.           
     R     
      P    
     S     
     R     
    R  R   
.           
.           
.           
.           


Input: (not enough reindeer)

***********
***********
***********
***********
******P****
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********


Output:

***********
***********
***********
***********
******P****
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********


Input: (no sack of presents)

***********
***********
***********
*****R*****
***********
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********


Output:

***********
***********
***********
*****R*****
***********
*****S*****
*****R*****
****R**R***
***********
***********
***********
***********


Input: (presents not close enough)

***********
***********
***********
*****R*****
***********
*****S*P***
*****R*****
****R**R***
***********
***********
***********
***********


Output:

***********
***********
***********
*****R*****
***********
*****S*P***
*****R*****
****R**R***
***********
***********
***********
***********


Input: (one of the reindeer not within the 5x5 square around Santa)

***********
***********
***********
*****R*****
******P****
*****S*****
*****R*****
****R******
*******R***
***********
***********
***********


Output:

***********
***********
***********
*****R*****
******P****
*****S*****
*****R*****
****R******
*******R***
***********
***********
***********


Test Scripts

As in some of my past questions, I've once again butchered some test scripts originally created by Joey and Ventero to provide some test cases for this question:


bash
Powershell


Usage: ./test [your program and its arguments]

Plain text version of the tests for reference: Plain text

Rewards

Each entry which I can verify that meets the spec, passes the tests and has obviously had some attempt at golfing will receive an upvote from me (so please provide usage instructions with your answer). The shortest solution by the end of 31/12/2013 will be accepted as the winner.
MATLAB: 110 ,95 characters

f=@(x,y) filter2(ones(x),y);a=M==83;b=M==82;c=M==80;d=f(5,a&amp;f(5,b)&gt;3&amp;f(3,c))&amp;(a|b|c);if ~d,M,else,M(~d)=32,end


Not sure about the way input is supposed to be processed, but the rest is pretty straightforward.

Normally formatted version:

f=@(x,y) filter2(ones(x),y);
a=M==83;
b=M==82;
c=M==80;
d=f(5,a&amp;f(5,b)&gt;3&amp;f(3,c))&amp;(a|b|c);
if ~d
  M
else
  M(~d)=32
end


Example input:

M=['***********'
'***********'
'***********'
'*****R*****'
'******P****'
'*****SQL_2*'
'*****R*****'
'****R**R***'
'***********'
'***********'
'***********'
'***********'];