There is a field divided into $n$ rows and $m$ columns. Some cells are empty (denoted as E), other cells contain robots (denoted as R).

You can send a command to all robots at the same time. The command can be of one of the four types:

move up;

move right;

move down;

move left.

When you send a command, all robots at the same time attempt to take one step in the direction you picked. If a robot tries to move outside the field, it explodes; otherwise, every robot moves to an adjacent cell in the chosen direction.

You can send as many commands as you want (possibly, zero), in any order. Your goal is to make at least one robot reach the upper left corner of the field. Can you do this without forcing any of the robots to explode?


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 5000$) — the number of test cases.

Each test case starts with a line containing two integers $n$ and $m$ ($1 \le n, m \le 5$) — the number of rows and the number of columns, respectively. Then $n$ lines follow; each of them contains a string of $m$ characters. Each character is either E (empty cell} or R (robot).

Additional constraint on the input: in each test case, there is at least one robot on the field.


-----Output-----

If it is possible to make at least one robot reach the upper left corner of the field so that no robot explodes, print YES. Otherwise, print NO.


-----Examples-----

Input
6
1 3
ERR
2 2
ER
RE
2 2
ER
ER
1 1
R
4 3
EEE
EEE
ERR
EER
3 3
EEE
EER
REE
Output
YES
NO
YES
YES
YES
NO


-----Note-----

Explanations for test cases of the example:

in the first test case, it is enough to send a command to move left.

in the second test case, if you try to send any command, at least one robot explodes.

in the third test case, it is enough to send a command to move left.

in the fourth test case, there is already a robot in the upper left corner.

in the fifth test case, the sequence "move up, move left, move up" leads one robot to the upper left corner;

in the sixth test case, if you try to move any robot to the upper left corner, at least one other robot explodes.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
import sys
input = sys.stdin.readline
T = int(input())
for testcase in range(1, T + 1):
	(n, m) = list(map(int, input().split()))
	up = -1
	left = m + 1
	linenumber = 0
	for i in range(n):
		line = input()
		first = line.find('R')
		if first != -1:
			if up == -1:
				up = linenumber
				upcol = first
			if first < left:
				left = first
				leftrow = linenumber
		linenumber += 1
	if up == -1:
		print('NO')
	elif upcol == left or leftrow == up:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
	board = []
	(rows, columns) = [int(i) for i in input().split()]
	for y in range(rows):
		board.append([i for i in input().replace('\n', '')])
	x_top = 0
	y_top = 0
	for y in range(rows):
		if not 'R' in board[y]:
			y_top = y + 1
		else:
			break
	for x in range(columns):
		column = [line[x] for line in board]
		if not 'R' in column:
			x_top = x + 1
		else:
			break
	if board[y_top][x_top] == 'R':
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def solution(content, rows, columns):
	row_min = rows
	column_min = columns
	for i in range(rows):
		for j in range(columns):
			if j >= column_min:
				continue
			if content[i][j] == 'E':
				continue
			row_min = min(row_min, i)
			column_min = min(column_min, j)
	if content[row_min][column_min] == 'R':
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	(rows, columns) = map(int, input().split())
	content = []
	for _ in range(rows):
		content.append(input())
	solution(content, rows, columns)


line_contains = int(input())
li = []
for contains in range(line_contains):
	lis = []
	(rows, columns) = input().split()
	rows = int(rows)
	l = 'No'
	for n_rows in range(rows):
		x = input()
		lis.append(x)
	if len(lis) == 1:
		li.append('YES')
	elif True:
		for i in lis:
			if 'R' in i:
				c = i.find('R')
				break
		for i in lis:
			if 'R' in i:
				if i.find('R') < c:
					li.append('NO')
					break
		else:
			li.append('YES')
