description: There is a grid, consisting of n rows and m columns. Each cell of the grid is either free or blocked. One of the free cells contains a lab. All the cells beyond the borders of the grid are also blocked.
  
  A crazy robot has escaped from this lab. It is currently in some free cell of the grid. You can send one of the following commands to the robot: "move right", "move down", "move left" or "move up". Each command means moving to a neighbouring cell in the corresponding direction.
  
  However, as the robot is crazy, it will do anything except following the command. Upon receiving a command, it will choose a direction such that it differs from the one in command and the cell in that direction is not blocked. If there is such a direction, then it will move to a neighbouring cell in that direction. Otherwise, it will do nothing.
  
  We want to get the robot to the lab to get it fixed. For each free cell, determine if the robot can be forced to reach the lab starting in this cell. That is, after each step of the robot a command can be sent to a robot such that no matter what different directions the robot chooses, it will end up in a lab.
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases.
  
  The first line of each testcase contains two integers n and m (1 ≤ n, m ≤ 10^6; n ⋅ m ≤ 10^6) — the number of rows and the number of columns in the grid.
  
  The i-th of the next n lines provides a description of the i-th row of the grid. It consists of m elements of one of three types: 
  
    * '.' — the cell is free; 
    * '#' — the cell is blocked; 
    * 'L' — the cell contains a lab. 
  
  
  
  The grid contains exactly one lab. The sum of n ⋅ m over all testcases doesn't exceed 10^6.
  
  Output
  
  For each testcase find the free cells that the robot can be forced to reach the lab from. Given the grid, replace the free cells (marked with a dot) with a plus sign ('+') for the cells that the robot can be forced to reach the lab from. Print the resulting grid.
  
  Example
  
  Input
  
  
  4
  3 3
  ...
  .L.
  ...
  4 5
  #....
  ..##L
  ...#.
  .....
  1 1
  L
  1 9
  ....L..#.
  
  
  Output
  
  
  ...
  .L.
  ...
  #++++
  ..##L
  ...#+
  ...++
  L
  ++++L++#.
  
  Note
  
  In the first testcase there is no free cell that the robot can be forced to reach the lab from. Consider a corner cell. Given any direction, it will move to a neighbouring border grid that's not a corner. Now consider a non-corner free cell. No matter what direction you send to the robot, it can choose a different direction such that it ends up in a corner.
  
  In the last testcase, you can keep sending the command that is opposite to the direction to the lab and the robot will have no choice other than move towards the lab.
solution: import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.text.DecimalFormat;
  import java.util.*;
  
   
  public class Codeforces {
  	
  	static int mod= 998244353;
  	static int dx[]= { 1,-1,0,0};
  	static int dy[]= { 0,0,-1,1};
  	
  	public static void main(String[] args) throws Exception {
  		PrintWriter out=new PrintWriter(System.out);
  		FastScanner fs=new FastScanner();
  		int t=fs.nextInt();
  		
  		outer:while(t-->0) {
  			int n=fs.nextInt(), m=fs.nextInt();
  			char arr[][]=new char[n][m];
  			for(int i=0;i<n;i++) arr[i]=fs.next().toCharArray();
  			int lx=0,ly=0;
  			here:for(int i=0;i<n;i++) {
  				for(int j=0;j<m;j++) {
  					if(arr[i][j]=='L') {
  						lx=i;
  						ly=j;
  						break here;
  					}
  				}
  			}
  			arr[lx][ly]='+';
  			for(int k=0;k<4;k++) {
  				int nx=lx+dx[k], ny=ly+dy[k];
  				dfs(nx,ny,arr,n,m);
  			}
  			arr[lx][ly]='L';
  			for(int i=0;i<n;i++) {
  				for(int j=0;j<m;j++) {
  					out.print(arr[i][j]);
  				}
  				out.println();
  			}
  		}
  		
  		out.close();
  		
  	}
  	static void dfs(int i,int j,char arr[][],int n,int m) {
  		if(!iss(i,j,n,m)||arr[i][j]!='.') return ;
  		int p=0,b=0;
  		for(int k=0;k<4;k++) {
  			
  			int nx=i+dx[k], ny=j+dy[k];
  			if(!iss(nx,ny,n,m)) {
  				b++;
  			}
  			else if(arr[nx][ny]=='#') {
  				b++;
  			}
  			else if(arr[nx][ny]=='+') {
  				p++;
  			}
  			
  		}
  		if(b+p>=3) {
  			arr[i][j]='+';
  			for(int k=0;k<4;k++) {
  				int nx=i+dx[k], ny=j+dy[k];
  				dfs(nx,ny,arr,n,m);
  			}
  		}
  		
  	}
  	static boolean iss(int i,int j,int n,int m) {
  		return i>=0&&i<n&&j>=0&&j<m;
  	}
  	static long pow(long a,long b) {
  		if(b<0) return 1;
  		long res=1;
  		while(b!=0) {
  			if((b&1)!=0) {
  				res*=a;
  				res%=mod;
  			}
  			a*=a;
  			a%=mod;
  			b=b>>1;
  		}
  		return res;
  	}
  	static int gcd(int  a,int  b) {
  		if(b==0) return a;
  		return gcd(b,a%b);
  	}
  	static long nck(int n,int k) {
  		if(k>n) return 0;
  		long res=1;
  		res*=fact(n);
  		res%=mod;
  		res*=modInv(fact(k));
  		res%=mod;
  		res*=modInv(fact(n-k)); 
  		res%=mod;
  		return res;
  	}
  	static long fact(long n) {
  //		return fact[(int)n];
  		long res=1;
  		for(int i=2;i<=n;i++) {
  			res*=i;
  			res%=mod;
  		}
  		return res;
  	}
  	
  	static long modInv(long n) {
  		return pow(n,mod-2);
  	}
  	
  	static void sort(int[] a) {
  		//suffle
  		int n=a.length;
  		Random r=new Random();
  		for (int i=0; i<a.length; i++) {
  			int oi=r.nextInt(n);
  			int temp=a[i];
  			a[i]=a[oi];
  			a[oi]=temp;
  		}
  		
  		//then sort
  		Arrays.sort(a);
  	}
  	
  	// Use this to input code since it is faster than a Scanner
  	static class FastScanner {
  		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer st=new StringTokenizer("");
  		String next() {
  			while (!st.hasMoreTokens())
  				try {
  					st=new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			return st.nextToken();
  		}
  		
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		long[] lreadArray(int n) {
  			long a[]=new long[n];
  			for(int i=0;i<n;i++) a[i]=nextLong();
  			return a;
  		}
  		int[] readArray(int n) {
  			int[] a=new int[n];
  			for (int i=0; i<n; i++) a[i]=nextInt();
  			return a;
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
   
  }