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: /* package codechef; // don't place package name! */
  
  import java.util.*;
  import java.lang.*;
  import java.io.*;
  /* Name of the class has to be "Main" only if the class is public. */
  public class Codechef
  {static class FastReader 
      { 
          BufferedReader br; 
          StringTokenizer st; 
    
          public FastReader() 
          { 
              br = new BufferedReader(new
                       InputStreamReader(System.in)); 
          } 
    
          String next() 
          { 
              while (st == null || !st.hasMoreElements()) 
              { 
                  try
                  { 
                      st = new StringTokenizer(br.readLine()); 
                  } 
                  catch (IOException  e) 
                  { 
                      e.printStackTrace(); 
                  } 
              } 
              return st.nextToken(); 
          } 
    
          int nextInt() 
          { 
              return Integer.parseInt(next()); 
          } 
    
          long nextLong() 
          { 
              return Long.parseLong(next()); 
          } 
    
          double nextDouble() 
          { 
              return Double.parseDouble(next()); 
          } 
    
          String nextLine() 
          { 
              String str = ""; 
              try
              { 
                  str = br.readLine(); 
              } 
              catch (IOException e) 
              { 
                  e.printStackTrace(); 
              } 
              return str; 
          } 
      } 
  //    static int mod = 998244353 ;
  //    static int N = 200005;
  //    static long factorial_num_inv[] = new long[N+1];
  //    static long natual_num_inv[] = new long[N+1];
  //    static long fact[] = new long[N+1];
  //    static void InverseofNumber() 
  //{ 
  //    natual_num_inv[0] = 1;
  //    natual_num_inv[1] = 1; 
  //    for (int i = 2; i <= N; i++) 
  //        natual_num_inv[i] = natual_num_inv[mod % i] * (mod - mod / i) % mod; 
  //} 
  //static void InverseofFactorial() 
  //{ 
  //    factorial_num_inv[0] = factorial_num_inv[1] = 1; 
    
  //    for (int i = 2; i <= N; i++) 
  //        factorial_num_inv[i] = (natual_num_inv[i] * factorial_num_inv[i - 1]) % mod; 
  //} 
  //static long nCrModP(long N, long R) 
  //{ 
  //    long ans = ((fact[(int)N] * factorial_num_inv[(int)R]) % mod * factorial_num_inv[(int)(N - R)]) % mod; 
  //    return ans%mod; 
  //}
      //static boolean prime[];
      //static void sieveOfEratosthenes(int n)
      //{
      //    prime = new boolean[n+1];
          
      //    for (int i = 0; i <= n; i++)
      //        prime[i] = true;
   
      //    for (int p = 2; p * p <= n; p++)
      //    {
      //        // If prime[p] is not changed, then it is a
      //        // prime
      //        if (prime[p] == true)
      //        {
      //            // Update all multiples of p
      //            for (int i = p * p; i <= n; i += p)
      //                prime[i] = false;
      //        }
      //    }
   
          
      //}
      
  	public static void main (String[] args) throws java.lang.Exception
  	{
      //    InverseofNumber();
      //    InverseofFactorial();
      //   fact[0] = 1; 
      //   for (long i = 1; i <= 2*100000; i++)
      //   { 
      //       fact[(int)i] = (fact[(int)i - 1] * i) % mod; 
      //   }
      
  		FastReader scan = new FastReader();
  		PrintWriter pw = new PrintWriter(System.out);
          int t = scan.nextInt();
          while(t-->0){
              int n = scan.nextInt();
              int m = scan.nextInt();
              String a[] = new String[n];
              char[][] ans = new char[n][m];
              int x = -1,y = -1;
              for(int i=0;i<n;i++){
                  a[i] = scan.next();
                  for(int j=0;j<m;j++){
                      if(a[i].charAt(j)=='L'){
                          x = i;
                          y = j;
                      }
                      ans[i][j] = a[i].charAt(j);
                  }
              }
              
              
              
              if(x-1>=0)
              fun(ans,n,m,x-1,y);
              
              if(x+1<n)
              fun(ans,n,m,x+1,y);
              
              if(y-1>=0)
              fun(ans,n,m,x,y-1);
              
              if(y+1<m)
              fun(ans,n,m,x,y+1);
  
              for(int i=0;i<n;i++){
                  for(int j=0;j<m;j++){
                      pw.print(ans[i][j]);
                  }
                  pw.println();
              }
              pw.flush();
          }
          
      }
      public static void fun(char ans[][],int n ,int m, int x,int y){
          if(ans[x][y]=='.'){
              int count1 = 0,count2 = 0;
              int dest_x = -1;
              int dest_y = -1;
              if(x-1>=0 && (ans[x-1][y]=='+' || ans[x-1][y]=='L')){
                 count1++;
              }
              else if(x-1>=0 && ans[x-1][y]=='.'){
                  count2++;
                  dest_x = x-1;
                  dest_y = y;
              }
              if(x+1<n && (ans[x+1][y]=='+' || ans[x+1][y]=='L')){
                  count1++;
              }
              else if(x+1<n && ans[x+1][y]=='.'){
                  count2++;
                  dest_x =  x+1;
                  dest_y = y;
              }
              if(y-1>=0 && (ans[x][y-1]=='+' || ans[x][y-1]=='L')){
                  count1++;
              }
              else if(y-1>=0 && ans[x][y-1]=='.'){
                  count2++;
                  dest_x = x;
                  dest_y = y-1;
              }
              if(y+1<m && (ans[x][y+1]=='+' || ans[x][y+1]=='L')){
                  count1++;
              }
              else if(y+1<m && ans[x][y+1]=='.'){
                  count2++;
                  dest_x = x;
                  dest_y = y+1;
              }
              if(count1>=1 && count2<=1){
                  ans[x][y] = '+';
                  if(count2==1){
                      fun(ans,n,m,dest_x,dest_y);
                  }
              }
          }
      }
          
          //static long bin_exp_mod(long a,long n){
              
          //    long res = 1;
              
          //    if(a==0)
          //    return 0;
          //    while(n!=0){
          //        if(n%2==1){
          //            res = ((res)*(a));
          //        }
          //           n = n/2;
          //            a = ((a)*(a));
          //    }
             
          //    return res;
          //}
      //static long bin_exp_mod(long a,long n){
  	//    long mod = 998244353;
  	//    long res = 1;
  	//    a = a%mod;
  	//    if(a==0)
  	//    return 0;
  	//    while(n!=0){
  	//        if(n%2==1){
  	//            res = ((res%mod)*(a%mod))%mod;
  	//        }
  	//           n = n/2;
  	//            a = ((a%mod)*(a%mod))%mod;
  	//    }
  	//    res = res%mod;
  	//    return res;
  	//}
  //   static long gcd(long a,long b){
  //       if(a==0)
  //       return b;
  //       return gcd(b%a,a);
  //   }
  //   static long lcm(long a,long b){
  //       return (a/gcd(a,b))*b;
  //   }
  }
  //class Pair{
  //    Integer x,y;
  //    Pair(int x,int y){
  //        this.x = x;
  //        this.y = y;
  //    }
  //    public boolean equals(Object obj) {
  //        // TODO Auto-generated method stub
  //        if(obj instanceof Pair)
  //        {
  //            Pair temp = (Pair) obj;
  //            if(this.x.equals(temp.x) && this.y.equals(temp.y))
  //                return true;
  //        }
  //        return false;
  //    }
  
  //    @Override
  //    public int hashCode() {
  //        // TODO Auto-generated method stub
          
  //        return (this.x.hashCode() + this.y.hashCode());        
  //    }
  //}
  //class Compar implements Comparator<Pair>{
  //    public int compare(Pair p1,Pair p2){
  //        return p1.x-p2.x;
  //    }
  //}