for i in li:
	print(i)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for z in range(n):
		s = input().strip()
		a.append(s)
	flag = False
	b = False
	x = [0, 0]
	for i in range(n):
		if b:
			break
		for j in range(m):
			if a[i][j] == 'R':
				if j == 0:
					flag = True
				else:
					x = [i, j]
				b = True
				break
	if flag:
		print('YES')
		continue
	b = False
	for j in range(m):
		if b:
			break
		for i in range(n):
			if a[i][j] == 'R':
				if [i, j] == x:
					flag = True
				b = True
				break
	if flag:
		print('YES')
	else:
		print('NO')


I = input
for _ in [0] * int(I()):
	n = int(I().split()[0]) - 1
	while (j := I().find('R')) < 0:
		n -= 1
	print('YNEOS'[any(['R' in I()[:j] for _ in [0] * n])::2])


lines = []
while True:
	try:
		a = input()
		lines.append(a)
	except:
		break
notest = int(lines[0])
i = 1
while i < len(lines):
	(norows, nocols) = (int(lines[i].split()[0]), int(lines[i].split()[1]))
	possible = True
	found = False
	for j in range(i + 1, i + 1 + norows):
		if 'R' in lines[j]:
			if found:
				if lines[j].index('R') >= n:
					continue
				else:
					possible = False
			else:
				(m, n) = (j, lines[j].index('R'))
				found = True
	if possible:
		print('YES')
	else:
		print('NO')
	i += norows + 1


t = int(input())
for k in range(t):
	s = input().split(' ')
	(n, m) = (int(s[0]), int(s[1]))
	for r in range(n):
		s = input()
		if 'R' in s:
			i = s.index('R')
			break
	val = 'YES'
	for rr in range(r + 1, n):
		s = input()
		if 'R' in s:
			if s.index('R') < i:
				val = 'NO'
	print(val)


import sys

def solve():
	inp = sys.stdin.readline
	(n, m) = map(int, inp().split())
	a = [None] * n
	r = n + 1
	c = m + 1
	for i in range(n):
		a[i] = inp()
		for j in range(m):
			if a[i][j] == 'R':
				r = min(r, i)
				c = min(c, j)
	if r < n and c < m and (a[r][c] == 'R'):
		print('YES')
	else:
		print('NO')

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


n = int(input())
l2 = []
for i in range(n):
	(n, m) = [int(x) for x in input().split()]
	l = []
	for i in range(n):
		a = input()
		l.append(a)
	l2.append(l)
for i in l2:
	s = 0
	l = []
	for j in i:
		if 'R' in j:
			l.append(j.index('R'))
	else:
		if l[0] == sorted(l)[0]:
			print('YES')
		else:
			print('NO')


I = input
for _ in [0] * int(I()):
	a = (*filter(None, (I().find('R') + 1 for _ in [0] * int(I().split()[0]))),)
	print('YNEOS'[a[0] > min(a)::2])


for i in range(int(input())):
	(n, m) = map(int, input().split())
	idx = None
	found = False
	for j in range(n):
		line = input()
		if 'R' in line and (not found):
			if idx is None:
				idx = line.index('R')
			elif line.index('R') < idx:
				found = True
	if found:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	mat = [input().strip() for _ in range(n)]
	leftmost = m - 1
	top = n - 1
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'R':
				leftmost = min(leftmost, j)
				top = min(top, i)
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'R':
				if leftmost - j >= 0 and top - i >= 0:
					return 'YES'
	return 'NO'
for _ in range(int(input())):
	print(solve())


for i in range(int(input())):
	(r, c) = [int(i) for i in input().split(' ')]
	l1 = [input().find('R') for k in range(r)]
	l1 = [l for l in l1 if l >= 0]
	if l1[0] <= min(l1):
		print('YES')
	else:
		print('NO')


I = input
for _ in [0] * int(I()):
	a = (*filter(None, (~I().find('R') for _ in [0] * int(I().split()[0]))),)
	print('YNEOS'[a[0] < max(a)::2])


def ri():
	return [int(i) for i in input().split()]

