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.util.*;
  import java.io.*;
  
  public class Practice {
  	static boolean multipleTC = true;
  	FastReader in;
  	PrintWriter out;
  
  	static int mod = (int) (1e9 + 7);
  	int mod2 = 998244353;
  
  	public static void main(String[] args) throws Exception {
  		new Practice().run();
  	}
  
  	void run() throws Exception {
  		in = new FastReader();
  		out = new PrintWriter(System.out);
  		int T = (multipleTC) ? ni() : 1;
  		pre();
  		for (int t = 1; t <= T; t++)
  			solve(t);
  		out.flush();
  		out.close();
  	}
  
  	void pre() throws Exception {
  	}
  
  	void solve(int TC) throws Exception {
  		int n = ni();
  		int m = ni();
  		char arr[][] = new char[n][m];
  		for (int i = 0; i < n; i++) {
  			arr[i] = nln().toCharArray();
  		}
  		Queue<pair> q = new LinkedList<>();
  		for (int i = 0; i < n; i++) {
  			for (int j = 0; j < m; j++) {
  				if (arr[i][j] == 'L') {
  					q.add(new pair(i, j));
  					break;
  				}
  			}
  		}
  		int xDir[] = { 1, -1, 0, 0 };
  		int yDir[] = { 0, 0, 1, -1 };
  		while (!q.isEmpty()) {
  			pair cur = q.poll();
  			for (int ii = 0; ii < 4; ii++) {
  				int newX = cur.x + xDir[ii];
  				int newY = cur.y + yDir[ii];
  				if (!isValid(arr, newX, newY))
  					continue;
  				if (isTwoSidesBlock(arr, newX, newY)) {
  					arr[newX][newY] = '+';
  					q.add(new pair(newX, newY));
  				}
  			}
  		}
  		StringBuilder sb = new StringBuilder();
  		for (int i = 0; i < n; i++) {
  			sb.append(new String(arr[i]) + "\n");
  		}
  		sb.deleteCharAt(sb.length() - 1);
  		pn(sb);
  	}
  
  	boolean isValid(char arr[][], int x, int y) {
  		int n = arr.length;
  		int m = arr[0].length;
  		if (x < 0 || x >= n || y < 0 || y >= m || arr[x][y] == '#' || arr[x][y] == '+' || arr[x][y] == 'L') {
  			return false;
  		}
  		return true;
  	}
  
  	boolean isTwoSidesBlock(char[][] arr, int x, int y) {
  		int block = 0;
  		int n = arr.length;
  		int m = arr[0].length;
  		if (x + 1 >= n || arr[x + 1][y] == '#' || arr[x + 1][y] == 'L' || arr[x + 1][y] == '+') {
  			block++;
  		}
  		if (y + 1 >= m || arr[x][y + 1] == '#' || arr[x][y + 1] == 'L' || arr[x][y + 1] == '+') {
  			block++;
  		}
  		if (x - 1 < 0 || arr[x - 1][y] == '#' || arr[x - 1][y] == 'L' || arr[x - 1][y] == '+') {
  			block++;
  		}
  		if (y - 1 < 0 || arr[x][y - 1] == '#' || arr[x][y - 1] == 'L' || arr[x][y - 1] == '+') {
  			block++;
  		}
  		return block > 2;
  	}
  
  	StringBuilder printArr(int arr[]) {
  		StringBuilder sb = new StringBuilder();
  		int n = arr.length;
  		for (int i = 0; i < n; i++) {
  			sb.append(arr[i] + " ");
  		}
  		return sb;
  	}
  
  	class pair {
  		int x, y;
  
  		pair(int x, int y) {
  			this.x = x;
  			this.y = y;
  		}
  
  		@Override
  		public String toString() {
  			return " " + x + ", " + y + "]";
  		}
  
  	}
  
  	class pairL {
  		long x, y;
  
  		pairL(long x, long y) {
  			this.x = x;
  			this.y = y;
  		}
  
  		@Override
  		public String toString() {
  			return " " + x + ", " + y + "]";
  		}
  
  	}
  
  	boolean isSorted(int arr[]) {
  		for (int i = 0; i < arr.length - 1; i++) {
  			if (arr[i] > arr[i + 1]) {
  				return false;
  			}
  		}
  		return true;
  	}
  
  	void swap(int arr[], int x, int y) {
  		int t = arr[x];
  		arr[x] = arr[y];
  		arr[y] = t;
  	}
  
  	static int bitCount(int x) {
  		return x == 0 ? 0 : (1 + bitCount(x & (x - 1)));
  	}
  
  	void sort(int arr[]) {
  		ArrayList<Integer> list = new ArrayList<>();
  		for (int i = 0; i < arr.length; i++)
  			list.add(arr[i]);
  		Collections.sort(list);
  		for (int i = 0; i < arr.length; i++)
  			arr[i] = list.get(i);
  	}
  
  	static void dbg(Object... o) {
  		System.err.println(Arrays.deepToString(o));
  	}
  
  	ArrayList<Long> primeFactorization(long n) {
  		ArrayList<Long> factorization = new ArrayList<>();
  		while (n % 2 == 0) {
  			factorization.add(2L);
  			n /= 2;
  		}
  		for (long d = 3; d * d <= n; d += 2) {
  			while (n % d == 0) {
  				factorization.add(d);
  				n /= d;
  			}
  		}
  		if (n > 1)
  			factorization.add(n);
  		return factorization;
  	}
  
  	public static boolean isPrime(long n) {
  		if (n < 2)
  			return false;
  		if (n == 2 || n == 3)
  			return true;
  		if (n % 2 == 0 || n % 3 == 0)
  			return false;
  		long sqrtN = (long) Math.sqrt(n) + 1;
  		for (long i = 6L; i <= sqrtN; i += 6) {
  			if (n % (i - 1) == 0 || n % (i + 1) == 0)
  				return false;
  		}
  		return true;
  	}
  
  	public static long gcd(long a, long b) {
  		if (a > b)
  			a = (a + b) - (b = a);
  		if (a == 0L)
  			return b;
  		return gcd(b % a, a);
  	}
  
  	public long binaryExpo(long base, long exp) {
  		long res = 1;
  		while (exp > 0) {
  			if ((exp & 1) == 1)
  				res = res * base;
  			base = base * base;
  			exp >>= 1;
  		}
  		return res;
  	}
  
  	public long pow(long base, long exp, long MOD) {
  		base %= MOD;
  		long res = 1;
  		while (exp > 0) {
  			if ((exp & 1) == 1)
  				res = res * base % MOD;
  			base = base * base % MOD;
  			exp >>= 1;
  		}
  		return res;
  	}
  
  	public static long totient(long n) {
  		long result = n;
  		for (int p = 2; p * p <= n; ++p)
  			if (n % p == 0) {
  				while (n % p == 0)
  					n /= p;
  				result -= result / p;
  			}
  		if (n > 1)
  			result -= result / n;
  		return result;
  	}
  
  	int bit(long n) {
  		return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
  	}
  
  	public long max(long... arr) {
  		long max = arr[0];
  		for (long itr : arr)
  			max = Math.max(max, itr);
  		return max;
  	}
  
  	public int max(int... arr) {
  		int max = arr[0];
  		for (int itr : arr)
  			max = Math.max(max, itr);
  		return max;
  	}
  
  	public long min(long... arr) {
  		long min = arr[0];
  		for (long itr : arr)
  			min = Math.min(min, itr);
  		return min;
  	}
  
  	public int min(int... arr) {
  		int min = arr[0];
  		for (int itr : arr)
  			min = Math.min(min, itr);
  		return min;
  	}
  
  	public long sum(long... arr) {
  		long sum = 0;
  		for (long itr : arr)
  			sum += itr;
  		return sum;
  	}
  
  	public long sum(int... arr) {
  		long sum = 0;
  		for (int itr : arr)
  			sum += itr;
  		return sum;
  	}
  
  	void p(Object o) {
  		out.print(o);
  	}
  
  	void pn(Object o) {
  		out.println(o);
  	}
  
  	void pni(Object o) {
  		out.println(o);
  		out.flush();
  	}
  
  	String n() throws Exception {
  		return in.next();
  	}
  
  	String nln() throws Exception {
  		return in.nextLine();
  	}
  
  	int ni() throws Exception {
  		return Integer.parseInt(in.next());
  	}
  
  	long nl() throws Exception {
  		return Long.parseLong(in.next());
  	}
  
  	int[] readArr(int n) throws Exception {
  		int arr[] = new int[n];
  		for (int i = 0; i < n; i++) {
  			arr[i] = ni();
  		}
  		return arr;
  	}
  
  	double nd() throws Exception {
  		return Double.parseDouble(in.next());
  	}
  
  	class FastReader {
  		BufferedReader br;
  		StringTokenizer st;
  
  		public FastReader() {
  			br = new BufferedReader(new InputStreamReader(System.in));
  		}
  
  		public FastReader(String s) throws Exception {
  			br = new BufferedReader(new FileReader(s));
  		}
  
  		String next() throws Exception {
  			while (st == null || !st.hasMoreElements()) {
  				try {
  					st = new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					throw new Exception(e.toString());
  				}
  			}
  			return st.nextToken();
  		}
  
  		String nextLine() throws Exception {
  			String str = "";
  			try {
  				str = br.readLine();
  			} catch (IOException e) {
  				throw new Exception(e.toString());
  			}
  			return str;
  		}
  	}
  }