def robots(mapa: list) -> bool:
	if len(mapa) == 1 and 'R' in mapa[0] or 'R' == mapa[0][0]:
		return True
	if len(set(mapa[0])) == 1:
		return robots(mapa[1:])
	newmap = []
	for l in mapa:
		if l[0] == 'R':
			return False
		newmap.append(l[1:])
	else:
		return robots(newmap)
for _ in range(int(input())):
	mapa1 = []
	for i in range(ri()[0]):
		mapa1.append(input())
	if robots(mapa1):
		print('YES')
	else:
		print('NO')


f = input
for l in [0] * int(f()):
	a = (*filter(None, (~f().find('R') for p in [0] * int(f().split()[0]))),)
	print('YNEOS'[a[0] < max(a)::2])


for _ in range(int(input())):
	(row, col) = map(int, input().split())
	r_found = False
	possible = True
	firstIndex = 0
	for i in range(row):
		current = input()
		if not r_found and 'R' in current:
			r_found = True
			firstIndex = current.index('R')
		elif r_found and 'R' in current and (current.index('R') < firstIndex):
			possible = False
	print('YES' if possible else 'NO')


n = int(input())

def is_robot_above(grid, row_index):
	for r in range(row_index):
		for c in grid[r]:
			if c == 'R':
				return True
	return False

def find_left_most(grid):
	for col in range(len(grid[0])):
		for row in range(len(grid)):
			if grid[row][col] == 'R':
				return (row, col)
for test_case in range(n):
	(rows, cols) = [int(val) for val in input().split()]
	grid = []
	for row in range(rows):
		grid.append(input().strip())
	(row, col) = find_left_most(grid)
	if is_robot_above(grid, row):
		print('NO')
	else:
		print('YES')


I = input
for _ in ' ' * int(I()):
	(r, c) = map(int, I().split())
	l = [-1, -1]
	t = [-1, -1]
	f = False
	for i in range(r):
		a = I()
		if t[0] < 0:
			if 'R' in a:
				t = [i, a.find('R')]
				l = [i, a.find('R')]
		elif 'R' in a:
			if a.find('R') < l[1]:
				f = True
	print('YNEOS'[f::2])


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	e = []
	count = 0
	for i in range(b):
		d = input()
		e += [d]
	f = []
	for i in range(len(e)):
		if 'R' in e[i]:
			f += [e[i].index('R')]
	if f[0] == min(f):
		print('YES')
	else:
		print('NO')


num = int(input())
for i in range(num):
	(n, m) = map(int, input().split())
	values = []
	k = 0
	while k < n:
		val = input()
		if 'R' in val:
			values.append(val.index('R'))
		k += 1
	if values.__len__() == 1:
		print('YES')
	elif min(values[1:]) - values[0] >= 0:
		print('YES')
	else:
		print('NO')


I = input
for _ in [0] * int(I()):
	a = [I() for _ in [0] * int(I().split()[0])]
	(b, c) = (['01'['R' in s] for s in l] for l in (a, [*zip(*a)]))
	print('YNEOS'[a[b.index('1')][c.index('1')] < 'R'::2])


t = int(input())
while t > 0:
	t -= 1
	[n, m] = [int(x) for x in input().split(' ')]
	ln = -1
	lm = -1
	inp_grid = []
	i = 0
	while i < n:
		row = input()
		inp_grid.append(row)
		if 'R' in row:
			if ln != -1:
				ln = min(i, ln)
			else:
				ln = i
			if lm != -1:
				lm = min(row.index('R'), lm)
			else:
				lm = row.index('R')
		i += 1
	if ln == -1 or lm == -1:
		print('NO')
	elif inp_grid[ln][lm] == 'R':
		print('YES')
	else:
		print('NO')


def process_case():
	(n, m) = list(map(int, input().split()))
	highest_robot_column = -1
	left_most_robot_column = m
	for _ in range(n):
		row_entry = input()
		if 'R' in row_entry:
			robot_position = row_entry.index('R')
			if robot_position < left_most_robot_column:
				left_most_robot_column = robot_position
			if highest_robot_column == -1:
				highest_robot_column = robot_position
	print('NO') if left_most_robot_column < highest_robot_column else print('YES')
num_of_tests = int(input())
for _ in range(num_of_tests):
	process_case()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lefts = [input().find('R') for _ in range(n)]
	lefts = [l for l in lefts if l >= 0]
	if lefts[0] <= min(lefts):
		print('YES')
	else:
		print('NO')


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_ls():
	return list(map(int, sys.stdin.readline().strip().split()))

def main():
	for _ in range(int(input())):
		(n, m) = get_ints()
		ls = []
		ok = True
		for i in range(n):
			x = input()
			ls.append(x)
		(a, b) = (0, 0)
		found = False
		for i in range(n):
			for j in range(m):
				if ls[i][j] == 'R':
					a = i
					b = j
					found = True
					break
			if found:
				break
		for i in range(a + 1, n):
			for j in range(b):
				if ls[i][j] == 'R':
					ok = False
					break
		print('YES' if ok else 'NO')
main()


for _ in range(int(input())):
	lst = []
	(n, m) = map(int, input().split())
	for i in range(n):
		line = input()
		if 'R' in line:
			lst.append(line.index('R'))
		else:
			continue
	if min(lst) == lst[0]:
		print('YES')
	else:
		print('NO')


tst = int(input())
for i in range(tst):
	gg = []
	(n, m) = map(int, input().split())
	for j in range(n):
		s = input()
		if 'R' in s:
			gg.append(s.index('R'))
		else:
			continue
	if min(gg) == gg[0]:
		print('YES')
	else:
		print('NO')


N = int(input())
for i in range(N):
	(sc, rc) = map(int, input().split())
	ur = rc
	upfound = 0
	lr = 0
	stop = 0
	for s in range(sc):
		a = str(input())
		if s == 0 and a.find('R') == 0:
			ur = lr
			stop = 1
		elif stop == 0:
			if a.find('R') >= 0:
				if upfound == 0:
					ur = a.find('R')
					lr = ur
					upfound = 1
				elif a.find('R') < lr:
					lr = a.find('R')
	if ur == lr:
		print('YES')
	else:
		print('NO')


def solve():
	(n, m) = map(int, input().split())
	mm = []
	for i in range(n):
		mm.append(input())
	p = -1
	for i in range(n):
		if p == -1:
			for j in range(m):
				if mm[i][j] == 'R':
					p = j
					break
		else:
			for j in range(0, p):
				if mm[i][j] == 'R':
					print('NO')
					return
	print('YES')
t = int(input())
while t > 0:
	t -= 1
	solve()


t = int(input())
for _ in range(t):
	(row, col) = map(int, input().split())
	k = 0
	o = 0
	ans = 'YES'
	for i in range(row):
		x = input()
		if 'R' in x:
			k = x.index('R')
			o = i + 1
			break
	for i in range(o, row):
		x = input()
		if 'R' in x:
			if x.index('R') < k:
				ans = 'NO'
	print(ans)


a = int(input())
for x in range(a):
	(b, c) = map(int, input().split())
	f = 0
	for x in range(b):
		d = input()
		if 'R' in d and f == 0:
			l = d.index('R')
			v = x
			f = 1
		elif 'R' in d and f == 1:
			if d.index('R') - l >= 0 and x - v >= 0:
				continue
			else:
				f = 2
	if f == 2:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(y, x) = map(int, input().split(' '))
	found = False
	least = None
	possible = True
	for _ in range(y):
		r = input()
		if 'R' not in r:
			continue
		if found:
			if r.index('R') < least:
				possible = False
		else:
			least = r.index('R')
			found = True
	print('YES' if possible else 'NO')


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	l = []
	for j in range(a):
		s = input()
		if 'R' in s:
			l.append(s.index('R'))
	if min(l) != l[0]:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	a = []
	for i in range(r):
		s = input()
		a.append(s)
	(x, y) = (-1, -1)
	ok = False
	for i in range(r):
		for j in range(c):
			if a[i][j] == 'R':
				(x, y) = (i, j)
				ok = True
				break
		if ok:
			break
	find = 'YES'
	for i in range(x + 1, r):
		for j in range(y):
			if a[i][j] == 'R':
				find = 'NO'
				break
		if find == 'NO':
			break
	print(find)


def up(l, n, m):
	ans = 0
	while ans < n:
		for i in range(m):
			if l[ans][i] == 'R':
				return ans
		ans += 1
	return -1

def left(l, n, m):
	ans = 0
	while ans < m:
		for i in range(n):
			if l[i][ans] == 'R':
				return ans
		ans += 1
	return -1
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	d = []
	for i in range(n):
		d.append(input())
	if d[0][0] == 'R':
		print('YES')
	else:
		u = up(d, n, m)
		l = left(d, n, m)
		if d[u][l] == 'R':
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline

def solve():
	(n, m) = map(int, input().split())
	g = [input().rstrip() for __ in range(n)]
	for i in range(n):
		for j in range(m):
			if g[i][j] == 'R':
				f = 0
				for a in range(0, i):
					for b in range(m):
						if g[a][b] == 'R':
							f = 1
							break
					if f:
						break
				for a in range(0, j):
					for b in range(n):
						if g[b][a] == 'R':
							f = 1
							break
					if f:
						break
				if not f:
					return 1
	return 0
for __ in range(int(input())):
	print('YES' if solve() else 'NO')


t = int(input())
while t:
	(n, m) = map(int, input().split())
	v = list()
	p_ans = -1
	mina = 600
	for i in range(n):
		v.append(list(input()))
		if 'R' in v[-1]:
			if p_ans < 0:
				p_ans = v[-1].index('R')
			mina = min(mina, v[-1].index('R'))
	if p_ans == mina:
		print('YES')
	else:
		print('NO')
	t -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	e = 0
	for i in range(n):
		a.append(input())
	i = 0
	while i < n and e == 0:
		for j in range(m):
			if a[i][j] == 'R':
				c = i
				d = j
				e = 1
				break
		i += 1
	i = c + 1
	e = 0
	while i < n and e == 0:
		for j in range(d):
			if a[i][j] == 'R':
				p = i
				q = j
				e = 1
				break
		i += 1
	if e == 1:
		print('NO')
	else:
		print('YES')


qq = int(input())
for fe in range(qq):
	(n, m) = [int(i) for i in input().split()]
	a = [input() for i in range(n)]
	d = {}
	for i in range(n):
		if 'R' in a[i]:
			d[i] = a[i].find('R') % m
	if d[min(d.keys())] != min(d.values()):
		print('NO')
	else:
		print('YES')


def ToUp(a):
	s = a[:indx]
	f = a[indx:]
	return f + s

def ToRight(a):
	s = a[0].index('R')
	for i in a:
		try:
			if i.index('R') < s:
				return 'NO'
		except ValueError:
			continue
	return 'YES'
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [list(input()) for i in range(n)]
	indx = 0
	if n == 1 and m == 1:
		print('YES')
		continue
	for i in range(n):
		if 'R' in a[i]:
			indx = i
			break
	a = ToUp(a)
	print(ToRight(a))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(ab, lt, ab_a, lt_a) = (10, 10, 10, 10)
	for i in range(n):
		s = input()
		for j in range(m):
			if s[j] == 'R':
				if j < lt:
					lt = j
					lt_a = i
				if i < ab:
					ab = i
					ab_a = j
	if ab == lt_a or ab_a == lt:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input())
	cord = 0
	f = True
	for i in range(m):
		for j in range(n):
			if l[j][i] == 'R':
				cord = j
				f = False
				break
		if not f:
			break
	ans = True
	for k in range(cord):
		if 'R' in l[k]:
			ans = False
			break
	if ans:
		print('YES')
	else:
		print('NO')


N = int(input())
for _ in range(N):
	(n, m) = input().split()
	idx1 = -1
	idx2 = -1
	for _ in range(int(n)):
		in_str = input()
		for i in range(len(in_str)):
			if in_str[i] == 'R':
				if idx1 == -1:
					idx1 = i
				elif idx2 == -1 and i < idx1:
					idx2 = i
				else:
					pass
				break
	if idx1 <= idx2 or idx2 == -1:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		try:
			a.append(input().index('R'))
		except:
			pass
	x = len(a)
	y = a[0]
	for i in range(1, x):
		if a[i] < a[0]:
			print('NO')
			break
	else:
		print('YES')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		matrix.append(list(input()))
	flag = True
	first_robort_position = -1
	second_robort_position = -1
	for row in matrix:
		if 'R' in row and first_robort_position == -1:
			first_robort_position = row.index('R')
		elif 'R' in row and first_robort_position != -1:
			second_robort_position = row.index('R')
			if first_robort_position > second_robort_position:
				flag = False
				break
	if flag:
		print('YES')
	else:
		print('NO')


def ss(g):
	n = len(g)
	m = len(g[0])
	for i in range(m):
		for j in range(n):
			if g[j][i] == 'R':
				return [j, i]

def ss1(g):
	n = len(g)
	m = len(g[0])
	for i in range(n):
		for j in range(m):
			if g[i][j] == 'R':
				return [i, j]
	return [-1, -1]
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	g = []
	for _ in range(n):
		s = str(input())
		g.append(s)
	if g[0][0] == 'R':
		print('YES')
	else:
		t1 = ss1(g)
		if t1 == [-1, -1]:
			print('NO')
		else:
			first_column = ss(g)
			if t1 == first_column:
				print('YES')
			else:
				print('NO')


import math

def Solve():
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		b = input()
		a.append(b)
	if a[0][0] == 'R':
		print('YES')
		return
	c = []
	d = []
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'R':
				c.append(i)
				d.append(j)
	minc = min(c)
	mind = min(d)
	for i in range(len(c)):
		c[i] = c[i] - minc
		d[i] = d[i] - mind
	res = False
	for i in range(len(c)):
		if c[i] == d[i] and c[i] == 0:
			res = True
	if res == True:
		print('YES')
	else:
		print('NO')
q = int(input())
while q > 0:
	Solve()
	q = q - 1


for i in range(int(input())):
	(n, q) = map(int, input().split())
	a = -1
	z = [0] * n
	for i in range(n):
		s = input()
		z[i] = s.find('R')
		if z[i] > -1:
			if a == -1:
				a = i
		else:
			z[i] = q + 6
	if min(z) < z[a]:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(m, n) = [int(x) for x in input().split()]
	a = [input() for i in range(m)]
	ok = 1
	tempCol = n
	for i in range(m):
		for j in range(n):
			if a[i][j] == 'R':
				ok = 0
				tempCol = j
				break
		if not ok:
			break
	ok = 1
	for i in range(m):
		for j in range(tempCol):
			if a[i][j] == 'R':
				ok = 0
				break
		if not ok:
			break
	if ok:
		print('YES')
	else:
		print('NO')


I = input
for _ in [0] * int(I()):
	a = [I() for _ in [0] * int(I().split()[0])]
	(i, j) = (['R' in s for s in l].index(1) for l in (a, [*zip(*a)]))
	print('YNEOS'[a[i][j] < 'R'::2])


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = []
	for i in range(n):
		s = input()
		a.append(s)
	c = -1
	flag = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'R':
				c = j
				break
		if c != -1:
			break
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'R' and j < c:
				flag = 1
				print('NO')
				break
		if flag == 1:
			break
	if flag == 0:
		print('YES')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	num = []
	for i in range(n):
		s = input()
		num.append(s)
	f = 1
	for i in range(n):
		if num[i].find('R') != -1:
			x = num[i].index('R')
			break
	for j in range(i + 1, n):
		if num[j].find('R') != -1:
			y = num[j].index('R')
			if y >= x:
				f = 1
			else:
				f = 0
				break
	if f:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	(n, m) = map(int, input().split())
	a = []
	flag = False
	for i in range(n):
		a.append(input())
	i = 0
	while i < n:
		for j in range(m):
			if a[i][j] == 'R':
				c = i
				d = j
				flag = True
				break
		if flag:
			break
		i += 1
	c = i + 1
	while c < n:
		for j in range(d):
			if a[c][j] == 'R':
				flag = False
				break
		if flag == False:
			break
		c += 1
	if flag:
		print('YES')
	else:
		print('NO')
	t -= 1


import sys

def solve(x, y, grid):
	rs = []
	for i in range(x):
		for j in range(y):
			if grid[i][j] == 'R':
				rs.append((i, j))
	rsx = sorted(rs, key=lambda x: x[0])
	sx = rsx[0]
	for (i, j) in rsx:
		if j < sx[1]:
			return 'NO'
	rsy = sorted(rs, key=lambda x: x[1])
	sy = rsy[0]
	for (i, j) in rsy:
		if i < sy[0]:
			return 'NO'
	return 'YES'
n = int(sys.stdin.readline())
for _ in range(n):
	[x, y] = [int(n) for n in sys.stdin.readline().strip().split()]
	grid = []
	for _ in range(x):
		grid.append(sys.stdin.readline().strip())
	print(solve(x, y, grid))


def solve():
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(input())

	def find_upper():
		for i in range(n):
			for j in range(m):
				if mat[i][j] == 'R':
					return (i, j)

	def find_left():
		for j in range(m):
			for i in range(n):
				if mat[i][j] == 'R':
					return (i, j)
	upper_most = find_upper()
	left_most = find_left()
	if upper_most == left_most:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	solve()


def solve():
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(input())

	def find_upper():
		for (i, s) in enumerate(mat):
			for (j, c) in enumerate(s):
				if c == 'R':
					return (i, j)

	def find_left():
		for (j, col) in enumerate(zip(*mat)):
			for (i, c) in enumerate(col):
				if c == 'R':
					return (i, j)
	upper_most = find_upper()
	left_most = find_left()
	if upper_most == left_most:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	solve()


def is_reachable(n, m):
	most_left_robot_row = -1
	most_left_robot_col = m - 1
	first_robot_row = -1
	for row_id in range(n):
		line = input().strip()
		for col_id in range(len(line)):
			if line[col_id] == 'R' and most_left_robot_col > col_id:
				most_left_robot_row = row_id
				most_left_robot_col = col_id
			if line[col_id] == 'R' and first_robot_row == -1:
				first_robot_row = row_id
	return 'YES' if first_robot_row >= most_left_robot_row else 'NO'
t = int(input())
for _ in range(t):
	(n, m) = [int(v) for v in input().strip().split(' ')]
	print(is_reachable(n, m))


import math, re

def fastlist():
	return list(map(int, input().split()))

def fastint():
	return int(input())

def solve():
	(n, m) = fastlist()
	x = 1000000
	b = True
	for i in range(n):
		dop = list(input())
		if 'R' in dop:
			if x == 1000000:
				dopp = 0
				while True:
					if dop[dopp] == 'R':
						break
					else:
						dopp += 1
				x = dopp
			else:
				dopp = 0
				while True:
					if dop[dopp] == 'R':
						break
					else:
						dopp += 1
				if dopp < x:
					b = False
	if b:
		print('YES')
	else:
		print('NO')
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for qwer in range(t):
	(n, m) = map(int, input().split())
	sp = []
	v = 0
	g = 1000000
	ui = True
	for i in range(n):
		el = list(input())
		sp.append(el)
		if 'R' in el:
			ui = False
			ind = el.index('R')
			g = min(ind, g)
		elif ui:
			v += 1
	fl = False
	for el in range(v + 1):
		if 'R' in sp[el][:g + 1]:
			print('YES')
			fl = True
			break
	if not fl:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = []
	for _ in range(n):
		s += [input()]
	minx = miny = 0
	flag = 0
	for i in range(n):
		for j in range(m):
			if s[i][j] == 'R':
				minx = i
				miny = j
				flag = 1
				break
		if flag:
			break
	flag = 0
	for i in range(minx + 1, n):
		for j in range(0, miny):
			if s[i][j] == 'R':
				flag = 1
				break
	if flag == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(bl, tr) = (-1, -1)
	(h, w) = map(int, input().split())
	m = []
	for i in range(h):
		m.append(list(input()))
	while (h > 0 or w > 0) and (bl == -1 or tr == -1):
		if tr == -1 and h >= 0 and ('R' in m[len(m) - h]):
			tr = len(m) - h
		w1 = len(m[0]) - w
		if bl == -1 and w >= 0 and ('R' in [i[w1] for i in m]):
			bl = w1
		w -= 1
		h -= 1
	print('YES' if m[tr][bl] == 'R' else 'NO')


def solve(n, m, array):
	leftMost = ''
	for i in range(m):
		for j in range(n):
			if array[j][i] == 'R':
				leftMost = [j, i]
				break
		if leftMost:
			break
	topMost = ''
	for i in range(n):
		for j in range(m):
			if array[i][j] == 'R':
				topMost = [i, j]
				break
		if topMost:
			break
	if leftMost[0] <= topMost[0]:
		return 'YES'
	else:
		return 'NO'
t = int(input())
for T in range(t):
	array = []
	(n, m) = list(map(int, input().split(' ')))
	for i in range(n):
		array.append(input())
	print(solve(n, m, array))


def checkValidity(col_row):
	messageChecker = False
	message = 'YES'
	row = col_row[0]
	col = col_row[1]
	flag = False
	ref_row = 0
	ref_col = 0
	for i in range(row):
		tempInput = input()
		if messageChecker is False:
			for index in range(len(tempInput)):
				if flag is False and tempInput[index] == 'R':
					ref_row = i
					ref_col = index
					flag = True
				elif tempInput[index] == 'R':
					if i - ref_row < 0 or index - ref_col < 0:
						message = 'NO'
						messageChecker = True
	return message
n = int(input())
for index in range(n):
	col_row = [int(i) for i in input().split()]
	print(checkValidity(col_row))


t = int(input())
for z in range(t):
	(n, m) = [int(x) for x in input().split()]
	l = []
	for y in range(n):
		l.append(input())
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'R':
				break
		if l[i][j] == 'R':
			break
	check = True
	u = i + 1
	while u < n and check:
		v = 0
		while v < j and check:
			if l[u][v] == 'R':
				check = False
			else:
				v += 1
		u += 1
	if check == True:
		print('YES')
	else:
		print('NO')


t = input()
end_result = ''
for i in range(int(t)):
	(m, n) = input().split()
	map = []
	for j in range(int(m)):
		map.append(input())
	found = False
	result = 'YES'
	row = 0
	while row < int(m):
		if not found:
			column = 0
		while not found and column < int(n):
			if map[row][column] == 'R':
				found = True
				break
			column += 1
		if found and 'R' in map[row][:column]:
			result = 'NO'
			break
		row += 1
	end_result += result + '\n'
print(end_result[:-1])


t = int(input())
for caso in range(t):
	(f, c) = map(int, input().split(' '))
	datos = []
	ans = 'YES'
	for fila in range(f):
		datos.append(input())
	rs = []
	for (i, fila) in enumerate(datos):
		for (j, letra) in enumerate(fila):
			if letra == 'R':
				rs.append([i, j])
				break
	primero = rs[0]
	for i in range(1, len(rs)):
		if rs[i][0] - primero[0] < 0 or rs[i][1] - primero[1] < 0:
			ans = 'NO'
	print(ans)