Consider a conveyor belt represented using a grid consisting of $n$ rows and $m$ columns. The cell in the $i$-th row from the top and the $j$-th column from the left is labelled $(i,j)$. 

Every cell, except $(n,m)$, has a direction R (Right) or D (Down) assigned to it. If the cell $(i,j)$ is assigned direction R, any luggage kept on that will move to the cell $(i,j+1)$. Similarly, if the cell $(i,j)$ is assigned direction D, any luggage kept on that will move to the cell $(i+1,j)$. If at any moment, the luggage moves out of the grid, it is considered to be lost. 

There is a counter at the cell $(n,m)$ from where all luggage is picked. A conveyor belt is called functional if and only if any luggage reaches the counter regardless of which cell it is placed in initially. More formally, for every cell $(i,j)$, any luggage placed in this cell should eventually end up in the cell $(n,m)$. 

This may not hold initially; you are, however, allowed to change the directions of some cells to make the conveyor belt functional. Please determine the minimum amount of cells you have to change.

Please note that it is always possible to make any conveyor belt functional by changing the directions of some set of cells.


-----Input-----

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10$). Description of the test cases follows.

The first line of each test case contains two integers $n, m$ ($1 \le n \le 100$, $1 \le m \le 100$)  — the number of rows and columns, respectively.

The following $n$ lines each contain $m$ characters. The $j$-th character in the $i$-th line, $a_{i,j}$ is the initial direction of the cell $(i, j)$. Please note that $a_{n,m}=$ C.


-----Output-----

For each case, output in a new line the minimum number of cells that you have to change to make the conveyor belt functional. 


-----Example-----
Input
4
3 3
RRD
DDR
RRC
1 4
DDDC
6 9
RDDDDDRRR
RRDDRRDDD
RRDRDRRDR
DDDDRDDRR
DRRDRDDDR
DDRDRRDDC
1 1
C

Output
1
3
9
0



-----Note-----

In the first case, just changing the direction of $(2,3)$ to D is enough.

You can verify that the resulting belt is functional. For example, if we place any luggage at $(2,2)$, it first moves to $(3,2)$ and then to $(3,3)$. 

In the second case, we have no option but to change the first $3$ cells from D to R making the grid equal to RRRC.

Source: codeforces | Difficulty: EASY
Tags: Complete search

Implementation

Greedy algorithms


Solutions:
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		b = list(input())
		a.append(b)
	c = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			c += 1
			a[i][m - 1] = 'D'
	for i in range(m):
		if a[n - 1][i] == 'D':
			c += 1
			a[n - 1][i] = 'R'
	print(c)


from sys import stdin
T = int(stdin.readline())
answer = ''
for t in range(T):
	(n, m) = map(int, stdin.readline().split())
	count = 0
	for i in range(n - 1):
		r = stdin.readline()[m - 1]
		if r == 'R':
			count += 1
	for i in stdin.readline():
		if i == 'D':
			count += 1
	answer += str(count) + '\n'
print(answer)


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, m) = [int(x) for x in inp().split()]
	grid = []
	ans = 0
	for i in range(n):
		grid.append(inp())
	for i in grid[-1]:
		if i == 'D':
			ans += 1
	for i in range(n):
		if grid[i][-1] == 'R':
			ans += 1
	print(ans)


import sys, math
from collections import Counter, deque, defaultdict
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
IN = lambda : input()
C = lambda : input().strip().split()
mod = 1000000007

def s(a):
	print(' '.join(list(map(str, a))))

def solve():
	(n, m) = M()
	a = []
	ans = 0
	for i in range(n):
		a.append(IN())
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			ans += 1
	for i in range(m - 1):
		if a[n - 1][i] != 'R':
			ans += 1
	print(ans)
for _ in range(I()):
	solve()


for _ in range(int(input())):
	l = []
	count = 0
	(n, m) = map(int, input().split())
	for i in range(n):
		s = input()
		l = list(s)
		if l[len(l) - 1] == 'R':
			count += 1
		if i == n - 1:
			count += l.count('D')
	print(count)


import math
t = int(input())
for q in range(t):
	(n, m) = [int(i) for i in input().split()]
	L = [input() for i in range(n)]
	s = 0
	for i in range(n):
		for j in range(m):
			if j == m - 1 and L[i][j] == 'R':
				s += 1
			elif i == n - 1 and L[i][j] == 'D':
				s += 1
	print(s)


import math, string, itertools, operator, fractions, heapq, collections, re, array, bisect, sys, functools

def solve(line):
	(m, n) = map(int, line.split())
	a = []
	for i in range(m):
		a.append(sys.stdin.readline().rstrip())
	ans = 0
	for i in range(m - 1):
		if a[i][-1] == 'R':
			ans += 1
	for i in range(n - 1):
		if a[m - 1][i] == 'D':
			ans += 1
	return ans
T = int(sys.stdin.readline())
t = 0
while True:
	line = sys.stdin.readline().rstrip()
	if not line:
		break
	print(solve(line))
	t += 1


import sys
import heapq

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, sys.stdin.readline().split())
		table = []
		for i in range(n):
			table.append(input().strip())
		ans = 0
		for i in range(n - 1):
			if table[i][-1] == 'R':
				ans += 1
		for i in range(m - 1):
			if table[-1][i] == 'D':
				ans += 1
		print(ans)
	return
main()


I = input
for _ in [0] * int(I()):
	r = 0
	for _ in [0] * int(I().split()[0]):
		s = I()
		r += s[-1] == 'R'
	print(r + s.count('D'))


def solve(l, n, m):
	ans = 0
	if m > 1:
		for i in range(m - 1):
			if l[n - 1][i] == 'D':
				ans += 1
	if n > 1:
		for i in range(n - 1):
			if l[i][m - 1] == 'R':
				ans += 1
	return ans
t = int(input())
for i in range(t):
	l = []
	(n, m) = map(int, input().split(' '))
	for qwe in range(n):
		l.append(input())
	print(solve(l, n, m))


t = int(input())
for x in range(t):
	s = input().split(' ')
	n = int(s[0])
	m = int(s[1])
	count = 0
	l = []
	for i in range(n):
		l.append(input())
	if n == 1:
		print(l[0].count('D'))
	elif m == 1:
		print(l.count('R'))
	else:
		for i in range(n):
			if i == n - 1:
				count += l[i].count('D')
			elif l[i][m - 1] == 'R':
				count += 1
		print(count)


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	ccc = 0
	for i in range(n):
		g = input()
		if g[-1] == 'C':
			for i in range(m - 1):
				if g[i] == 'D':
					ccc += 1
		elif g[-1] == 'R':
			ccc += 1
	print(ccc)


a = int(input())
for i in range(a):
	(x, y) = list(map(int, input().split()))
	ans = []
	for i in range(x):
		s = input()
		ans.append(s[-1])
	print(s.count('D') + ans.count('R'))


t = int(input())
a = []
count = []
for i in range(t):
	(n, m) = list(map(int, input().split()))
	a.append([])
	for j in range(n):
		a[i].append(input())
	y = 0
	x = a[i][-1].count('D')
	for j in range(len(a[i])):
		for k in range(len(a[i][j])):
			if a[i][j][-1] == 'R':
				y += 1
				break
	count.append(x + y)
for i in count:
	print(i)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = [input() for i in range(n)]
	ans = 0
	for i in range(n - 1):
		if s[i][m - 1] == 'R':
			ans += 1
	for i in range(m - 1):
		if s[n - 1][i] == 'D':
			ans += 1
	print(ans)


import sys
import random
from math import *

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

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

def trinput():
	return tuple(rinput())

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

def NOYES(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def YESNO(fl):
	if fl:
		print('YES')
	else:
		print('NO')

def main():
	(n, m) = rinput()
	q = [linput() for i in range(n)]
	print(sum([q[i][m - 1] != 'D' for i in range(n - 1)]) + sum([q[n - 1][i] != 'R' for i in range(m - 1)]))
for inytd in range(iinput()):
	main()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	ans = 0
	for i in range(n):
		s = input()
		a.append(list(s))
	for j in range(n):
		if j == n - 1:
			r = a[j].count('D')
			ans += r
		elif a[j][-1] == 'R':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [['' for i in range(m)] for j in range(n)]
	c = 0
	for i in range(n - 1):
		s = input()
		if s[-1] == 'R':
			c += 1
	s = input()
	c += s.count('D')
	print(c)


mod = 10 ** 9 + 7

def solve():
	(n, m) = map(int, input().split())
	s = []
	for i in range(n):
		s.append(list(input()))
	ans = 0
	for i in range(n - 1):
		if s[i][m - 1] != 'D':
			ans += 1
	for j in range(m - 1):
		if s[n - 1][j] != 'R':
			ans += 1
	print(ans)
t = 1
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	ans = 0
	for __ in range(r):
		s = input()
		if s[-1] == 'R':
			ans += 1
	for d in s:
		if d == 'D':
			ans += 1
	print(ans)


t = int(input())
for tt in range(t):
	s = input()
	n = [int(i) for i in s.split()]
	RR = 0
	CC = 0
	for i in range(n[0] - 1):
		r = input()
		if r[n[1] - 1] == 'R':
			RR += 1
	q = input()
	for i in range(len(q) - 1):
		if q[i] == 'D':
			CC += 1
	print(RR + CC, end='')
	if tt != t - 1:
		print()


for tt in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input())
	count = 0
	for i in range(n - 1):
		if l[i][m - 1] != 'D':
			count += 1
	for i in range(m - 1):
		if l[n - 1][i] != 'R':
			count += 1
	print(count)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	cnt = 0
	for x in range(n):
		a.append(input().rstrip())
		if a[-1][-1] == 'R':
			cnt += 1
	for x in a[-1]:
		if x == 'D':
			cnt += 1
	print(cnt)


t = int(input())
for f in range(t):
	b = []
	c = []
	(n, m) = input().split()
	zamen = 0
	for i in range(int(n)):
		a = str(input())
		if i == int(n) - 1:
			for j in range(int(m) - 1):
				c.append(a[j])
		b.append(a[int(m) - 1])
	for elem in b:
		if elem == 'R':
			zamen += 1
	for elem in c:
		if elem == 'D':
			zamen += 1
	print(zamen)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	ans = 0
	for i in range(n - 1):
		if mat[i][-1] != 'D':
			ans += 1
	for j in range(m - 1):
		if mat[-1][j] != 'R':
			ans += 1
	print(ans)


import random

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	c = 0
	for i in range(n):
		a = input()
		mat.append(a)
	for i in range(n):
		for j in range(m):
			if i == n - 1 and j < m - 1:
				if mat[i][j] == 'D':
					c += 1
			if j == m - 1 and i != n - 1:
				if mat[i][j] == 'R':
					c += 1
	print(c)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(list(input()))
	count = 0
	i = n - 1
	j = 0
	while j < m - 1:
		if arr[i][j] == 'D':
			count = count + 1
		j = j + 1
	i = 0
	j = m - 1
	while i < n - 1:
		if arr[i][j] == 'R':
			count = count + 1
		i = i + 1
	print(count)


t = int(input())
for i in range(t):
	inp = str(input()).split(' ')
	n = int(inp[0])
	m = int(inp[1])
	count = 0
	for j in range(n):
		l = str(input())
		if j == n - 1:
			count += l.count('D')
		elif l[m - 1] == 'R':
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	p = []
	for i in range(n):
		k = input()
		p.append(k)
	count = 0
	for i in range(len(p)):
		if p[i][-1] == 'R':
			count = count + 1
	u = p[-1]
	for i in range(len(u)):
		if u[i] == 'D':
			count = count + 1
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = [][:m]
	for i in range(n):
		st = input()
		arr.append(st)
	count = 0
	for j in range(n - 1):
		if arr[j][m - 1] == 'R':
			count += 1
	for j in range(m - 1):
		if arr[n - 1][j] == 'D':
			count += 1
	print(count)


import math
import os
import random
import re
import sys
from collections import defaultdict, Counter, deque
import heapq
from functools import lru_cache
from itertools import accumulate, chain, combinations, permutations, groupby, zip_longest
from math import floor, ceil, sqrt

def solve(mat, m, n):
	a = sum((mat[m - 1][j] != 'R' for j in range(n - 1)))
	b = sum((mat[i][n - 1] != 'D' for i in range(m - 1)))
	return a + b
t = int(input())
results = []
for _ in range(t):
	(m, n) = map(int, input().split())
	mat = [input() for _ in range(m)]
	results.append(solve(mat, m, n))
for res in results:
	print(res)


tc = int(input())
while tc:
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		s = input()
		arr.append(s)
	ans = 0
	for i in range(n):
		if arr[i][m - 1] == 'R':
			ans += 1
	for i in range(m):
		if arr[n - 1][i] == 'D':
			ans += 1
	print(ans)
	tc -= 1


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	(n, m) = Ri()
	lis = []
	for i in range(n):
		lis.append(ri())
	cnt = 0
	for i in range(0, n - 1):
		if lis[i][m - 1] == 'R':
			cnt += 1
	for i in range(0, m - 1):
		if lis[n - 1][i] == 'D':
			cnt += 1
	print(cnt)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	arr = []
	cnt = 0
	for i in range(n):
		arr.append(input())
	for i in range(n):
		if arr[i][-1] == 'R':
			cnt += 1
	for i in range(m):
		if arr[-1][i] == 'D':
			cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	li = []
	if n == 1 and m == 1:
		s = input()
		s = 0
	else:
		c1 = 0
		c2 = 0
		for i in range(n):
			x = input()
			x = list(x)
			li.append(x)
		for i in range(n):
			if li[i][m - 1] == 'R':
				c1 += 1
		for i in range(m):
			if li[n - 1][i] == 'D':
				c2 += 1
		s = c1 + c2
	print(s)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
ans = []
t = ini()
for _ in range(t):
	(n, m) = inm()
	count = 0
	for i in range(n):
		s = ins()
		if s[-1] == 'R':
			count += 1
	count += s.count('D')
	ans.append(count)
print('\n'.join(map(str, ans)))


t = int(input())
while t:
	(m, n) = map(int, input().split())
	l = []
	for i in range(m):
		a = list(map(str, input().split()))
		l.append(a)
	c = 0
	for i in range(m - 1):
		z = l[i][0]
		p = z[len(z) - 1]
		if p == 'R':
			c += 1
	p = 0
	pp = str(l[m - 1])
	print(pp.count('D') + c)
	t -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().strip().split())
	x = 1
	y = 1
	cnt = 0
	for x in range(n):
		s = input()
		if x < n - 1:
			if s[-1] != 'D':
				cnt += 1
		else:
			for i in range(len(s) - 1):
				if s[i] != 'R':
					cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	chng = 0
	for i in range(n):
		arr = str(input())
		if arr[m - 1] == 'R':
			chng += 1
	for j in arr:
		if j == 'D':
			chng += 1
	print(chng)


x = int(input())
for _ in range(x):
	(n, m) = [int(x) for x in input().strip().split()]
	answer = 0
	for i in range(n):
		line = input()
		if i == n - 1:
			for c in line:
				if c == 'D':
					answer += 1
		elif line[-1] == 'R':
			answer += 1
	print(answer)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ls = []
	for i in range(n):
		ls.append(list(input()))
	count = 0
	for i in range(n - 1):
		if ls[i][-1] == 'R':
			count += 1
	for i in range(m - 1):
		if ls[-1][i] == 'D':
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = []
	for j in range(n):
		l.append(input())
	ans = 0
	for j in range(n):
		if l[j][m - 1] == 'R':
			ans += 1
	for j in range(m):
		if l[n - 1][j] == 'D':
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	count1 = 0
	for i in range(n):
		temp = list(input())
		if i < n - 1 and temp[m - 1] == 'R':
			count1 += 1
		if i == n - 1:
			count1 += temp.count('D')
	print(count1)
	t -= 1


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().rstrip().split()))
	mn = 0
	for i in range(n):
		a = list(input())
		if i != n - 1:
			if a[-1] == 'R':
				mn += 1
		else:
			for j in range(m - 1):
				if a[j] == 'D':
					mn += 1
	print(mn)


testcase = int(input())
for i in range(testcase):
	s = input()
	temp = s.split()
	row = int(temp[0])
	column = int(temp[1])
	matrix = []
	for i in range(row):
		r = input()
		matrix.append(r)
	dCount = 0
	rCount = 0
	for i in range(column - 1):
		if matrix[row - 1][i] == 'D':
			dCount += 1
	for i in range(row - 1):
		if matrix[i][column - 1] == 'R':
			rCount += 1
	print(dCount + rCount)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	grid = []
	ctr = 0
	for i in range(n):
		grid.append(input())
	for i in range(m - 1):
		if grid[n - 1][i] != 'R':
			ctr += 1
	for i in range(n - 1):
		if grid[i][m - 1] != 'D':
			ctr += 1
	print(ctr)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(n, m) = map(int, fastinput().split())
	count = 0
	for i in range(n):
		s = input()
		if s[-1] == 'R':
			count += 1
		if i == n - 1:
			for j in range(m - 1):
				if s[j] == 'D':
					count += 1
	print(count)


def ii():
	return int(input())

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

def mi():
	return map(int, input().split())

def main():
	for i in range(ii()):
		(n, m) = mi()
		count = 0
		for i in range(n):
			s = input()
			if s[-1] == 'R':
				count += 1
			if i == n - 1:
				for j in s:
					if j == 'D':
						count += 1
		print(count)
main()


def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
for _ in range(ii()):
	(n, m) = mi()
	a = []
	for i in range(n):
		a.append(si())
	ans = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			ans += 1
	for i in range(m):
		if a[n - 1][i] == 'D':
			ans += 1
	print(ans)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(n, m) = mapi()
	mat = []
	for i in range(n):
		mat.append(list(input().strip()))
	vis = {}
	res = 0
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'R' and j + 1 >= m or (mat[i][j] == 'D' and i + 1 >= n):
				res += 1
	print(res)


t = int(input())
for T in range(t):
	x = input()
	(n, m) = x.split(' ')
	n = int(n)
	m = int(m)
	ans = 0
	for i in range(n):
		s = input()
		if i != n - 1:
			if s[-1] == 'R':
				ans += 1
		else:
			for i in s:
				if i == 'D':
					ans += 1
	print(ans)


import io, os
from collections import deque
import bisect
RL = lambda : list(map(int, input().split(' ')))
T = int(input())
for _ in range(T):
	(n, m) = RL()
	ans = 0
	for i in range(n):
		s = input()
		if s[-1] == 'R':
			ans += 1
	for i in range(len(s)):
		if s[i] == 'D':
			ans += 1
	print(ans)


for i in range(int(input())):
	(m, n) = map(int, input().split())
	last_col = []
	mat = []
	for i in range(m):
		mat.append(input().split())
	ct = 0
	for i in mat:
		if i[-1][-1] != 'D' and i[-1][-1] != 'C':
			ct += 1
	for i in mat[-1][-1]:
		if i != 'R' and i != 'C':
			ct += 1
	print(ct)


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = [int(j) for j in input().split()]
	matrix = []
	for i in range(n):
		a = input()
		matrix.append(a)
	lc = m - 1
	count = 0
	for i in range(n):
		if matrix[i][lc] == 'R':
			count += 1
	lr = n - 1
	for i in range(m):
		if matrix[lr][i] == 'D':
			count += 1
	print(count)


n = list(map(int, input().split()))[0]
for t in range(n):
	(a, b) = map(int, input().split())
	count = 0
	for k in range(a):
		st = input()
		if k != a - 1:
			if st[-1] != 'D':
				count += 1
		else:
			for j in range(b - 1):
				if st[j] != 'R':
					count += 1
	print(count)


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	(n, m) = li()
	a = []
	for i in range(n):
		a.append(input().strip())
	c = 0
	for i in range(m):
		if a[n - 1][i] == 'D':
			c += 1
	for i in range(n):
		if a[i][m - 1] == 'R':
			c += 1
	print(c)
for _ in range(I()):
	solve()


from collections import defaultdict as dd
import math
import sys
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

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

def solve():
	(n, m) = mi()
	grid = []
	for i in range(n):
		grid.append(input())
	count = 0
	for i in range(n - 1):
		if grid[i][m - 1] != 'D':
			count += 1
	for i in range(m - 1):
		if grid[n - 1][i] != 'R':
			count += 1
	print(count)
q = nn()
for _ in range(q):
	solve()


def function(n, m, arr):
	count = 0
	for i in range(n):
		if i == n - 1:
			for j in arr[n - 1]:
				if j != 'R':
					count += 1
		if arr[i][m - 1] != 'D':
			count += 1
	return count - 2
t = int(input())
while t:
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		s = str(input())
		x = []
		for j in s:
			x.append(j)
		arr.append(x)
	print(function(n, m, arr))
	t -= 1


for _ in range(0, int(input())):
	li1 = input()
	li = li1.split()
	n = int(li[0])
	m = int(li[1])
	a = []
	for k in range(0, n):
		s = input()
		x = list(s)
		a.append(x)
	l = 0
	for i in range(0, n):
		if a[i][m - 1] == 'R':
			l = l + 1
	for j in range(0, m):
		if a[n - 1][j] == 'D':
			l = l + 1
	print(l)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	answer = 0
	for i in range(n):
		a = input()
		if i == n - 1:
			answer += a.count('D')
		elif a[-1] == 'R':
			answer += 1
	print(answer)


for _ in range(int(input())):
	(n, m) = list(map(int, input().strip().split()))
	li = []
	fin1 = 0
	for i in range(n):
		li.append(list(input()))
	test = []
	for i in range(n):
		test.append(li[i][m - 1])
	fin1 = test.count('R') + li[n - 1].count('D')
	print(fin1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	for i in range(n):
		l = input()
		if i != n - 1:
			if l[-1] != 'D':
				c += 1
		else:
			for j in range(m - 1):
				if l[j] != 'R':
					c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = input().split()
	edits = 0
	for i in range(1, int(n) + 1):
		line = input()
		if int(n) - i == 0 and 'D' in line:
			edits += line.count('D')
		if line[-1] == 'R':
			edits += 1
	print(edits)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split(' ')))
	(a, c) = ([], 0)
	if n == 1:
		print(input().count('D'))
	elif m == 1:
		for i in range(n):
			if input() == 'R':
				c += 1
		print(c)
	else:
		for i in range(n):
			a.append(input())
		for i in range(n - 1):
			if a[i][-1] == 'R':
				c += 1
		c += a[-1].count('D')
		print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for _ in range(n):
		l.append(input())
	cnt = 0
	for i in range(n - 1):
		if l[i][m - 1] == 'R':
			cnt += 1
	for j in range(m - 1):
		if l[n - 1][j] == 'D':
			cnt += 1
	print(cnt)


def solve(n, m, arr):
	cnt = 0
	for i in range(n - 1):
		if arr[i][m - 1] == 'R':
			cnt += 1
	for j in range(m - 1):
		if arr[n - 1][j] == 'D':
			cnt += 1
	print(cnt)
t = int(input())
while t != 0:
	(n1, m1) = map(int, input().split(' '))
	s = [list(input()) for _ in range(n1)]
	solve(n1, m1, s)
	t -= 1


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(1, itg() + 1):
	(n, m) = mpint()
	g = [inp() for _ in range(n)]
	ans = 0
	for i in range(n):
		if g[i][-1] == 'R':
			ans += 1
	ans += g[-1].count('D')
	print(ans)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	(n, m) = mInt()
	ans = 0
	for i in range(n - 1):
		a = input()
		if a[m - 1] == 'R':
			ans += 1
	a = input()
	for i in range(m):
		if a[i] == 'D':
			ans += 1
	print(ans)


for test_i in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [list(input()) for i in range(n)]
	arr[n - 1][m - 1] = 'R'
	vis = [[False for i in range(m)] for i in range(n)]
	ans = 0
	for r in range(n):
		for c in range(m):
			if not vis[r][c] and r + c < n + m - 2:
				(r1, c1) = (r, c)
				while r1 < n and c1 < m and (not vis[r1][c1]):
					vis[r1][c1] = True
					if arr[r1][c1] == 'R':
						c1 += 1
					else:
						r1 += 1
				ans += c1 == m and r1 != n - 1 or r1 == n
	print(ans)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	c = 0
	for i in range(n):
		b = list(input())
		for j in range(len(b)):
			if i != n - 1 and j == len(b) - 1:
				if b[j] == 'R':
					b[j] = 'D'
					c += 1
			if i == n - 1:
				if b[j] == 'D':
					b[j] = 'R'
					c += 1
	print(c)


import os
from io import BytesIO, IOBase
import sys

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		s = [0 for i in range(n)]
		for i in range(n):
			s[i] = input()
		ans = 0
		for i in range(n):
			if s[i][m - 1] != 'D':
				ans += 1
		for i in range(m):
			if s[n - 1][i] != 'R':
				ans += 1
		print(ans - 2)
	return
BUFSIZE = 1048576

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	a = []
	for i in range(n):
		a.append([i for i in input()])
	c = a[-1].count('D')
	for i in range(n):
		if a[i][-1] == 'R':
			c += 1
	print(c)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	out = 0
	for r in range(n):
		temp = input()
		if r != n - 1:
			if temp[-1] == 'R':
				out += 1
		if r == n - 1:
			for j in range(len(temp) - 1):
				if temp[j] == 'D':
					out += 1
	print(out)


for t in range(int(input())):
	(x, y) = map(int, input().split())
	i = 0
	l = []
	c = 0
	for i in range(x):
		ll = input()
		l.append(ll)
		if ll[-1] == 'R':
			c += 1
	for i in ll:
		if i == 'D':
			c += 1
	if x == 1 and y == 1:
		print(0)
	else:
		print(c)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		s = str(input())
		grid.append(s)
	moves = 0
	for i in range(len(grid[n - 1]) - 1):
		if grid[n - 1][i] != 'R':
			moves += 1
	for i in range(n - 1):
		if grid[i][m - 1] != 'D':
			moves += 1
	print(moves)
	t -= 1


t = int(input())
a = []
for _ in range(t):
	c = 0
	(x, y) = map(int, input().split())
	for i in range(x):
		a.append(input())
	for i in range(x - 1):
		if a[i][y - 1] == 'R':
			c += 1
	c += a[x - 1].count('D')
	print(c)
	a.clear()


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		r = input()
		grid.append(r)
	count = 0
	for j in range(n):
		for z in range(m):
			if z == m - 1:
				if grid[j][z] == 'R':
					count = count + 1
			elif j == n - 1:
				if grid[j][z] == 'D':
					count = count + 1
	print(count)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	for i in range(a - 1):
		s = input()
		if s[-1] != 'D':
			ans += 1
	s = input()
	for i in range(b - 1):
		if s[i] != 'R':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input().strip())
	ans = 0
	for i in range(n - 1):
		if l[i][-1] == 'R':
			ans += 1
	for i in l[-1]:
		if i == 'D':
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input())
	ct = 0
	for i in range(m - 1):
		if l[n - 1][i] != 'R':
			ct += 1
	for i in range(n - 1):
		if l[i][m - 1] != 'D':
			ct += 1
	print(ct)


t = int(input())
for _ in range(t):
	(n, m) = [int(i) for i in input().strip().split()]
	mat = []
	Rs_in_last_column = 0
	for row in range(n):
		mat.append(input())
		if mat[row][m - 1] == 'R':
			Rs_in_last_column += 1
	Ds_in_last_row = 0
	for col in range(m):
		if mat[n - 1][col] == 'D':
			Ds_in_last_row += 1
	print(Rs_in_last_column + Ds_in_last_row)


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for _ in range(n):
		s = input()
		if _ < n - 1:
			ans += int(s[m - 1] == 'R')
		else:
			for x in range(0, m - 1):
				ans += int(s[x] == 'D')
	print(ans)


import sys
import math
import heapq
import collections
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')

def printspace(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer(' ')

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

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

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, m) = inputnums()
	a = inputmatrixchar(n)
	ans = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			ans += 1
	for i in range(m):
		if a[n - 1][i] == 'D':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	count = 0
	for i in range(n):
		x = str(input())
		if i != n - 1:
			if x[-1] != 'D':
				count += 1
		else:
			for i in x[:m - 1]:
				if i != 'R':
					count += 1
	print(count)


for t in range(int(input())):
	(n, m) = list(map(int, input().split()))
	change = 0
	s = None
	for i in range(n - 1):
		s = input()
		if s[-1] == 'R':
			change = change + 1
	s = input()
	for i in range(m - 1):
		if s[i] == 'D':
			change = change + 1
	print(change)


def check_falling(lastCol, lastRow):
	ans = 0
	ans += lastCol.count('R')
	ans += lastRow.count('D')
	return ans
t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		arr.append(input())
	lastRow = arr[-1]
	cols = list(zip(*arr))
	lastCol = cols[-1]
	print(check_falling(lastCol, lastRow))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	cnt = 0
	for i in range(n - 1):
		lo = [n for n in input().split()]
		if lo[0][-1] == 'R':
			cnt += 1
	lol = input()
	for i in lol:
		if i == 'D':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	belt = []
	changesInLastColoumn = 0
	for i in range(n):
		a = list(input())
		if a[-1] == 'R':
			changesInLastColoumn += 1
		belt.append(a)
	lastRow = belt[-1]
	changesInLastRow = lastRow.count('D')
	print(changesInLastColoumn + changesInLastRow)


a = int(input())
b = 0
out = []
while b < a:
	(n, m) = [int(n) for n in input().split()]
	count = 0
	op = 0
	while op < n:
		r = input()
		row = list(r)
		if row[-1] == 'R':
			count += 1
		if op == n - 1:
			for r in row:
				if r == 'D':
					count += 1
		op += 1
	out.append(count)
	b += 1
print(*out, sep='\n')


def check(l):
	count = 0
	if len(l) > 1:
		for s in l[:-1]:
			if s[-1] != 'D':
				count += 1
	for j in l[-1][:-1]:
		if j != 'R':
			count += 1
	print(count)
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split(' '))
	l = []
	for j in range(n):
		l.append(input())
	check(l)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	data = []
	for i in range(n):
		data.append(input())
	answer = 0
	for i in range(m):
		if data[n - 1][i] == 'D':
			answer += 1
	for i in range(n):
		if data[i][m - 1] == 'R':
			answer += 1
	print(answer)


t = int(input())
for h in range(t):
	lis = list(map(int, input().split()))
	n = lis[0]
	m = lis[1]
	a = 0
	for h in range(n):
		li = list(input())
		if h < n - 1:
			if li[-1] == 'R':
				a += 1
	for i in li:
		if i == 'D':
			a += 1
	print(a)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [['0'] * m] * n
	for z in range(n):
		a[z] = list(input())
	ans = 0
	for z in range(n - 1, -1, -1):
		if z == n - 1:
			for x in range(0, m - 1):
				if a[z][x] == 'D':
					ans += 1
		elif a[z][m - 1] == 'R':
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	grid = []
	min = 0
	for i in range(n):
		grid.append(input())
	for i in range(n):
		if grid[i][m - 1] == 'R':
			min += 1
		if i == n - 1:
			min += grid[i].count('D')
	print(min)


def solve(mat, n, m):
	cnt = 0
	if n == 1:
		for i in range(m):
			if mat[0][i] == 'D':
				cnt += 1
		print(cnt)
		return
	for i in range(0, m):
		if mat[-1][i] == 'D':
			cnt += 1
	for i in range(0, n):
		if mat[i][-1] == 'R':
			cnt += 1
	print(cnt)
t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	mat = []
	for i in range(n):
		mat.append(list(input()))
	ans = []
	solve(mat, n, m)


for _ in range(int(input())):
	(h, l) = map(int, input().split())
	ans = 0
	for i in range(1, h + 1):
		s = input()
		if i == h:
			for j in s:
				if j == 'R' or j == 'C':
					continue
				ans += 1
		elif s[l - 1] == 'R':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ct = 0
	for i in range(n - 1):
		a = input()
		if a[-1] != 'D':
			ct += 1
	a = input()
	for i in range(m - 1):
		if a[i] != 'R':
			ct += 1
	print(ct)


import sys
for bruh in range(0, int(sys.stdin.readline())):
	nm = list(map(int, sys.stdin.readline().split()))
	lcol = [0] * (nm[0] - 1)
	for i in range(0, nm[0] - 1):
		lcol[i] = sys.stdin.readline()[nm[1] - 1]
	lrow = list(sys.stdin.readline()[:nm[1] - 1])
	sw = lcol.count('R') + lrow.count('D')
	sys.stdout.write(str(sw) + '\n')


__author__ = 'Jethiyaaa'

def solve():
	(n, m) = map(int, input().split())
	conveyer = []
	for _ in range(n):
		conveyer.append(list(input()))
	counter = 0
	for i in range(n - 1):
		if conveyer[i][m - 1] != 'D':
			counter += 1
	for j in range(m - 1):
		if conveyer[n - 1][j] != 'R':
			counter += 1
	print(counter)
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	count = 0
	for i in range(n):
		x = input()
		if x[-1] == 'R':
			count += 1
		elif i == n - 1:
			count += m - x.count('R') - 1
	print(count)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n - 1):
		ans += input()[-1] == 'R'
	ans += input().count('D')
	print(ans)


for _ in range(int(input())):
	(n, m) = [int(j) for j in input().split()]
	w = []
	count = 0
	for i in range(n):
		s = input()
		w.append(s)
	for i in range(n - 1):
		if w[i][m - 1] == 'R':
			count += 1
	for i in range(m - 1):
		if w[n - 1][i] == 'D':
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = [input() for i in range(n)]
	count = 0
	for i in range(n - 1):
		if matrix[i][m - 1] != 'D':
			count += 1
	for j in range(m - 1):
		if matrix[n - 1][j] != 'R':
			count += 1
	print(count)


while True:
	try:
		t = eval(input())
		for i in range(t):
			(n, m) = map(int, input().split())
			list0 = []
			cnt = 0
			for j in range(n):
				list0.append(input())
				if list0[j][m - 1] == 'R':
					cnt += 1
				if j == n - 1:
					for k in range(m):
						if list0[j][k] == 'D':
							cnt += 1
			print(cnt)
	except:
		break


import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
for _ in range(r()):
	(n, m) = rm()
	a = []
	for i in range(n):
		a.append(list(input()))
	res = 0
	for i in range(n):
		for j in range(m):
			if i == n - 1 and j == m - 1:
				continue
			if i == 0:
				if j == 0:
					if a[i][j] == 'L' or a[i][j] == 'U':
						res += 1
						continue
				elif j == m - 1:
					if a[i][j] == 'R' or a[i][j] == 'U':
						res += 1
						continue
				elif a[i][j] == 'U':
					res += 1
					continue
			if i == n - 1:
				if j == 0:
					if a[i][j] == 'L' or a[i][j] == 'D':
						res += 1
						continue
				elif a[i][j] == 'D':
					res += 1
					continue
			if j == 0:
				if a[i][j] == 'L':
					res += 1
					continue
			if j == m - 1:
				if a[i][j] == 'R':
					res += 1
	print(res)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n - 1):
		arr = list(input())
		if arr[-1] == 'R':
			ans += 1
	arr = list(input())
	for i in range(m):
		if arr[i] == 'D':
			ans += 1
	print(ans)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		a = input()
		matrix.append(a)
	count = 0
	for num in range(n - 1):
		if matrix[num][m - 1] == 'R':
			count += 1
	for ber in range(m - 1):
		if matrix[n - 1][ber] == 'D':
			count += 1
	print(count)


def main():
	(n, m) = map(int, input().split())
	c = 0
	for i in range(n - 1):
		s = str(input())
		if s[m - 1] == 'R':
			c += 1
	s = str(input())
	c += s.count('D')
	return c
for _ in range(int(input())):
	print(main())


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().strip().split()))
	list1 = []
	for _ in range(n):
		temp = input().strip()
		list1.append(temp)
	change = 0
	for x in range(m):
		if list1[n - 1][x] == 'D':
			change += 1
	for x in range(n):
		if list1[x][m - 1] == 'R':
			change += 1
	print(change)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	arr = [['' for i in range(m)] for _i in range(n)]
	for i in range(n):
		s = input()
		arr[i] = list(s)
	dp = [[False for i in range(m)] for _i in range(n)]
	dp[n - 1][m - 1] = True
	br = False
	ans = 0
	while True:
		br = False
		(a, b) = (n, m)
		for i in range(n - 1, -1, -1):
			if br:
				break
			for j in range(m - 1, -1, -1):
				if dp[i][j] == False:
					if i + 1 < n and dp[i + 1][j] == True:
						arr[i][j] = 'D'
					elif j + 1 < m and dp[i][j + 1] == True:
						arr[i][j] = 'R'
					ans += 1
					br = True
					break
				else:
					if i - 1 >= 0 and arr[i - 1][j] == 'D':
						dp[i - 1][j] = True
					if j - 1 >= 0 and arr[i][j - 1] == 'R':
						dp[i][j - 1] = True
		if not br:
			break
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for ii in range(t):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append([i for i in input() if i != '\n'])
	count = 0
	for i in range(n):
		if mat[i][-1] == 'R':
			count += 1
	for i in range(m):
		if mat[-1][i] == 'D':
			count += 1
	print(count)


def lug(n, m):
	if (n, m) == (1, 1):
		p = input()
		if p == 'C':
			return 0
		else:
			return 1
	elif n == 1:
		p = input()
		return m - 1 - p.count('R')
	elif m == 1:
		c = 0
		for i in range(n):
			p = input()
			if p == 'R':
				c += 1
		return c
	else:
		w = ''
		c = 0
		for i in range(n):
			p = input()
			w = p
			if p[-1] == 'R':
				c += 1
		c += w.count('D')
		return c
t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	print(lug(n, m))


for s in range(int(input())):
	(r, c) = map(int, input().split())
	(a, b) = ([], [])
	for i in range(r):
		st = input()
		a = []
		for i in st:
			a.append(i)
		b.append(a)
	add = 0
	for i in range(c):
		if b[r - 1][i] == 'D':
			add += 1
	for i in range(r):
		if b[i][c - 1] == 'R':
			add += 1
	print(add)


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split(' ')]
	mat = []
	for j in range(n):
		mat.append(input())
	if n == 1 and m == 1:
		print(0)
	elif n == 1:
		count = len([x for x in mat[0] if x == 'D'])
		print(count)
	elif m == 1:
		count = 0
		for m in mat:
			if m[0] == 'R':
				count += 1
		print(count)
	else:
		count = 0
		for m in mat:
			if m[-1] == 'R':
				count += 1
		count += len([x for x in mat[-1] if x == 'D'])
		print(count)


for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	k = 0
	for i in range(n):
		s = str(input())
		if s[-1] == 'R':
			k += 1
		if i == n - 1:
			k += s.count('D')
	print(k)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(n, m) = map(int, input().split())
	bb = [list(input()) for _ in range(n)]
	res = bb[n - 1][:m - 1].count('D') + [x for y in range(n - 1) for x in bb[y][m - 1]].count('R')
	print(res)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
input = iter(sys.stdin.read().splitlines()).__next__
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	last_column = []
	for _ in range(n - 1):
		last_column.append(input()[-1])
	last_row = input()
	print(last_column.count('R') + last_row.count('D'))


import sys

def main():
	input = sys.stdin.readline
	print = sys.stdout.write
	t = int(input())
	for i1 in [0] * t:
		(n, m) = map(int, input().split())
		grid = []
		for i in range(n):
			grid.append(input().strip())
		counter = 0
		for i in range(n - 1):
			if grid[i][-1] != 'D':
				counter += 1
		for j in range(m - 1):
			if grid[n - 1][j] != 'R':
				counter += 1
		print(str(counter))
		print('\n')
main()


def ans(arr, n, o):
	w = arr[-1]
	ans = 0
	for i in range(o):
		if w[i] == 'D':
			ans += 1
	c = []
	for i in range(n):
		c.append(arr[i][-1])
	for j in range(n):
		if c[j] == 'R':
			ans += 1
	return ans
m = int(input())
for i in range(m):
	b = input().split()
	n = int(b[0])
	o = int(b[1])
	arr = []
	for i in range(n):
		s = input()
		arr.append(s)
	print(ans(arr, n, o))


t = int(input())
for i in range(t):
	(n, m) = list(map(lambda x: int(x), input().split()))
	ans = 0
	for i in range(1, n):
		line = input()
		if line[-1] == 'R':
			ans += 1
	line = input()
	for val in line:
		if val == 'D':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = []
	for _ in range(n):
		matrix.extend(list(map(str, input().split())))
	lastrow = matrix[-1].count('D')
	lastcolum = 0
	for i in range(len(matrix)):
		if matrix[i][-1] == 'R':
			lastcolum += 1
	print(lastcolum + lastrow)


def solve(matrix, n, m):
	count = 0
	for i in range(m - 1):
		if matrix[n - 1][i] == 'D':
			count += 1
	for i in range(n - 1):
		if matrix[i][m - 1] == 'R':
			count += 1
	return count
t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	matrix = []
	for i in range(n):
		s = input()
		matrix.append(list(s))
	print(solve(matrix, n, m))


def find_cells_to_fix_n(conveyor):
	right_border_n = sum((row[-1] == 'R' for row in conveyor))
	bottom_border_n = conveyor[-1].count('D')
	return right_border_n + bottom_border_n

def main():
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split())
		conveyor = tuple((input() for i in range(n)))
		cells_to_fix_n = find_cells_to_fix_n(conveyor)
		print(cells_to_fix_n)
main()


def solve(R, C, grid):
	min_moves = 0
	for row in grid:
		if row[-1] == 'R':
			row[-1] == 'D'
			min_moves += 1
	for (i, c) in enumerate(grid[-1][:-1]):
		if c == 'D':
			grid[-1][i] = 'R'
			min_moves += 1
	return min_moves

def main():
	T = int(input())
	for _ in range(T):
		(R, C) = list(map(int, input().split()))
		grid = []
		for _ in range(R):
			grid.append(list(input().rstrip()))
		ans = solve(R, C, grid)
		print(ans)
main()


import math as mt

def tran(gr):
	last = 0
	for i in gr:
		if i[-1] == 'R':
			last += 1
	low = gr[-1].count('D')
	return low + last
t = int(input())
ans = []
for i in range(t):
	nk = list(map(int, input().rstrip().split()))
	gr = []
	for i in range(nk[0]):
		s = input()
		gr.append(s)
	r = tran(gr)
	ans.append(r)
for i in ans:
	print(i)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect
from collections import deque, defaultdict, OrderedDict
import collections
N = 100009
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def factorial(p):
	fact[0] = 1
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % p

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	p = 1000000007
	InverseofNumber(p)
	InverseofFactorial(p)
	factorial(p)
	for _ in range(ri()):
		(n, m) = ria()
		f = ''
		g = ''
		for i in range(n - 1):
			s = rs()
			f += s[m - 1]
		s = rs()
		g = s[:m - 1]
		c = 0
		for i in f:
			if i != 'D':
				c += 1
		for i in g:
			if i != 'R':
				c += 1
		print(c)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


def main(case):
	(n, m) = map(int, input().split())
	sm = 0
	for i in range(n):
		line = input()
		if i == n - 1:
			for i in line:
				if i == 'D':
					sm += 1
		elif line[-1] == 'R':
			sm += 1
	print(sm)
t = int(input())
for i in range(t):
	main(i + 1)


t = int(input())
for ii in range(t):
	(n, m) = map(int, input().split())
	c = 0
	if n == 1 and m == 1:
		x = input()
		print(0)
	else:
		for i in range(0, n):
			x = input()
			if i == n - 1:
				if len(x) > 1:
					for j in range(0, len(x) - 1):
						if x[j] == 'D':
							c = c + 1
			elif x[len(x) - 1] == 'R':
				c = c + 1
		print(c)


t = input()
for i in range(int(t)):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	grid = []
	min = 0
	for j in range(n):
		grid.append(list(input()))
	for x in range(m - 1):
		if grid[n - 1][x] == 'D':
			grid[n - 1][x] = 'R'
			min += 1
	for y in range(n - 1):
		if grid[y][m - 1] == 'R':
			grid[y][m - 1] = 'D'
			min += 1
	print(min)


test_cases = int(input())
for test_case in range(test_cases):
	(n, m) = list(map(int, input().split()))
	grid = []
	for i in range(n):
		x = input()
		grid.append(x)
	ans = 0
	for i in range(n):
		if i != n - 1:
			if grid[i][-1] == 'R':
				ans += 1
		else:
			for j in range(m - 1):
				if grid[i][j] == 'D':
					ans += 1
	print(ans)


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	m = int(l[1])
	l = []
	for i in range(n):
		s = input()
		l.append(s)
	count = 0
	for i in range(n - 1):
		if l[i][-1] != 'D':
			count += 1
	for i in range(m - 1):
		if l[n - 1][i] != 'R':
			count += 1
	print(count)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().strip().split(' '))
	grid = []
	for i in range(n):
		arr = input().strip()
		grid.append(arr)
	dp = [[0 for i in range(m)] for j in range(n)]
	cnt = 0
	for i in range(n):
		if grid[i][m - 1] == 'R':
			cnt += 1
	for i in range(m):
		if grid[n - 1][i] == 'D':
			cnt += 1
	print(cnt)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	s = [input() for i in range(n)]
	a = [i[-1] for i in s]
	b = s[-1]
	cnt = 0
	for i in b:
		if i == 'D':
			cnt += 1
	for i in a:
		if i == 'R':
			cnt += 1
	print(cnt)


t = int(input())
for j in range(t):
	(n, m) = map(int, input().split())
	ct = 0
	for i in range(n - 1):
		s = input()
		if s[-1] == 'R':
			ct += 1
	s = input()
	for i in s:
		if i == 'D':
			ct += 1
	print(ct)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = [input() for i in range(n)]
	cnt = 0
	for i in range(n - 1):
		cnt += matrix[i][m - 1] == 'R'
	for i in range(m - 1):
		cnt += matrix[n - 1][i] == 'D'
	print(cnt)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		st = input()
		if i == n - 1:
			for j in range(m - 1):
				if st[j] == 'D':
					ans += 1
		elif st[-1] == 'R':
			ans += 1
	print(ans)


a = int(input())
for i in range(0, a):
	(n, m) = map(int, input().split())
	c = 0
	for i in range(0, n):
		l = input()
		if l[m - 1] == 'R':
			c += 1
	c += l.count('D')
	print(c)


import sys
input = sys.stdin.readline
cases = int(input()[:-1])
for x in range(cases):
	count = 0
	for y in range(int(input()[:-1].split(' ')[0]) - 1):
		if input()[-2:-1] == 'R':
			count += 1
	last = sorted(list(input()[:-2]))
	if 'R' not in last:
		count += len(last)
	else:
		count += last.index('R')
	print(count)


import pdb
ncase = int(input())
while ncase:
	ncase -= 1
	(n, m) = map(int, input().split())
	g = []
	for i in range(n):
		g.append(input())
	ans = 0
	for i in range(m):
		ans += g[-1][i] == 'D'
	for i in range(n):
		ans += g[i][-1] == 'R'
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().strip().split())
	lis = []
	for x in range(n):
		arr = input()
		lis.append(arr)
	count = 0
	for y in range(n):
		if lis[y][-1] == 'R':
			count += 1
	count += list(lis[n - 1]).count('D')
	print(count)


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		s = input().strip('\n')
		mat.append(s)
	count = 0
	for i in range(n):
		if i == n - 1:
			continue
		if mat[i][m - 1] == 'R':
			count += 1
	for i in range(m):
		if i == m - 1:
			continue
		if mat[n - 1][i] == 'D':
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		li = list(input())
		a.append(li)
	count = 0
	last_row = a[n - 1]
	for i in range(m):
		if last_row[i] == 'D':
			count += 1
			a[n - 1][i] = 'R'
	for i in range(n):
		if a[i][-1] == 'R':
			count += 1
			a[i][-1] = 'D'
	print(count)


import sys
import heapq
pprint = lambda s: print(' '.join(map(lambda x: str(x), s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
for i in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		lol = input()
		a = lol[-1]
		if a == 'R':
			ans += 1
		if i == n - 1:
			ans += lol.count('D')
	print(ans)


def solve():
	T = int(input())
	for i in range(T):
		(n, m) = map(int, input().split())
		a = []
		for i in range(n):
			s = input()
			s = list(s)
			a.append(s)
		ans = 0
		for i in a:
			if i[m - 1] == 'R':
				ans += 1
		for i in a[n - 1]:
			if i == 'D':
				ans += 1
		print(ans)
solve()


def verify(grid):
	(n, m) = (len(grid), len(grid[0]))
	uncorrect = 0
	for sum in range(n + m - 3, -1, -1):
		for k in range(0, n):
			if 0 <= k <= n - 1 and 0 <= sum - k <= m - 1:
				i = k
				j = sum - k
				if i == n - 1:
					if grid[i][j] != 'R':
						uncorrect += 1
					grid[i][j] = 'C'
				elif j == m - 1:
					if grid[i][j] == 'R':
						uncorrect += 1
					grid[i][j] = 'C'
				else:
					if grid[i + 1][j] == 'C' or grid[i][j + 1] == 'C':
						pass
					else:
						uncorrect += 1
					grid[i][j] = 'C'
	return uncorrect
t = int(input())
results = []
for num in range(t):
	(n, m) = [int(x) for x in input().split()]
	grid = [list(input()) for i in range(n)]
	results.append(str(verify(grid)))
for result in results:
	print(result)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	b = []
	for j in range(n):
		s = input()
		c = []
		for p in s:
			c.append(p)
		b.append(c)
	s1 = 0
	for j in range(n - 1):
		if b[j][m - 1] == 'R':
			s1 += 1
	for j in range(m - 1):
		if b[n - 1][j] == 'D':
			s1 += 1
	print(s1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = [''] * n
	for i in range(n):
		grid[i] = list(input())
	c = 0
	for i in range(m):
		if grid[n - 1][i] == 'D':
			c += 1
	for i in range(n):
		if grid[i][m - 1] == 'R':
			c += 1
	print(c)


from sys import stdin
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	a = [None] * n
	for i in range(n):
		a[i] = list(input())
	for i in range(n):
		if a[i][m - 1] == 'R':
			c += 1
	for j in range(m):
		if a[n - 1][j] == 'D':
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	c = 0
	for _ in range(n):
		s = input()
		if s[-1] == 'R':
			c += 1
	print(s.count('D') + c)


n = int(input())
for _ in range(n):
	(row, col) = map(int, input().split())
	arr = []
	for _ in range(row):
		temp = input()
		ar = []
		for i in range(col):
			ar.append(temp[i])
		arr.append(ar)
	count = 0
	for i in range(row):
		if arr[i][col - 1] == 'R':
			count += 1
	for i in range(col):
		if arr[row - 1][i] == 'D':
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	lst = []
	for i in range(n):
		lst.append(input())
	cnt = 0
	for i in range(n):
		if lst[i][m - 1] == 'R':
			cnt += 1
	for i in range(m):
		if lst[n - 1][i] == 'D':
			cnt += 1
	print(cnt)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	res = 0
	for i in range(n - 1):
		row = input().strip()
		if row[-1] == 'R':
			res += 1
	row = input().strip()
	for c in row[:m - 1]:
		if c == 'D':
			res += 1
	print(res)


testcases = int(input())
for i in range(testcases):
	(n, m) = map(int, input().split())
	change = 0
	for j in range(n):
		row = input()
		if j == n - 1:
			for ele in row:
				if ele == 'D':
					change += 1
		elif row[-1] == 'R':
			change += 1
	print(change)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	m = []
	ans = 0
	for j in range(n):
		s = input()
		if s[-1] == 'R' and j != n - 1:
			ans += 1
		if j == n - 1:
			ans += k - s.count('R') - 1
	print(ans)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	matrix = []
	for i in range(m):
		col = input()
		matrix.append(col)
	count = 0
	for char in matrix[m - 1]:
		if char == 'D':
			count += 1
	for i in range(m):
		if matrix[i][n - 1] == 'R':
			count += 1
	print(count)


for i in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	dp = [0] * n
	for i in range(n):
		dp[i] = [i for i in input()]
	ans = 0
	for i in range(m - 1):
		if dp[n - 1][i] != 'R':
			ans += 1
	for i in range(n - 1):
		if dp[i][m - 1] != 'D':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	belts = [list(input()) for i in range(n)]
	changes = belts[n - 1].count('D')
	for i in range(n):
		if belts[i][m - 1] == 'R':
			changes += 1
	print(changes)


t = int(input())
for u in range(t):
	count = 0
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append([])
		y = input()
		for j in range(m):
			a[i].append(y[j])
	i = 0
	j = 0
	for i in range(n - 1):
		if a[i][m - 1] == 'R':
			a[i][m - 1] = 'D'
			count += 1
	for j in range(m - 1):
		if a[n - 1][j] == 'D':
			a[n - 1][j] = 'R'
			count += 1
	print(count)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	a = []
	count = 0
	for i in range(n):
		x = list(input())
		a.append(x)
	for i in range(n):
		if a[i][m - 1] == 'R':
			count += 1
	for i in range(m):
		if a[n - 1][i] == 'D':
			count += 1
	print(count)
	t -= 1


from collections import Counter
from math import ceil, gcd, log

def ans(n, m):
	down = 0
	right = 0
	for i in range(n):
		k = input()
		if n == 1 and m == 1:
			print(0)
			return
		if i == n - 1:
			for jj in k[:len(k) - 1]:
				if jj != 'R':
					right += 1
		if k[-1] != 'D':
			down += 1
	print(right + down - 1)
	return
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans(n, m)


def f(mat):
	c = 0
	for i in range(len(mat)):
		for j in range(len(mat[0])):
			if mat[i][j] == 'R' and j + 1 >= m:
				mat[i][j] = 'D'
				c += 1
			elif mat[i][j] == 'D' and i + 1 >= n:
				mat[i][j] = 'R'
				c += 1
	return c
for _ in range(int(input())):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	mat = []
	for i in range(n):
		x = list(input())
		mat.append(x)
	print(f(mat))


t = int(input())
while t != 0:
	(n, m) = map(int, input().split())
	list1 = []
	for i in range(n):
		temp = input()
		list1.append(temp)
	count = 0
	for i in range(m):
		if list1[-1][i] == 'D':
			count += 1
	for i in range(n):
		if list1[i][-1] == 'R':
			count += 1
	print(count)
	t -= 1


for _ in range(int(input())):
	(rows, _) = map(int, input().split())
	r_in_last_col = 0
	ran = False
	for _ in range(rows):
		ran = True
		columns = input()
		if columns[-1] == 'R':
			r_in_last_col += 1
	if ran:
		ans = r_in_last_col + columns.count('D')
	else:
		ans = 0
	print(ans)


import math
import sys
from collections import Counter
from math import factorial as fact
from collections import defaultdict

def inpint():
	return int(input())

def inpstr():
	return str(input())

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

def inptup():
	return map(int, input().strip().split())
for _ in range(inpint()):
	(n, m) = inptup()
	a = []
	ans = 0
	for i in range(n):
		a.append(inpstr())
	for i in range(0, n - 1):
		if a[i][-1] == 'R':
			ans += 1
	for i in range(0, m - 1):
		if a[-1][i] == 'D':
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = []
	for j in range(n):
		a.append(input())
	c = 0
	x = a[n - 1]
	n1 = len(x)
	for j in range(n1 - 1):
		if x[j] == 'D':
			c += 1
	y = ''
	for j in range(n):
		y = y + a[j][m - 1]
	n2 = len(y)
	for j in range(n2 - 1):
		if y[j] == 'R':
			c += 1
	print(c)


import bisect
import sys
import math
input = sys.stdin.readline
import functools
from collections import defaultdict

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve(case):
	[n, m] = inlt()
	s = []
	res = 0
	for i in range(n):
		s.append(input().rstrip())
		if i < n - 1 and s[-1][-1] != 'D':
			res += 1
	for i in range(m - 1):
		if s[-1][i] != 'R':
			res += 1
	return res
if len(sys.argv) > 1 and sys.argv[1].startswith('input'):
	f = open('./' + sys.argv[1], 'r')
	input = f.readline
T = inp()
for i in range(T):
	res = solve(i + 1)
	print(str(res))


for ii in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for jj in range(n):
		x = input()
		if x[-1] == 'R':
			ans += 1
	print(ans + x.count('D'))


def end(i, j):
	cur = belt[i][j]
	if cur == 'C':
		return cur
	while cur != 'C':
		if cur == 'R':
			j += 1
			if j < m:
				cur = belt[i][j]
			else:
				return (i, j - 1)
		elif cur == 'D':
			i += 1
			if i < n:
				cur = belt[i][j]
			else:
				return (i - 1, j)
	return cur
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	belt = []
	for _ in range(n):
		row = input()
		row = list(row)
		belt.append(row)
	changes = 0
	for i in range(n):
		for j in range(m):
			dest = end(i, j)
			if dest == 'C':
				continue
			(r, c) = dest
			if belt[r][c] == 'D':
				belt[r][c] = 'R'
				changes += 1
			elif belt[r][c] == 'R':
				belt[r][c] = 'D'
				changes += 1
	print(changes)


def solve():
	(n, m) = map(int, input().split())
	e = 0
	l = []
	for i in range(n):
		l.append(input())
	e += l[-1].count('D')
	for j in range(n - 1):
		if l[j][-1] == 'R':
			e += 1
	print(e)
for _ in range(int(input())):
	solve()


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
krish = 100
t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	l = []
	for i in range(n):
		s = input()
		tmp = []
		for i in s:
			tmp.append(i)
		l.append(tmp)
	cnt = 0
	for i in range(n - 1):
		if l[i][m - 1] == 'R':
			cnt += 1
	for i in range(m - 1):
		if l[n - 1][i] == 'D':
			cnt += 1
	print(cnt)


test = int(input())
for i in range(test):
	(m, n) = [int(x) for x in input().split(' ')]
	a = []
	count = 0
	for i in range(m):
		temp = input()
		a.append(temp)
	for i in range(m):
		if a[i][n - 1] == 'R':
			count += 1
	for i in range(n - 1):
		if a[m - 1][i] == 'D':
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(h, w) = map(int, input().split())
	s = [input() for i in range(h)]
	edgeRow = list(s[-1])
	edgeColumn = [s[i][-1] for i in range(h)]
	ans = 0
	for i in range(w):
		if edgeRow[i] == 'D':
			ans += 1
	for i in range(h):
		if edgeColumn[i] == 'R':
			ans += 1
	print(ans)


n = int(input())
for _ in range(n):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	q = list()
	for i in range(n):
		q.append(list(input()))
	c = 0
	for j in range(n - 1):
		if q[j][m - 1] == 'R':
			c = c + 1
	for k in range(m - 1):
		if q[n - 1][k] == 'D':
			c = c + 1
	print(c)


from sys import stdin
ip = stdin.readline
t = int(ip())
while t:
	t -= 1
	(n, m) = map(int, ip().split())
	a = []
	for _ in range(n):
		a.append(list(ip()))
	ans = 0
	for i in range(n - 1):
		if not a[i][m - 1] == 'D':
			ans += 1
	for i in range(m - 1):
		if not a[n - 1][i] == 'R':
			ans += 1
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	b = []
	c = 0
	for i in range(n):
		temp = list(map(str, input()))
		if temp[m - 1] == 'R':
			c += 1
		if i == n - 1:
			k = temp.count('D')
	print(k + c)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for ii in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [list(input()) for i in range(n)]
	ans = 0
	for i in range(n):
		if arr[i][m - 1] == 'R':
			ans += 1
	for j in range(m):
		if arr[n - 1][j] == 'D':
			ans += 1
	print(ans)


for i in range(int(input())):
	arr1 = [int(_) for _ in input().split()]
	f1 = []
	l = []
	for j in range(arr1[0]):
		arr2 = [*input()]
		f1.append(arr2[-1])
		l.append(arr2)
	f2 = l[-1]
	c1 = f1.count('R')
	c2 = f2.count('D')
	print(c1 + c2)


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	mat = []
	for _ in range(r):
		mat.append(input())
	cnt = 0
	for j in range(c):
		if mat[r - 1][j] == 'D':
			cnt += 1
	for i in range(r):
		if mat[i][c - 1] == 'R':
			cnt += 1
	print(cnt)


number_of_tests = int(input())
answer = []
for case in range(number_of_tests):
	tempo = 0
	(n, m) = input().split(' ')
	(n, m) = (int(n), int(m))
	for i in range(n):
		line = input()
		if i == n - 1:
			for j in range(m):
				if line[j] == 'D':
					tempo += 1
		else:
			for j in range(m):
				if j == m - 1 and line[j] == 'R':
					tempo += 1
	answer.append(str(tempo))
print('\n'.join(answer))


t = int(input())
while t:
	t -= 1
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	c = 0
	for i in range(0, a - 1):
		x = input()
		if x[-1] != 'D':
			c += 1
	x = input()
	for i in range(0, len(x) - 1):
		if x[i] != 'R':
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	l1 = [int(x) for x in input().split()]
	rows = l1[0]
	columns = l1[1]
	ans = 0
	for i in range(rows):
		t = list(input())
		if t[-1] == 'R':
			ans += 1
		if i == rows - 1:
			ans += t.count('D')
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = []
	a = 0
	for i in range(n):
		t = input()
		A.append(t)
		if t[-1] == 'R':
			a += 1
	for j in range(m):
		if A[n - 1][j] == 'D':
			a += 1
	print(a)


t = int(input())
for __ in range(t):
	(n, m) = list(map(int, input().split()))
	a = list()
	for _ in range(n):
		a.append(input())
	c = 0
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			o = a[i - 1][j - 1]
			if 0 == 'C':
				continue
			if i == n and o == 'D':
				c += 1
			if j == m and o == 'R':
				c += 1
	print(c)


def solve(n, m, C):
	count = 0
	for c in range(m):
		if C[n - 1][c] == 'D':
			count += 1
	for r in range(n):
		if C[r][m - 1] == 'R':
			count += 1
	return count
cases = int(input())
for _ in range(cases):
	(n, m) = map(int, input().split())
	C = [[0] * m for _ in range(n)]
	for i in range(n):
		row = input()
		for (j, v) in enumerate(row):
			C[i][j] = v
	print(solve(n, m, C))


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	c = 0
	for i in range(n):
		row = input()
		if i == n - 1:
			c += row.count('D')
		if row[-1] == 'R':
			c += 1
	print(c)


from collections import Counter

def tc():
	(n, m) = map(int, input().split())
	grid = [input() for _ in range(n)]
	if n == 1 and m == 1:
		print('0')
		return
	ans = 0
	for ch in grid[-1][:-1]:
		if ch == 'D':
			ans += 1
	for row in grid[:-1]:
		if row[-1] == 'R':
			ans += 1
	print(ans)
T = int(input())
for _ in range(T):
	tc()


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : sys.stdin.readline().strip().split()
ri = lambda : int(sys.stdin.readline().strip())
rs = lambda : sys.stdin.readline().strip()
from collections import defaultdict as df
import random
from queue import PriorityQueue as pq
from math import ceil
t = ri()
for _ in range(t):
	(n, m) = RI()
	l = [[] for i in range(n)]
	for i in range(n):
		l[i] = rs()
	cnt = 0
	for i in range(0, n - 1):
		if l[i][m - 1] == 'R':
			cnt += 1
	for i in range(0, m - 1):
		if l[n - 1][i] == 'D':
			cnt += 1
	print(cnt)


from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	(n, m) = map(int, stdin.readline().split())
	mat = []
	for i in range(n):
		mat.append(list(stdin.readline().strip()))
	ans = 0
	for i in range(n):
		ans += mat[i][-1] == 'R'
	for j in range(m):
		ans += mat[-1][j] == 'D'
	print(ans)


from functools import reduce

def ip():
	return int(input())

def sip():
	return input()

def mip():
	return map(int, input().split())

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]
t = ip()
while t:
	t -= 1
	(n, m) = mip()
	arr = []
	for i in range(n):
		s = sip()
		lst = []
		for j in range(m):
			lst.append(s[j])
		arr.append(lst)
	val = 0
	if n == 1:
		for i in range(m - 1):
			if arr[0][i] == 'D':
				val += 1
	elif m == 1:
		for i in range(n - 1):
			if arr[i][0] == 'R':
				val += 1
	else:
		for i in range(m - 1):
			if arr[n - 1][i] == 'D':
				val += 1
		for i in range(n - 1):
			if arr[i][m - 1] == 'R':
				val += 1
	print(val)


for x in range(int(input())):
	c = 0
	l = []
	(a, b) = map(int, input().split())
	for _ in range(a):
		l.append(input())
	for i in l:
		if i[-1] == 'R':
			c += 1
	temp = l[-1]
	c += temp.count('D')
	print(c)


t = int(input())
for i in range(t):
	f = lambda : map(int, input().split(' '))
	(n, m) = f()
	l = []
	for i in range(n):
		a = input()
		l.append(a)
	c = 0
	for i in l:
		if i[-1] == 'R':
			c += 1
	for i in l[-1]:
		if i == 'D':
			c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	l = []
	for abc in range(n):
		l.append(input())
	count = 0
	for i in range(n - 1):
		if l[i][m - 1] == 'R':
			count += 1
	for j in range(m):
		if l[n - 1][j] == 'D':
			count += 1
	print(count)


def conveyor(arr, n, m):
	flip = 0
	for i in range(n - 1):
		if arr[i][m - 1] != 'D':
			flip += 1
	for j in range(m - 1):
		if arr[n - 1][j] != 'R':
			flip += 1
	return flip
n = int(input())
ans = []
for i in range(n):
	a = list(map(int, input().split()))
	rows = a[0]
	columns = a[1]
	inst = []
	for k in range(rows):
		inst.append(list(input()))
	ans.append(conveyor(inst, rows, columns))
for i in ans:
	print(i)


from collections import defaultdict
con = 10 ** 9 + 7
INF = float('inf')

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

class UnionFind:

	def __init__(self, n):
		self.par = [i for i in range(n + 1)]
		self.rank = [0] * (n + 1)
		self.size = [1] * (n + 1)

	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]

	def same_check(self, x, y):
		return self.find(x) == self.find(y)

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if self.rank[x] < self.rank[y]:
			if self.same_check(x, y) != True:
				self.size[y] += self.size[x]
				self.size[x] = 0
			self.par[x] = y
		else:
			if self.same_check(x, y) != True:
				self.size[x] += self.size[y]
				self.size[y] = 0
			self.par[y] = x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1

	def siz(self, x):
		x = self.find(x)
		return self.size[x]

def main():
	T = int(input())
	for _ in range(T):
		(N, M) = getlist()
		UF = UnionFind(N * M)
		S = []
		for i in range(N):
			s = input()
			S.append(s)
		for i in range(N):
			for j in range(M):
				if S[i][j] == 'R':
					if j < M - 1:
						UF.union(M * i + j, M * i + j + 1)
				elif S[i][j] == 'D':
					if i < N - 1:
						UF.union(M * i + j, M * (i + 1) + j)
		for i in range(N * M):
			UF.par[i] = UF.find(i)
		ans = 0
		for i in range(N * M):
			if UF.size[i] != 0:
				ans += 1
		print(ans - 1)
main()


t = int(input())
while t:
	(n, m) = map(int, input().split())
	s = [list(input()) for x in range(n)]
	ans = 0
	if n == 1 and m == 1:
		ans = 0
	elif n == 1:
		for x in range(m - 1):
			if s[0][x] != 'R':
				ans += 1
	elif m == 1:
		for x in range(n - 1):
			if s[x][0] != 'D':
				ans += 1
	else:
		for x in range(m - 1):
			if s[n - 1][x] != 'R':
				ans += 1
		for x in range(n - 1):
			if s[x][m - 1] != 'D':
				ans += 1
	print(ans)
	t -= 1


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(input())
	ans = 0
	cnt = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			cnt += 1
	for i in range(m):
		if a[n - 1][i] == 'D':
			ans += 1
	print(cnt + ans)


t = int(input())
while t > 0:
	sum = 0
	(a, b) = map(int, input().split())
	for i in range(0, a, 1):
		s = str(input())
		if i < a - 1:
			if s[b - 1] == 'R':
				sum += 1
		else:
			for j in range(0, b - 1, 1):
				if s[j] == 'D':
					sum += 1
	print(sum)
	t -= 1


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	g = []
	for i in range(n):
		s = str(input())
		g.append(s)
	c = 0
	for i in range(n - 1):
		if g[i][-1] == 'R':
			c += 1
	for i in g[-1]:
		if i == 'D':
			c += 1
	print(c)


t = int(input())
while t > 0:
	(n, m) = list(map(int, input().split()))
	if n == 1 and m == 1:
		c = input()
		print('0')
	elif n == 1:
		c = input()
		flag = 0
		for i in c:
			if i == 'D':
				flag += 1
		print(flag)
	elif m == 1:
		flag = 0
		for i in range(n):
			c = input()
			if c == 'R':
				flag += 1
		print(flag)
	else:
		flag = 0
		for i in range(n):
			c = input()
			if i == n - 1:
				for j in c:
					if j == 'D':
						flag += 1
			elif c[-1] == 'R':
				flag += 1
		print(flag)
	t -= 1


for t in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		row = input()
		grid.append(row)
	if n == 1 and m == 1:
		if grid[n - 1][m - 1] == 'C':
			print(0)
		else:
			print(1)
		continue
	ans = 0
	for i in range(n - 1):
		if grid[i][m - 1] == 'R':
			ans += 1
	for j in range(m - 1):
		if grid[n - 1][j] == 'D':
			ans += 1
	print(ans)


def main():
	(n, m) = map(int, input().split())
	c = 0
	for _ in range(n - 1):
		line = input()
		if line[m - 1] != 'D':
			c += 1
	line = input()
	for r in line:
		if r == 'C':
			pass
		elif r == 'D':
			c += 1
	print(c)
for _ in range(int(input())):
	main()


import sys
input = sys.stdin.readline
from collections import deque
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	field = []
	field.append('#' * (m + 2))
	for i in range(n):
		line = input().rstrip()
		field.append('#' + line + '#')
		if 'C' in line:
			sx = i
			sy = line.index('C')
	field.append('#' * (m + 2))
	visited = [[0] * (m + 2) for _ in range(n + 2)]
	ans = 0
	for i in range(n):
		for j in range(m):
			if visited[i + 1][j + 1]:
				continue
			x = i + 1
			y = j + 1
			seen = set()
			while True:
				visited[x][y] = 1
				if x == sx and y == sy:
					break
				if (x, y) in seen:
					ans += 1
				seen.add((x, y))
				if field[x][y] == '#':
					ans += 1
				elif field[x][y] == 'R':
					y += 1
				elif field[x][y] == 'L':
					y -= 1
				elif field[x][y] == 'D':
					x += 1
				elif field[x][y] == 'U':
					x -= 1
				if visited[x][y]:
					break
	print(ans)


fr = int(input())
kk = []
for i in range(fr):
	(n, m) = map(int, input().split())
	ans = 0
	for j in range(n):
		a = input()
		if 'C' not in a and a[-1] == 'R':
			ans += 1
		if 'C' in a:
			for k in a:
				if k == 'D':
					ans += 1
	kk.append(ans)
for i in kk:
	print(i)


def solve(arr, r, c):
	change = 0
	for i in range(r):
		if arr[i][-1] == 'R':
			change += 1
		elif i == r - 1:
			change += arr[i].count('D')
	print(change)
for _ in range(int(input())):
	(r, c) = list(map(int, input().split()))
	arr = []
	for i in range(r):
		s = str(input())
		arr.append(s)
	solve(arr, r, c)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdarr = lambda : map(int, stdstr().split())
mod = 1000000007
for _ in range(stdint()):
	(n, m) = stdarr()
	matrix = []
	for __ in range(n):
		row = input()
		matrix.append(row)
	res = 0
	for i in range(n - 1):
		if matrix[i][-1] == 'R':
			res += 1
	for i in matrix[-1]:
		if i == 'D':
			res += 1
	print(res)


import collections
from functools import lru_cache

def read():
	return input().strip()

def readInt():
	return int(input().strip())

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

def solve(R, C, grid):
	ans = 0
	for c in range(C - 1):
		if grid[R - 1][c] != 'R':
			ans += 1
	for r in range(R - 1):
		if grid[r][C - 1] != 'D':
			ans += 1
	return ans
t = readInt()
for i in range(t):
	(R, C) = readList()
	grid = []
	for _ in range(R):
		grid.append([ch for ch in read()])
	print(solve(R, C, grid))


from collections import Counter

def read_grid(n, m):
	c = []
	for _ in range(n):
		r = list(input())
		c.append(r)
	return c

def solve(c, n, m):
	most_right = Counter([c[i][m - 1] for i in range(n)])['R']
	most_down = Counter(c[n - 1])['D']
	return most_down + most_right
t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split(' ')]
	c = read_grid(n, m)
	print(solve(c, n, m))


import sys
input = sys.stdin.readline
from collections import Counter

def solve():
	(n, m) = map(int, input().split())
	ans = 0
	for _ in range(n - 1):
		t = input().strip()
		if t[-1] == 'R':
			ans += 1
	ans += Counter(input())['D']
	return ans

def main():
	t = int(input())
	ANS = [solve() for _ in range(t)]
	print('\n'.join(map(str, ANS)))
main()


import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
	(n, m) = [int(_) for _ in input().split()]
	M = []
	for i in range(n):
		row = input()[:-1]
		M.append(row)
	answer = 0
	for i in range(n):
		if M[i][-1] == 'R':
			answer += 1
	for i in range(len(M[0])):
		if M[-1][i] == 'D':
			answer += 1
	print(answer)


a = int(input())
for i in range(0, a):
	(n, m) = map(int, input().split())
	arr = []
	count = 0
	for i in range(n):
		arr.append(input())
	for i in range(0, len(arr) - 1):
		if arr[i][len(arr[0]) - 1] == 'R':
			count = count + 1
	for i in range(0, len(arr[0]) - 1):
		if arr[len(arr) - 1][i] == 'D':
			count = count + 1
	print(count)


for t in range(int(input())):
	(n, m) = [*map(int, input().split())]
	conv = []
	for i in range(n):
		conv.append(list(input()))
	res = 0
	for (r, l) in enumerate(conv, 0):
		for (c, e) in enumerate(l, 0):
			if e == 'D' and r == n - 1:
				res += 1
			if e == 'R' and c == m - 1:
				res += 1
	print(res)


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(n, m) = map(int, stdin.readline().split())
		grid = [stdin.readline() for i in range(n)]
		reachable = [[False for i in range(m + 1)] for j in range(n + 1)]
		move = 0
		for i in range(1, m + 1):
			if grid[n - 1][i - 1] == 'D':
				move += 1
			reachable[n][i] = True
		for i in range(1, n + 1):
			if grid[i - 1][m - 1] == 'R':
				move += 1
				reachable[i][m] = True
		stdout.write(str(move))
		stdout.write('\n')
	return
main()


import math
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		s = input()
		arr.append(list(s))
	x = arr[-1]
	ctr = 0
	for i in range(n):
		for j in range(m):
			if j == m - 1:
				if arr[i][j] == 'R':
					ctr += 1
			if i == n - 1:
				if arr[i][j] == 'D':
					ctr += 1
	print(ctr)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	for __ in range(n):
		a.append(input())
	curr = a[0][0]
	i = 0
	j = 0
	ct = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			ct += 1
	for i in range(m):
		if a[n - 1][i] == 'D':
			ct += 1
	print(ct)


qw = int(input())
for i in range(qw):
	s = input().split(' ')
	n = int(s[0])
	m = int(s[1])
	s1 = ''
	s2 = ''
	for j in range(n):
		ts = input()
		s1 += ts[len(ts) - 1]
		if j == n - 1:
			s2 = ts
	ssa = 0
	for j in range(len(s1) - 1):
		if s1[j] != 'D':
			ssa += 1
	for j in range(len(s2) - 1):
		if s2[j] != 'R':
			ssa += 1
	print(ssa)


t = int(input())
for _ in range(t):
	(R, C) = map(int, input().split())
	grid = [input() for _ in range(R)]
	result = sum((1 for x in grid[-1] if x != 'R')) + sum((1 for r in range(R) if grid[r][-1] != 'D')) - 2
	print(result)


T = int(input())
for t in range(1, T + 1):
	(N, M) = [int(s) for s in input().split()]
	(ans, grid) = (0, [])
	for n in range(N):
		x = input()
		if n < N - 1:
			if x[M - 1] == 'R':
				ans += 1
		else:
			for m in range(M - 1):
				if x[m] == 'D':
					ans += 1
	print(ans)


t = int(input())
ans = []
for i in range(t):
	s = input().split()
	n = int(s[0])
	m = int(s[1])
	grid = []
	for row in range(n):
		arr = input()
		grid.append(arr)
	answer = 0
	for column in range(m - 1):
		if grid[n - 1][column] == 'D':
			answer += 1
	for row in range(n - 1):
		if grid[row][m - 1] == 'R':
			answer += 1
	ans.append(answer)
for a in ans:
	print(a)


def find_min_cells_to_change(n, m, matrix):
	min_to_change = 0
	for v in range(m - 1):
		if matrix[-1][v] != 'R':
			min_to_change += 1
	for v in range(n - 1):
		if matrix[v][-1] != 'D':
			min_to_change += 1
	return min_to_change

def find_permutation(n):
	return [i for i in range(1, n + 1)]

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split(' '))
		matrix = []
		for _ in range(n):
			matrix.append(input())
		print(find_min_cells_to_change(n, m, matrix))
main()


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict
neo: lambda : map(int, input().split())
Neo: lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = []
	for i in range(n):
		s = input()
		A.append(s)
	Ans = 0
	for i in range(m):
		if A[n - 1][i] == 'D':
			Ans += 1
	for i in range(n):
		if A[i][m - 1] == 'R':
			Ans += 1
	print(Ans)


t = int(input())
for _ in range(0, t):
	inputs = [int(num) for num in input().split()]
	n = inputs[0]
	m = inputs[1]
	grid = []
	for i in range(0, n):
		s = input()
		grid.append([letter for letter in s])
	c = 0
	for i in range(0, n - 1):
		if grid[i][m - 1] == 'R':
			c += 1
	for i in range(0, m - 1):
		if grid[n - 1][i] == 'D':
			c += 1
	print(c)


for t in range(int(input())):
	arr = list(map(int, input().strip().split()))[:2]
	n = arr[0]
	m = arr[1]
	change = 0
	for x in range(n):
		s = input()
		if not x == n - 1:
			if s[m - 1] == 'R':
				change += 1
		else:
			for i in range(m):
				if s[i] == 'D':
					change += 1
	print(change)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	s = [input() for i in range(n)]
	res = 0
	for i in range(n):
		res += s[i][-1] == 'R'
	for i in range(m):
		res += s[-1][i] == 'D'
	print(res)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		curr = input()
		if curr[len(curr) - 1] == 'R':
			ans += 1
		if i == n - 1:
			ans += curr.count('D')
	print(ans)


t = int(input())
for p in range(t):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		row = input()
		matrix.append(row)
	count = 0
	for i in matrix[n - 1]:
		if i == 'D':
			count += 1
	for i in range(n - 1):
		if matrix[i][m - 1] == 'R':
			count += 1
	print(count)


t = int(input())
for q in range(t):
	(n, m) = map(int, input().split())
	rows = []
	for y in range(n):
		rows.append([x for x in input()])
	count = 0
	for x in range(n - 1):
		if rows[x][-1] == 'R':
			count += 1
	for x in range(m - 1):
		if rows[-1][x] == 'D':
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [[0] * m] * n
	for i in range(0, n):
		a[i] = list(input())
	c = 0
	col = m - 1
	for i in range(n - 1):
		if a[i][col] != 'D':
			c += 1
	row = n - 1
	for i in range(m - 1):
		if a[row][i] != 'R':
			c += 1
	print(c)


import math

def mi():
	return map(int, input().split())

def ii():
	return int(input())

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

def si():
	return input().split()
t = ii()
for _ in range(t):
	(n, m) = mi()
	a = []
	for i in range(n):
		a.append(input())
	cnt = 0
	for i in range(n - 1):
		if a[i][-1] != 'D':
			cnt += 1
	for i in range(m - 1):
		if a[-1][i] != 'R':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, m) = [int(e) for e in input().split()]
	l = []
	for i in range(n):
		l.append(input())
	dp = []
	if n == 1 and n == m:
		print(0)
	else:
		for i in range(n):
			dp.append([-1 for j in range(m)])
		dp[n - 1][m - 1] = 0
		for i in range(n - 2, -1, -1):
			dp[i][m - 1] = dp[i + 1][m - 1]
			if l[i][m - 1] == 'R':
				dp[i][m - 1] += 1
		for j in range(m - 2, -1, -1):
			dp[n - 1][j] = dp[n - 1][j + 1]
			if l[n - 1][j] == 'D':
				dp[n - 1][j] += 1
		for i in range(n - 2, -1, -1):
			for j in range(m - 2, -1, -1):
				if l[i][j] == 'D':
					dp[i][j] = min(dp[i + 1][j], 1 + dp[i][j + 1])
				else:
					dp[i][j] = min(1 + dp[i + 1][j], dp[i][j + 1])
		print(dp[0][m - 1] + dp[n - 1][0])


l = []
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	s = []
	for i in range(n):
		s.append(list(input()))
	if n == 1:
		if m != 1:
			count = 0
			for i in range(m - 1):
				if s[0][i] == 'D':
					count = count + 1
			l.append(count)
		else:
			l.append(0)
	elif m == 1:
		if n == 1:
			l.append(0)
		else:
			count = 0
			for i in range(n - 1):
				if s[i][0] == 'R':
					count = count + 1
			l.append(count)
	else:
		count = 0
		for i in range(n - 1):
			if s[i][m - 1] == 'R':
				count = count + 1
		for i in range(m - 1):
			if s[n - 1][i] == 'D':
				count = count + 1
		l.append(count)
for i in l:
	print(i)


from collections import *
import sys

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	(n, m) = rl()
	ans = 0
	for i in range(n - 1):
		aa = input()
		if aa[-1] == 'R':
			ans += 1
	aa = input()
	for i in range(m - 1):
		if aa[i] == 'D':
			ans += 1
	print(ans)


import sys
input = sys.stdin.readline
from math import *

def inp():
	return int(input().strip())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
for t in range(int(input())):
	(r, c) = invr()
	arr = []
	for i in range(r):
		arr.append(insr())
	cnt = 0
	for i in range(r):
		for j in range(c):
			if i == r - 1 and arr[i][j] == 'D':
				cnt += 1
			if j == c - 1 and arr[i][j] == 'R':
				cnt += 1
	print(cnt)


t = int(input())

def solve(n, m):
	cnt = 0
	for _ in range(n - 1):
		r = input()
		if r[-1] == 'R':
			cnt += 1
	r = input()
	cnt += r.count('D')
	return cnt
for _ in range(t):
	(n, m) = map(int, input().split())
	print(solve(n, m))


t = int(input())
d = 0
r = 0
for _ in range(t):
	(n, m) = map(int, input().split())
	d = 0
	for i in range(n):
		x = input()
		x = list(x)
		if i != n - 1:
			if x[m - 1] != 'D':
				d = d + 1
		if i == n - 1:
			r = abs(m - x.count('R') - 1)
	print(d + r)


Test = int(input())
for f in range(Test):
	(j, m) = map(int, input().split())
	list = []
	c2 = 0
	for i in range(j):
		lis = input()
		if lis[-1] == 'R':
			c2 += 1
		list.append(lis)
	c1 = list[-1].count('D')
	print(c1 + c2)


t = int(input())

def check(arr, n_, m_):
	res = 0
	for i in range(n_):
		if arr[i][m_ - 1] == 'R':
			res += 1
	for j in range(m_):
		if arr[n_ - 1][j] == 'D':
			res += 1
	return res
for k in range(t):
	(n, m) = list(map(int, input().split()))
	a = []
	for p in range(n):
		a.append(input())
	print(check(a, n, m))


tests = int(input())
for test in range(tests):
	(n, m) = map(int, input().split())
	cnt = 0
	for i in range(n - 1):
		s = input()
		if s[m - 1] == 'R':
			cnt += 1
	s = input()
	for i in range(m - 1):
		if s[i] == 'D':
			cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	dp = []
	for i in range(n):
		dp.append(input())
	c = 0
	for i in range(m - 1):
		if dp[-1][i] != 'R':
			c += 1
	for i in range(n - 1):
		if dp[i][-1] != 'D':
			c += 1
	print(c)


import sys
T = int(sys.stdin.readline())
for i in range(T):
	(n, m) = map(int, sys.stdin.readline().split())
	matrix = []
	cnt = 0
	for j in range(n):
		matrix.append(str(sys.stdin.readline().strip()))
	if n == 1 and m == 1:
		print(cnt)
	else:
		for k in range(n):
			if k != n - 1:
				if matrix[k][-1] == 'R':
					cnt += 1
			elif k == n - 1:
				cnt += matrix[k].count('D')
		print(cnt)


t = int(input())
out = []
for _ in range(t):
	(r, c) = map(int, input().split())
	mat = []
	for _ in range(r):
		mat.append(list(input()))
	count = 0
	for i in range(c):
		if mat[r - 1][i] == 'D':
			count = count + 1
	for i in range(r):
		if mat[i][c - 1] == 'R':
			count = count + 1
	out.append(count)
for i in out:
	print(i)


import sys
import heapq
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	c = 0
	for _ in range(n - 1):
		t = input().rstrip()
		if t[-1] == 'R':
			c += 1
	t = input().rstrip()
	c += t.count('D')
	print(c)


import math
import time
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import PriorityQueue
import sys
t = int(input())
for _ in range(t):
	(n, m) = map(int, stdin.readline().split())
	ans = 0
	for _ in range(n - 1):
		a = input()
		if a[-1] == 'R':
			ans += 1
	a = input()
	for i in a:
		if i == 'D':
			ans += 1
	print(ans)


def matrix(x, n, m):
	l = 0
	for j in range(m):
		for i in range(n):
			if x[i][j] == 'C':
				l += 0
			elif x[i][j] == 'D':
				if i + 1 >= n:
					l += 1
			elif x[i][j] == 'R':
				if j + 1 >= m:
					l += 1
	return l
for _ in range(int(input())):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	x = []
	for i in range(n):
		dp = [i for i in input()][:m]
		x.append(dp)
	print(matrix(x, n, m))


def moveItem(initPoint):
	(x, y) = initPoint
	while (x, y) != (N - 1, M - 1):
		if A[x][y] == 'R':
			if not 0 <= y + 1 < M:
				return (x, y)
			y += 1
		elif A[x][y] == 'D':
			if not 0 <= x + 1 < N:
				return (x, y)
			x += 1
	return (-1, -1)
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	A = [list(input()) for _ in range(N)]
	points = []
	for i in range(N):
		for j in range(M):
			if i == 0 or i == N - 1:
				points.append((i, j))
			elif j == 0 or j == M - 1:
				points.append((i, j))
	points.pop()
	ans = 0
	for point in points:
		while True:
			(x, y) = moveItem(point)
			if x == -1 and y == -1:
				break
			if A[x][y] == 'R':
				A[x][y] = 'D'
			else:
				A[x][y] = 'R'
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().strip().split(' '))
	rows = []
	for __ in range(n):
		rows.append(list(input().strip()))
	if n == 1 and m == 1:
		print(0)
		continue
	ans = 0
	for (i, c) in enumerate(rows[n - 1]):
		if c == 'D':
			ans += 1
	for (i, r) in enumerate(rows):
		if r[m - 1] == 'R':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	s = [input() for _ in range(a)]
	count = 0
	for e in s[:-1]:
		if e[-1] != 'D':
			count += 1
	for ele in s[-1][:-1]:
		if ele != 'R':
			count += 1
	print(count)


from sys import stdin, stdout
input = stdin.readline

def write(n, sep='\n'):
	stdout.write(str(n))
	stdout.write(sep)

def gil():
	return list(map(int, input().split()))
for _t in range(int(input())):
	(n, m) = gil()
	r = []
	d = []
	for i in range(n - 1):
		x = input().strip()
		r.append(x[-1])
	x = input().strip()
	d = x
	c = 0
	for i in r:
		if i == 'R':
			c += 1
	for i in d:
		if i == 'D':
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	grid = [input() for _ in range(n)]
	total = sum((c == 'D' for c in grid[-1]))
	for x in range(n):
		if grid[x][-1] == 'R':
			total += 1
	print(total)


cases = int(input())
for t in range(cases):
	(n, m) = list(map(int, input().split()))
	out = 0
	for i in range(n):
		s = input()
		if i == n - 1:
			out += sum([j != 'R' for j in s[:-1]])
		else:
			out += s[-1] != 'D'
	print(out)


for i in ' ' * int(input()):
	(n, m) = map(int, input().split())
	k = 0
	for i in range(n):
		s = input()
		if i == n - 1:
			k += s[:m - 1].count('D')
		else:
			k += s[-1] != 'D'
	print(k)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	l1 = []
	for i in range(0, n):
		s = input()
		l1.append(s)
	count = 0
	for i in range(0, n - 1):
		if l1[i][-1] == 'R':
			count = count + 1
	for i in range(0, m - 1):
		if l1[-1][i] == 'D':
			count = count + 1
	print(count)
	t = t - 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append([])
		for c in input():
			a[i].append(c)
	p = [[0] * m for i in range(n)]
	ans = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			ans += 1
			a[i][m - 1] = 'D'
	for i in range(m):
		if a[n - 1][i] == 'D':
			ans += 1
			a[n - 1][i] = 'R'
	print(ans)


tc = int(input())
for p in range(tc):
	(a, b) = map(int, input().split())
	ar = []
	for i in range(a):
		row = list(input())
		ar.append(row)
	count = 0
	if a == 1 and b == 1:
		if ar[0][0] == 'C':
			count = 0
	elif a == 1 and b != 1:
		for i in ar:
			for j in i:
				if j == 'D':
					count = count + 1
	elif a != 1 and b == 1:
		for i in ar:
			for j in i:
				if j == 'R':
					count = count + 1
	else:
		for i in ar:
			if i[-1] == 'R':
				count += 1
		for j in ar[-1]:
			if j == 'D':
				count += 1
	print(count)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(N, M) = map(int, input().split())
	res = 0
	for _ in range(N - 1):
		a = list(input())[:-1]
		res += a[-1] != 'D'
	a = list(input())[:-1]
	res += a.count('D')
	print(res)


t = int(input())
for k in range(t):
	s = input().split(' ')
	n = int(s[0])
	m = int(s[1])
	c = 0
	for i in range(n - 1):
		s = input()
		if s[m - 1] == 'R':
			c += 1
	s = input()
	for i in range(m - 1):
		if s[i] == 'D':
			c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [[0 for i in range(m)] for i in range(n)]
	for i in range(n):
		inp = input()
		c = 0
		for j in range(m):
			a[i][j] = inp[c]
			c += 1
	ans = sum((1 for i in a[-1] if i == 'D'))
	for i in range(n):
		if a[i][-1] == 'R':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split(' '))
	lis = []
	for i in range(n):
		k = str(input())
		lis.append(k)
	if n == 1 and m == 1:
		print(0)
	elif n == 1 and m != 1:
		count = 0
		for ch in lis[0][:-1]:
			if ch != 'R':
				count += 1
		print(count)
	elif n != 1 and m == 1:
		count = 0
		for z in range(n - 1):
			if lis[z][0] != 'D':
				count += 1
		print(count)
	else:
		count = 0
		for z in range(n - 1):
			if lis[z][-1] != 'D':
				count += 1
		for ch in lis[-1][:-1]:
			if ch != 'R':
				count += 1
		print(count)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = [int(x) for x in input().split()]
	mat = []
	for i in range(n):
		temp = input()
		mat.append(temp)
	count = 0
	for i in range(n):
		s = mat[i]
		if s[-1] == 'R':
			count += 1
		if i == n - 1:
			for j in range(m):
				if s[j] == 'D':
					count += 1
	print(count)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	ans = 0
	for i in range(x - 1):
		fd = input()
		if fd[-1] == 'R':
			ans += 1
	fd = input().rstrip()
	for j in fd:
		if j == 'D':
			ans += 1
	print(ans)


try:
	tst = int(input())
	for _ in range(tst):
		(n, m) = map(int, input().split())
		lst = []
		count = 0
		for i in range(n):
			lst.append(input())
		for i in lst[-1]:
			if i == 'C':
				continue
			elif i == 'D':
				count += 1
		for i in range(n):
			if lst[i][-1] == 'C':
				continue
			elif lst[i][-1] == 'R':
				count += 1
		print(count)
except:
	pass


t = int(input())
for _ in range(t):
	(r, c) = list(map(int, input().split(' ')))
	A = []
	for i in range(r):
		A.append(list(input()))
	last_row = A[-1]
	last_column = []
	for i in range(r):
		last_column.append(A[i][-1])
	print(last_column.count('R') + last_row.count('D'))


def fix(a, n, m):
	count = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			count += 1
	for j in range(m):
		if a[n - 1][j] == 'D':
			count += 1
	return count
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		a = list(input())
		matrix.append(a)
	print(fix(matrix, n, m))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	for i in range(n - 1):
		l = input()
		if l[-1] != 'D':
			c += 1
	l = input()
	c1 = l.count('D')
	c += c1
	print(c)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list()
	ans = 0
	for i in range(n):
		str = input()
		if i == n - 1:
			ans += str.count('D')
		elif str[m - 1] == 'R':
			ans += 1
	print(ans)


t = int(input())
ans = []
for i in range(t):
	(n, m) = [int(i) for i in input().split()]
	d = []
	for j in range(n):
		d.append(input())
	count = 0
	for k in d:
		if k[-1] == 'R':
			count += 1
	for j in d[-1]:
		if j == 'D':
			count += 1
	ans.append(count)
for i in ans:
	print(i)


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	arr = []
	ans = 0
	for i in range(n):
		a = list((i for i in input()))
		arr.append(a)
	for i in range(n - 1):
		if arr[i][m - 1] == 'R':
			ans += 1
	for j in arr[n - 1]:
		if j == 'D':
			ans += 1
	print(ans)


def solve(s, il, jl):
	Rcount = 0
	for i in range(il):
		Rcount += s[i][jl - 1].count('R')
	Dcount = s[il - 1].count('D')
	print(Rcount + Dcount)
n = int(input())
for i in range(n):
	(a, b) = input().split()
	x = []
	for j in range(int(a)):
		s = [s for s in input()]
		x.append(s)
	solve(x, int(a), int(b))


n = int(input())
for i in range(n):
	x = map(int, input().split())
	(a, b) = x
	c = 0
	for j in range(a - 1):
		a = input()
		if a[-1] == 'R':
			c += 1
	y = input()
	print(y.count('D') + c)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(n, m) = sp()
	mat = []
	for i in range(n):
		mat.append(list(data()))
	answer = mat[-1].count('D')
	for i in range(n):
		if mat[i][-1] == 'R':
			answer += 1
	out(answer)


t = int(input())
l = []
(n, m) = (0, 0)
c = 0
p = []
for i in range(t):
	c = 0
	l = input().split(' ')
	for j in range(int(l[0]) - 1):
		k = input()
		if k[int(l[1]) - 1] == 'R':
			c += 1
	k = input()
	for j in k:
		if j == 'D':
			c += 1
	p.append(c)
for i in range(t):
	print(p[i])


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	res = 0
	for i in range(a):
		s = input()
		if s[-1] != 'C':
			if s[-1] == 'R':
				res += 1
		else:
			res += s.count('D')
	print(res)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	counter = 0
	for i in range(n):
		s = input()
		if s[-1] == 'R':
			counter += 1
		if i == n - 1:
			for j in s:
				if j == 'D':
					counter += 1
	print(counter)


import sys
import math
from collections import defaultdict, Counter, deque

def solve(test):
	(n, m) = map(int, input().split())
	mat = [None for i in range(n)]
	for i in range(n):
		mat[i] = list(input())
	visit = [[False for j in range(m)] for i in range(n)]
	visit[-1][-1] = True
	for i in range(n - 1, -1, -1):
		for j in range(m - 1, -1, -1):
			if i > 0:
				visit[i - 1][j] = visit[i - 1][j] or (True if mat[i - 1][j] == 'D' else False)
			if j > 0:
				visit[i][j - 1] = visit[i][j - 1] or (True if mat[i][j - 1] == 'R' else False)
	ans = 0
	for i in range(n):
		for j in range(m):
			ans += 1 if not visit[i][j] else 0
	print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n - 1):
		a.append(list(str(input()))[-1])
	print(list(str(input())).count('D') + a.count('R'))


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, m) = list(map(int, stdin.readline().split()))
	res = 0
	for _ in range(n - 1):
		s = input()
		if s[-1] == 'R':
			res += 1
	s = input()
	for c in s[:-1]:
		if c == 'D':
			res += 1
	print(res)


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	S = [input()[:-1] for _ in range(n)]
	D_bo = 0
	R_ri = 0
	for i in range(m - 1):
		if S[-1][i] == 'D':
			D_bo += 1
	for i in range(n - 1):
		if S[i][-1] == 'R':
			R_ri += 1
	print(D_bo + R_ri)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(list(input()))
	d = a[n - 1].count('D')
	r = 0
	for i in range(n):
		if a[i][-1] == 'R':
			r += 1
	print(d + r)


t = int(input())
for case in range(0, t):
	(n, m) = list(map(int, input().split()))
	matrix = []
	for i in range(0, n):
		matrix.append(input())
	count = 0
	for i in range(0, n - 1):
		if matrix[i][m - 1] == 'R':
			count += 1
	for j in range(0, m - 1):
		if matrix[n - 1][j] == 'D':
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	cnt = 0
	for i in range(n):
		st = input()
		for (j, tmp) in enumerate(st):
			if j == m - 1 and tmp != 'D':
				cnt += 1
			if i == n - 1 and tmp != 'R':
				cnt += 1
	print(cnt - 2)


import sys
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(input())
	ans = 0
	for i in range(n - 1):
		if mat[i][m - 1] == 'R':
			ans += 1
	for i in range(m - 1):
		if mat[n - 1][i] == 'D':
			ans += 1
	print(ans)


for testcases in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	counter = 0
	for i in range(a - 1):
		nice = input()
		if nice[-1] != 'D':
			counter += 1
	nice = input()
	for x in range(len(nice) - 1):
		if nice[x] != 'R':
			counter += 1
	print(counter)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
from fractions import Fraction
INF = float('inf')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	(n, m) = mdata()
	mat = []
	for i in range(n):
		mat.append(data())
	ans = 0
	for i in range(n - 1):
		if mat[i][m - 1] != 'D':
			ans += 1
	for i in range(m - 1):
		if mat[n - 1][i] != 'R':
			ans += 1
	out(ans)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop
from bisect import bisect_right, bisect_left

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
mod = 1000000007
res = ['NO', 'YES']
(test, test_case) = (0, 1)
test_case = ii()
while test < test_case:
	test += 1
	(n, m) = mi()
	a = []
	for _ in range(n):
		a.append(lsi())
	c = 0
	for i in range(m):
		if a[n - 1][i] == 'D':
			c += 1
	for i in range(n):
		if a[i][m - 1] == 'R':
			c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [list(input()) for _ in range(n)]
	print(len([x for x in a[n - 1] if x == 'D']) + len([x for x in a if x[m - 1] == 'R']))


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	count = 0
	for _ in range(m - 1):
		row = input()
		if row[-1] == 'R':
			count += 1
	last_row = input()
	for cell in last_row:
		if cell == 'D':
			count += 1
	print(count)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin, stdout
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math
import math
import time
from queue import Queue

def seive(n):
	l = [True]
	l = l * (n + 1)
	for i in range(2, int(sqrt(n)) + 1):
		if l[i] == True:
			val = i * i
			while val < len(l):
				l[val] = False
				val += i
	prime = []
	for i in range(2, len(l)):
		if l[i] == True:
			prime.append(i)
	return prime

def dp(l, i, n, val, ans):
	if i >= n or val < 0:
		return 1000000
	elif val == 0:
		return 0
	else:
		if ans[i] == 1000000:
			ans[i] = min(min(1 + dp(l, i + 1, n, val - l[i], ans), 1 + dp(l, i, n, val - l[i], ans)), dp(l, i + 1, n, val, ans))
		return ans[i]
from queue import Queue

def factors(n):
	l = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def check1(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v -= 1

def check2(s, v, x):
	while True:
		if v not in s:
			return v
		else:
			v += 1

def up(n):
	j = n - 1
	while j > 0:
		if n % j == 0:
			break
		j -= 1
	return j

def fac(n):
	c = 1
	i = 1
	while i <= n:
		c *= i
		i += 1
	return c

def check_happy(n):
	ss = set()
	print(n)
	while n != 1:
		val = n
		s = 0
		print(val)
		while val != 0:
			s += (val % 10) ** 2
			val = val // 10
		print(val)
		print('hi')
		if val in ss:
			return False
		else:
			n = val
			ss.add(n)
	return True

def update(a, b):
	c = 1
	val = a
	while a < b:
		print(c, a)
		c += c
		a += a
	print(1)
	while a > b:
		print()
		a -= val
		c -= 1
	return c
import random as rand

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
from itertools import permutations

def insertion_sort(arr):
	for i in range(len(arr)):
		j = i
		while j > 0:
			if arr[j] < arr[j - 1]:
				temp = arr[j]
				arr[j] = arr[j - 1]
				arr[j - 1] = temp
			j -= 1
	return arr

def quick_sort(arr, low, high):
	i = low
	j = high
	while i < j:
		if arr[i] > arr[low] and arr[j] < arr[low]:
			temp = arr[i]
			arr[i] = arr[j]
			arr[j] = arr[i]
			i += 1
			j -= 1
		elif arr[i] <= arr[low]:
			i += 1
		elif arr[j] >= arr[low]:
			j -= 1
	print(i, j)
	toto = arr[j]
	arr[j] = arr[low]
	arr[low] = toto
	return j

def dodo(arr, low, high):
	if low < high:
		val = quick_sort(arr, low, high)
		dodo(arr, low, val - 1)
		dodo(arr, val + 1, high)

def dp(arr, c, n, k, z, ans):
	if k == 0:
		return ans
	elif c == 0:
		return dp(arr, c + 1, n, k - 1, z, ans + arr[c + 1])
	elif c == n - 1:
		if z == 0:
			return 0
		else:
			return dp(arr, c - 1, n, k - 1, z - 1, ans + arr[c - 1])
	elif z == 0:
		return dp(arr, c + 1, n, k - 1, z, ans + arr[c + 1])
	else:
		return max(dp(arr, c + 1, n, k - 1, z, ans + arr[c + 1]), dp(arr, c - 1, n, k - 1, z - 1, ans + arr[c - 1]))

def check(arr, val):
	a = -1
	for i in range(len(arr)):
		if arr[i][len(arr[i]) - 1] == val:
			a = i
			break
	return a

def reverse(s, i, ans):
	if i >= len(s):
		return ans
	else:
		return reverse(s, i + 1, s[i] + ans)

def update(arr, i, j, n, m):
	if i >= 0 and i < n and (j >= 0) and (j < m):
		if arr[i][j] == 1:
			arr[i][j] == 2
			return [i, j]
	return [-1, -1]
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split(' '))
	arr = []
	for j in range(n):
		l = []
		s = input()
		for k in s:
			l.append(k)
		arr.append(l)
	ans = 0
	for j in range(m - 1):
		if arr[n - 1][j] != 'R':
			ans += 1
	for j in range(n - 1):
		if arr[j][m - 1] != 'D':
			ans += 1
	print(ans)


t = int(input())
for x in range(t):
	grid = []
	flag = 0
	(n, m) = map(int, input().split())
	for i in range(n):
		grid.append(input())
		if grid[i][-1] == 'R':
			flag += 1
	j = 0
	while j < m:
		if grid[-1][j] == 'D':
			flag += 1
		j += 1
	print(flag)


def min_moves(mat, n, m):
	ans = 0
	for i in range(n - 1):
		if mat[i][m - 1] != 'D':
			ans += 1
	for j in range(m - 1):
		if mat[n - 1][j] != 'R':
			ans += 1
	return ans
t = int(input())
while t:
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	print(min_moves(mat, n, m))
	t -= 1


def f():
	(a, b) = map(int, input().split(' '))
	c = 0
	for i in range(a - 1):
		s = input()
		if s[len(s) - 1] == 'R':
			c += 1
	s = input()
	for i in s:
		if i == 'D':
			c += 1
	print(c)
	return
t = int(input())
while t:
	f()
	t -= 1


import sys
import collections

def input():
	return sys.stdin.readline().rstrip()

def split_input():
	return [int(i) for i in input().split()]
tests = int(input())
for _ in range(tests):
	(n, m) = split_input()
	a = []
	for i in range(n):
		tmp = list(input())
		a.append(tmp)
	num = 0
	for j in range(m - 1):
		if a[n - 1][j] != 'R':
			num += 1
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			num += 1
	print(num)


t = int(input())
for i in range(t):
	(n, m) = input().strip().split(' ')
	(n, m) = [int(n), int(m)]
	p = []
	for j in range(n):
		a = input()
		p.append(a)
	c = 0
	for j in p[n - 1]:
		if j == 'D':
			c += 1
	for j in range(n):
		if p[j][m - 1] == 'R':
			c += 1
	print(c)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	arr = []
	ans = 0
	if m == 1 and n != 1:
		a = list(input())
		ans = a.count('D')
	else:
		for i in range(m - 1):
			a = list(input())
			if a[n - 1] == 'R':
				ans += 1
		a = list(input())
		ans += a.count('D')
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	lines = [input() for _ in range(n)]
	total = sum((l[-1] == 'R' for l in lines)) + lines[-1].count('D')
	print(total)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	l = []
	for i in range(n):
		x = input()
		x = list(x)
		l.append(x)
	count = 0
	vis = [[False] * m for g in range(n)]
	for i in range(n):
		for j in range(m):
			if j == m - 1 and l[i][j] == 'R':
				count += 1
			elif l[i][j] == 'D' and i == n - 1 and (j < m - 1):
				count += 1
	print(count)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())
t = oint()
for _ in range(t):
	(n, m) = rint()
	a = []
	for i in range(n):
		a.append(get_str())
	cnt = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'R':
				if j + 1 >= m:
					cnt += 1
			elif a[i][j] == 'D':
				if i + 1 >= n:
					cnt += 1
	print(cnt)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	(n, m) = sep()
	ar = []
	for _ in range(n):
		ar.append(inp())
	c = 0
	for j in range(m):
		if ar[n - 1][j] == 'D':
			c += 1
	for i in range(n):
		if ar[i][m - 1] == 'R':
			c += 1
	print(c)
testcase(int(inp()))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	jadval = []
	for _ in range(n):
		a = input()
		a = list(a)
		jadval.append(a)
	ans = 0
	for i in range(n - 1):
		if jadval[i][m - 1] != 'D':
			ans += 1
	for i in range(m - 1):
		if jadval[n - 1][i] != 'R':
			ans += 1
	print(ans)


import sys
import collections as cc
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, m) = I()
	a = []
	for i in range(n):
		a.append(list(input()))
	ans = 0
	for i in range(m - 1):
		if a[n - 1][i] != 'R':
			ans += 1
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	c = 0
	for i in range(n):
		arrtemp = input()
		if arrtemp[m - 1] == 'R':
			c += 1
		if i == n - 1:
			c += arrtemp.count('D')
	print(c)


from math import *
from collections import *
from random import *
from decimal import Decimal
from heapq import *
from bisect import *
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)

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

def ma():
	return map(int, input().split())

def inp():
	return int(input())

def st1():
	return input().rstrip('\n')
t = inp()
while t:
	t -= 1
	(n, m) = ma()
	r = []
	for i in range(n):
		s = st1()
		s = list(s)
		r.append(s)
	mo = 0
	for i in range(n):
		if r[i][-1] == 'R':
			mo += 1
	print(r[-1].count('D') + mo)


tests = int(input())
for i in range(tests):
	(n, m) = list(map(int, input().split()))
	edge_down = []
	edge_right = []
	for i in range(n):
		x = input()
		edge_right += x[-1]
		if i == n - 1:
			edge_down += x
	c = 0
	for i in edge_down:
		if i == 'D':
			c += 1
	for i in edge_right:
		if i == 'R':
			c += 1
	print(c)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return
mod = 10 ** 9 + 7

def solve():
	(n, m) = L()
	li = [input() for i in range(n)]
	if n == 1 and m == 1:
		P(0)
		return
	else:
		cnt = 0
		for i in range(n):
			if li[i][m - 1] == 'R':
				cnt += 1
		for i in range(m):
			if li[n - 1][i] == 'D':
				cnt += 1
		P(cnt)
		return
t = II()
for i in range(t):
	solve()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	M = [input().strip() for _ in range(n)]
	count = 0
	for i in M[-1]:
		if i == 'D':
			count += 1
	c1 = [M[j][-1] for j in range(n)]
	count += c1.count('R')
	print(count)


t = int(input())
for i in range(t):
	(x, y) = map(int, input().split())
	arr = []
	for j in range(x):
		s = input()
		arr.append(s)
	bottom = arr[x - 1].count('D')
	right = 0
	for j in range(x):
		if arr[j][y - 1] == 'R':
			right += 1
	print(bottom + right)


tc = int(input())
result = []
for i in range(tc):
	change = 0
	nm = input().split(' ')
	n = int(nm[0])
	m = int(nm[1])
	for t in range(n):
		grid = input()
		if grid[m - 1] == 'R' and grid[m - 1] != 'C':
			change += 1
		if t + 1 == n:
			for e in grid:
				if e == 'D' and e != 'C':
					change += 1
	result.append(str(change))
for r in result:
	print(r)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, m) = map(int, input().split())
	c = 0
	g = []
	for i in range(n):
		p = list(input())
		g.append(p)
	for i in range(n - 1):
		if g[i][m - 1] != 'D':
			c += 1
	for i in range(m - 1):
		if g[n - 1][i] != 'R':
			c += 1
	print(c)


from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		s = input().strip()
		if s[-1] == 'R':
			ans += 1
		elif s[-1] == 'C':
			ans += s.count('D')
	print(ans)


def main():
	test = int(input())
	for _ in range(test):
		(n, m) = map(int, input().split())
		li = []
		for _ in range(n):
			arr = input()
			li.append(arr[-1])
		c1 = -1
		for i in li:
			if i == 'D':
				continue
			else:
				c1 += 1
		c2 = -1
		for j in arr:
			if j == 'R':
				continue
			else:
				c2 += 1
		print(c1 + c2)
main()


def funk(m, n):
	reply = 0
	for i in range(m):
		s = str(input())
		if s[n - 1] == 'R':
			reply += 1
	for j in range(n):
		if s[j] == 'D':
			reply += 1
	print(reply)
num = int(input())
for i in range(num):
	(m, n) = input().split()
	m = int(m)
	n = int(n)
	funk(m, n)


def solve():
	(n, m) = map(int, input().split())
	lst = [input() for _ in range(n)]
	cnt = 0
	for i in range(n):
		if lst[i][m - 1] == 'R':
			cnt += 1
	for i in range(m):
		if lst[n - 1][i] == 'D':
			cnt += 1
	print(cnt)
for _ in range(int(input())):
	solve()


TC = int(input())
for tc in range(TC):
	(N, M) = map(int, input().split())
	C = []
	result = 0
	for _ in range(N):
		C.append(list(input()))
	for i in range(N - 1):
		if C[i][-1] != 'D':
			result += 1
	for j in range(M - 1):
		if C[-1][j] != 'R':
			result += 1
	print(result)


n = int(input())
for i in range(n):
	grid = input().split()
	gridx = int(grid[1])
	gridy = int(grid[0])
	count = 0
	for j in range(gridy):
		arr = input()
		if arr[-1] == 'R':
			count += 1
	print(count + arr.count('D'))


def solution(arr, x, y):
	operations = 0
	for i in range(y):
		if arr[i][-1] == 'R':
			operations += 1
	for i in range(x):
		if arr[-1][i] == 'D':
			operations += 1
	return operations

def main():
	for test in range(int(input())):
		(y, x) = map(int, input().split())
		field = []
		for _ in range(y):
			field.append(list(input()))
		result = solution(field, x, y)
		print(result)
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	cb = []
	for _ in range(n):
		cb.append(input())
	c = 0
	for i in range(n - 1):
		if cb[i][-1] == 'R':
			c += 1
	for ch in cb[-1]:
		if ch == 'D':
			c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	cnt = 0
	for i in range(n):
		a = list(input())
		if a[-1] == 'R' and i != n - 1:
			cnt += 1
		if i == n - 1:
			for k in range(m):
				if a[k] == 'D':
					cnt += 1
	print(cnt)


import sys, os
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = lambda : sys.stdin.readline().strip()
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
for _ in range(I()):
	(n, m) = li()
	grid = []
	for i in range(n):
		grid.append(list(input()))
	c = 0
	for i in range(n - 1):
		if grid[i][m - 1] != 'D':
			c += 1
	for i in range(m - 1):
		if grid[n - 1][i] != 'R':
			c += 1
	print(c)


def sol():
	(rows, cols) = list(map(int, input().split()))
	res = 0
	for _ in range(rows - 1):
		res += [1, 0][input()[-1] == 'D']
	for char in input()[:-1]:
		if char != 'R':
			res += 1
	return res

def main():
	T = int(input())
	for t in range(T):
		res = sol()
		print(res)
main()


from sys import stdin
for _ in range(int(input())):
	(n, m) = list(map(int, stdin.readline().split()))
	matrix = []
	for i in range(n):
		matrix.append(list(stdin.readline().rstrip()))
	ans = 0
	for i in range(n):
		for j in range(m):
			if i == n - 1 and matrix[i][j] == 'D':
				ans += 1
			if j == m - 1 and matrix[i][j] == 'R':
				ans += 1
	print(ans)


t = int(input())
for o in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		g = list(input())
		a.append(g)
	cnt = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			cnt += 1
	for i in range(m):
		if a[n - 1][i] == 'D':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	(x, y) = [int(x) for x in input().split()]
	grid = []
	for i in range(x):
		grid.append(list(input()))
	counter = 0
	for i in range(x):
		if grid[i][y - 1] == 'R':
			counter += 1
	for i in range(y):
		if grid[x - 1][i] == 'D':
			counter += 1
	print(counter)


for z in range(int(input())):
	(n, m) = map(int, input().split())
	s = []
	for i in range(n):
		s.append(input())
	cnt = 0
	for i in range(0, n):
		for j in range(m):
			if s[i][j] == 'R' and j == m - 1:
				cnt += 1
			elif s[i][j] == 'D' and i == n - 1:
				cnt += 1
	print(cnt)


t = int(input())
for cases in range(t):
	(y, x) = map(int, input().split())
	ls = [0] * y
	for i in range(y):
		ls[i] = list(input())
	ans = 0
	l = ls[y - 1]
	for i in l:
		if i == 'D':
			ans += 1
	for i in range(y - 1):
		if ls[i][x - 1] == 'R':
			ans += 1
	print(ans)


import sys
from math import sqrt
from collections import OrderedDict
inpt = sys.stdin.readline

def inp():
	return int(inpt())

def inlist():
	return list(map(int, inpt().split()))

def instr():
	s = inpt()
	return list(s[:len(s) - 1])

def invr():
	return map(int, inpt().split())

def main():
	t = inp()
	for l in range(t):
		(n, m) = invr()
		a = [[] * m] * n
		for i in range(n):
			a[i] = instr()
		tot = 0
		for i in range(n - 1):
			if a[i][m - 1] != 'D':
				tot += 1
		for i in range(m - 1):
			if a[n - 1][i] != 'R':
				tot += 1
		print(tot)
main()


t = int(input())
for q in range(0, t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(0, n):
		b = input()
		b = list(b)
		a.append(b)
	count = 0
	for i in range(0, n - 1):
		if a[i][m - 1] == 'R':
			count += 1
	for i in range(0, m - 1):
		if a[n - 1][i] == 'D':
			count += 1
	print(count)


t = int(input())
a = []
for i in range(t):
	s = 0
	(n, m) = list(map(int, input().split()))
	for i in range(n - 1):
		t = input()
		if t[-1] == 'R':
			s += 1
	t = input()
	for i in range(m - 1):
		if t[i] == 'D':
			s += 1
	a.append(s)
print(*a, sep='\n')


from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gcl = lambda : list(g())
mod = int(1000000000.0) + 7
(t,) = gil()
for _ in range(t):
	(n, m) = gil()
	cnt = 0
	for _ in range(n - 1):
		if g()[-1] == 'R':
			cnt += 1
	for char in g()[:-1]:
		if char == 'D':
			cnt += 1
	print(cnt)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n - 1):
		k = input()
		if k[m - 1] == 'R':
			ans += 1
	k = input()
	for i in k:
		if i == 'D':
			ans += 1
	print(ans)


import sys

def main():
	tn = int(sys.stdin.readline())
	for ti in range(tn):
		(n, _) = map(int, sys.stdin.readline().split())
		F = [sys.stdin.readline().strip() for _ in range(n)]
		a = F[-1]
		b = ''.join((f[-1] for f in F))
		print(a.count('D') + b.count('R'))
main()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		ct = 0
		for i in range(n):
			s = input()
			if i == n - 1:
				for j in s:
					if j == 'D':
						ct += 1
			elif s[m - 1] == 'R':
				ct += 1
		print(ct)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, collections

def bfs(a, b):
	global cnt
	q = collections.deque()
	q.append((a, b))
	while q:
		(x, y) = q.popleft()
		if board[x][y] == 'R':
			(nx, ny) = (x, y + 1)
			if nx < 0 or nx >= n or ny < 0 or (ny >= m):
				cnt += 1
				board[x][y] = 'D'
				continue
			elif vis[nx][ny] == False:
				q.append((nx, ny))
		elif board[x][y] == 'D':
			(nx, ny) = (x + 1, y)
			if nx < 0 or nx >= n or ny < 0 or (ny >= m):
				cnt += 1
				board[x][y] = 'R'
				continue
			elif vis[nx][ny] == False:
				q.append((nx, ny))
		else:
			continue
tc = int(sys.stdin.readline())
for _ in range(tc):
	(n, m) = map(int, sys.stdin.readline().split())
	board = [list(sys.stdin.readline().rstrip()) for _ in range(n)]
	vis = [[False] * m for _ in range(n)]
	cnt = 0
	for i in range(n):
		for j in range(m):
			if vis[i][j] == False:
				bfs(i, j)
	print(cnt)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	A = []
	if n == 1 and m == 1:
		A = str(input())
		print(ans)
	else:
		for j in range(n - 1):
			A = str(input())
			if A[-1] == 'R':
				ans += 1
		A = str(input())
		ans += A[:-1].count('D')
		print(ans)


t = int(input())
while t:
	t -= 1
	(n, p) = map(int, input().split())
	count = 0
	l = [[i for i in input()] for j in range(n)]
	for i in range(n):
		s = l[i]
		if i != n - 1:
			if s[-1] == 'R':
				count += 1
		else:
			count += s.count('D')
	print(count)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)
MOD = 1000000007
PMOD = 998244353
T = 1
T = int(stdin.readline())
for _ in range(T):
	(n, m) = list(map(int, stdin.readline().rstrip().split()))
	a = []
	for i in range(n):
		a.append(list(stdin.readline().strip('\n')))
	ans = 0
	for i in range(n):
		for j in range(m):
			if i == n - 1 and a[i][j] == 'D':
				ans += 1
			if j == m - 1 and a[i][j] == 'R':
				ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	rs = 0
	for i in range(n):
		string = input()
		if string[m - 1] == 'R':
			rs += 1
		if i == n - 1:
			rs += string.count('D')
	print(rs)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [input() for i in range(n)]
	ans = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			ans += 1
	ans += a[-1].count('D')
	print(ans)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(list(input()))
	col = [x[-1] for x in arr]
	row = arr[-1]
	ans = 0
	for x in col:
		if x != 'D':
			ans += 1
	for x in row:
		if x != 'R':
			ans += 1
	print(ans - 2)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	lst = []
	col = []
	for _ in range(n):
		s = list(input())
		col.append(s[-1])
		lst.append(s)
	col.pop()
	row = lst[-1]
	row.pop()
	count = 0
	for i in row:
		if i == 'D':
			count += 1
	for i in col:
		if i == 'R':
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	count = 0
	for j in range(n):
		row = input()
		if j == n - 1:
			for val in row:
				if val == 'D':
					count += 1
		elif row[m - 1] == 'R':
			count += 1
	print(count)


t = int(input())
new = []
for _ in range(t):
	(n, m) = map(int, input().split())
	myList1 = []
	myList2 = []
	k = 0
	l = 0
	o = 0
	f = 0
	for k in range(n):
		if k != n - 1:
			st = list(input())
			myList1.append(st[-1])
		else:
			st = list(input())
			while l < m - 1:
				myList2.append(st[l])
				l += 1
	for i in range(n - 1):
		if myList1[i] == 'R':
			o += 1
	for j in range(m - 1):
		if myList2[j] == 'D':
			f += 1
	new.append(f + o)
for elem in new:
	print(elem)


t = int(input())
for count in range(t):
	(n, m) = map(int, input().split())
	x = 0
	for i in range(n):
		a = str(input())
		if i == n - 1:
			for h in range(m):
				if a[h] == 'D':
					x += 1
		elif a[m - 1] == 'R':
			x += 1
	print(x)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	a = [input() for i in range(m)]
	print(sum([1 for i in a if i[-1] != 'D']) + sum([1 for i in a[-1] if i != 'R']) - 2)


for i in range(int(input())):
	arr = []
	(n, m) = map(int, input().split())
	for j in range(n - 1):
		d = list(input())
		arr.append(d[m - 1])
	e = list(input())
	f = e.count('D')
	print(arr.count('R') + f)


from sys import stdin
input = stdin.readline
import math
lines = int(input())
for j in range(lines):
	(height, length) = map(int, input().split())
	array = []
	counter = 0
	for i in range(height):
		x = list(map(str, input().split()))
		array.append(x)
	for i in range(length):
		if array[height - 1][0][i:i + 1] == 'D':
			counter += 1
	for i in range(height):
		if array[i][0][length - 1:] == 'R':
			counter += 1
	print(counter)


import time
from collections import deque

def inpt():
	return int(input())

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

def inpm():
	return map(int, input().split())

def solve():
	(n, m) = inpm()
	l = []
	for i in range(n):
		x = input()
		l.append(x)
	ans = 0
	for i in range(m - 1):
		if l[n - 1][i] == 'D':
			ans += 1
	for i in range(n - 1):
		if l[i][m - 1] == 'R':
			ans += 1
	print(ans)

def main():
	m = 10 ** 9 + 7
	t = int(input())
	while t:
		t -= 1
		solve()
main()


def solve(n, m):
	if n == 1 and m == 1:
		s = input()
		return 0
	if n == 1:
		s = input()
		return s.count('D')
	s = ''
	count = 0
	for i in range(1, n):
		s = input()
		if s[-1] == 'R':
			count = count + 1
	s = input()
	count = count + s.count('D')
	return count
t = int(input())
for i in range(t):
	(n, m) = input().split()
	result = solve(int(n), int(m))
	print(result)


N = int(input())
for i in range(N):
	s = input()
	c = 0
	for j in range(len(s)):
		if s[j] == ' ':
			k = j
	x = int(s[0:k])
	y = int(s[k + 1:len(s)])
	for j in range(x - 1):
		t = input()
		if t[y - 1] == 'R':
			c = c + 1
	t = input()
	for j in range(y):
		if t[j] == 'D':
			c = c + 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ls = []
	for i in range(n - 1):
		ls.append(input())
	waste = input()
	ans = waste.count('D')
	for i in ls:
		if i[-1] == 'R':
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	s = str(input())
	L = []
	for i in range(n - 1):
		L = L + [s[m - 1]]
		s = str(input())
	C = []
	for i in s[:m - 1]:
		C = C + [i]
	a = C.count('D')
	f = 0
	b = L.count('R')
	f = f + a + b
	print(f)


t = int(input())
for _ in range(0, t):
	(n, m) = map(int, input().split())
	a = []
	count = 0
	x = 0
	y = 0
	for i in range(0, n):
		b = list(map(str, input().split()))
		a.append(b)
	if n == 1 and m == 1:
		print(0)
	elif n == 1:
		a = a[0][0]
		p = a.count('D')
		print(p)
	else:
		i = 0
		for i in range(0, n - 1):
			z = a[i][0]
			p = z[len(z) - 1]
			if p == 'R':
				count += 1
		z = a[len(a) - 1][0]
		p = z.count('D')
		print(count + p)


for _ in range(int(input())):
	(r, c) = (int(x) for x in input().split())
	l = []
	for i in range(r):
		l.append(input())
	cnt = 0
	for i in range(r - 1):
		if l[i][c - 1] == 'R':
			cnt += 1
	for i in range(c - 1):
		if l[r - 1][i] == 'D':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list()
	r = 0
	for __ in range(n):
		l.append(input())
	r += l[-1].count('D')
	for i in l:
		if i[-1] == 'R':
			r += 1
	print(r)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, m) = li()
	l = []
	for i in range(n):
		l.append(list(st()))
	ans = l[-1].count('D')
	for i in range(n - 1):
		ans += 1 if l[i][-1] == 'R' else 0
	print(ans)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, Counter
import math

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

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = intIn()
while t > 0:
	t -= 1
	(n, m) = listIn()
	matrix = []
	for i in range(n):
		a = stringIn()
		matrix.append(a)
	last_row = matrix[-1]
	last_col = []
	for i in range(n):
		last_col.append(matrix[i][-1])
	ans = 0
	last_col = last_col[:-1]
	last_row = last_row[:-1]
	ans = last_col.count('R') + last_row.count('D')
	print(ans)


T = int(input())
for _ in range(T):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	l = []
	for i in range(n):
		l.append(input())
	flips = 0
	for i in range(n):
		if l[i][m - 1:] == 'R':
			flips += 1
	for i in range(m):
		if l[n - 1][i:i + 1] == 'D':
			flips += 1
	print(flips)


t = int(input())
for h in range(0, t):
	(i, j) = [int(g) for g in input().split()]
	o = []
	a = 0
	for l in range(0, i):
		o.append(input())
	for k in o:
		if k[-1] == 'R':
			a += 1
	a += o[-1].count('D')
	print(a)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = [list(input()) for _ in range(n)]
	a = grid[-1]
	b = [row[-1] for row in grid]
	print(a.count('D') + b.count('R'))


def ans():
	N = int(input())
	for j in range(N):
		a = input().split()
		c = 0
		for i in range(int(a[0])):
			if i == int(a[0]) - 1:
				b = input()
				for k in range(len(b) - 1):
					if b[k] != 'R':
						c += 1
			else:
				b = input()
				if b[-1] != 'D':
					c += 1
		print(c)
ans()


t = int(input())
res = []
for i in range(t):
	a = list()
	r = 0
	(m, n) = list(map(int, input().split(' ')))
	for j in range(m):
		a.append(input())
		if a[-1][-1] == 'R':
			r += 1
	r += a[-1].count('D')
	res.append(str(r))
print('\n'.join(res))


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def solve(n, m, grid):
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'C':
				cn = i
				cm = j
				break
	cntr = 0
	for i in range(n):
		for j in range(m):
			if (i, j) == (cn, cm):
				continue
			if i >= cn and grid[i][j] == 'D':
				cntr += 1
				continue
			if j >= cm and grid[i][j] == 'R':
				cntr += 1
				continue
	return cntr
t = read_int()
for case in range(t):
	(n, m) = read_ints()
	grid = []
	for i in range(n):
		grid.append(input())
	sol = solve(n, m, grid)
	print(sol)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		b = input()
		if i == n - 1:
			ans += b.count('D')
		elif b[-1] == 'R':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(i, j) = map(int, input().split())
	z = 0
	f = 999
	for k in range(i):
		a = list(input())[:j]
		if i == 1:
			x = a.count('D')
			print(x)
			break
		else:
			if a[-1] == 'R':
				f = 0
				z = z + 1
			if k == i - 1:
				f = 0
				m = a.count('D')
		a.clear()
	if f == 0:
		print(z + m)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	strings = list()
	for _ in range(n):
		strings.append(input())
	if n * m == 1:
		print(0)
		continue
	counter = 0
	for i in range(n - 1):
		if strings[i][-1] == 'R':
			counter += 1
	for j in range(m - 1):
		if strings[-1][j] == 'D':
			counter += 1
	print(counter)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	ans = ''
	for _ in range(ii()):
		(n, m) = mi()
		cnt = 0
		for i in range(n):
			s = I().strip()
			if i == n - 1:
				cnt += s.count('D')
			elif s[-1] == 'R':
				cnt += 1
		ans += str(cnt) + '\n'
	print(ans)
main()


t = int(input())
while t:
	(m, n) = [int(x) for x in input().split()]
	mat = []
	for i in range(m):
		s = input()
		mat.append(list(s))
	last_row = mat[-1]
	last_col = []
	for i in range(0, m):
		last_col.append(mat[i][-1])
	c = 0
	for ch in last_row:
		if ch == 'D':
			c += 1
	for ch in last_col:
		if ch == 'R':
			c += 1
	print(c)
	t -= 1


def solve(grid, n, m, ans):
	moves = 0
	for col in range(m - 1):
		if grid[n - 1][col] != 'R':
			grid[n - 1][col] = 'R'
			moves += 1
	for row in range(n - 1):
		if grid[row][m - 1] != 'D':
			grid[row][m - 1] == 'D'
			moves += 1
	ans.append(str(moves))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, m) = map(int, input().split())
		grid = []
		for j in range(n):
			grid.append(list(input()))
		solve(grid, n, m, ans)
	print('\n'.join(ans))
main()


for i in range(int(input())):
	l = []
	(n, m) = map(int, input().split())
	for i in range(n):
		a = list(map(str, input()))
		l.append(a)
	r = 0
	for i in range(m - 1):
		if l[n - 1][i] == 'D':
			r = r + 1
	for i in range(n - 1):
		if l[i][m - 1] == 'R':
			r = r + 1
	print(r)


def main():
	num_tests = int(input())
	for i in range(num_tests):
		dimensions = input().split(' ')
		n = int(dimensions[0])
		m = int(dimensions[1])
		count = 0
		for j in range(n):
			if j == n - 1:
				count += input().count('D')
			elif input()[m - 1] == 'R':
				count += 1
		print(count)
main()


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = []
	c = 0
	for i in range(n):
		s = input()
		if s[-1] == 'R':
			c += 1
		l.append(list(s))
	x = l[-1].count('D')
	c += x
	print(c)


def main():
	for __ in [0] * int(input()):
		(H, W) = map(int, input().split())
		S = [input() for _ in [0] * H]
		ans = 0
		for i in range(H):
			if S[i][W - 1] == 'R':
				ans += 1
		for j in range(W):
			if S[H - 1][j] == 'D':
				ans += 1
		print(ans)
main()


n1 = int(input())
for z in range(n1):
	a = []
	c = 0
	(n, m) = map(int, input().split(' '))
	for i in range(n):
		a.append(input())
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			c += 1
	for i in range(m - 1):
		if a[n - 1][i] != 'R':
			c += 1
	print(c)


def convey(A, n, m):
	count = 0
	for i in range(m - 2, -1, -1):
		if A[n - 1][i] == 'D':
			count += 1
	for j in range(n - 2, -1, -1):
		if A[j][m - 1] == 'R':
			count += 1
			A[j][m - 1] = True
	return count
t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	A = []
	for i in range(n):
		temp = input()
		Z = []
		for i in temp:
			Z.append(i)
		A.append(Z)
	print(convey(A, n, m))


t = int(input())
for h in range(t):
	(m, n) = [int(i) for i in input().split()]
	conv = []
	for i in range(m):
		li = []
		for j in input():
			li.append(j)
		conv.append(li)
	c = 0
	for i in range(m - 1):
		if conv[i][n - 1] == 'R':
			c += 1
	for i in range(n - 1):
		if conv[m - 1][i] == 'D':
			c += 1
	print(c)


def main():
	for _ in range(int(input())):
		(y, x) = [int(i) for i in input().split()]
		counter = 0
		if y > 1:
			for i in range(y - 1):
				if input().endswith('R'):
					counter += 1
		counter += input().count('D')
		print(counter)
main()


for t in range(int(input())):
	(n, m) = map(int, input().split(' '))
	ans = 0
	for ri in range(n - 1):
		r = input()
		ans += 1 if r[-1] == 'R' else 0
	r = input()
	ans += sum((1 if c == 'D' else 0 for c in r))
	print(ans)


import sys
import os.path
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
	sys.stdout = open('out.txt', 'w')
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n - 1):
		s = input()
		if s[-1] == 'R':
			ans += 1
	s = input()
	ans += s.count('D')
	print(ans)


for t in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	cnt = 0
	for i in range(n - 1):
		if input()[-1] == 'R':
			cnt += 1
	l = input()
	for i in l:
		if i == 'D':
			cnt += 1
	print(cnt)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	f = 0
	s = 0
	new = []
	for i in range(n):
		new.append(input())
	for i in range(n):
		for j in range(m):
			if j == m - 1:
				if new[i][j] == 'R':
					f += 1
			if i == n - 1:
				if new[i][j] == 'D':
					f += 1
	print(f)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	for i in range(n):
		a = input()
		if i == n - 1:
			for ele in a:
				if ele == 'D':
					c += 1
		elif a[-1] == 'R':
			c += 1
	print(c)


cases = int(input())
for _ in range(cases):
	(n, m) = map(int, input().split())
	w = []
	for i in range(n):
		w.append(list(input()))
	m = w[-1].count('D')
	w = list(zip(*w))
	m += w[-1].count('R')
	print(m)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	grid = []
	for i in range(n):
		ss = list(input())
		grid.append(ss)
	count = 0
	count += grid[-1].count('D')
	for i in range(n):
		if grid[i][-1] == 'R':
			count += 1
	print(count)


t = int(input())
for i in range(t):
	arr = list(map(int, input().strip().split()))[:2]
	n = arr[0]
	m = arr[1]
	count = 0
	for j in range(n):
		s = input()
		if s[m - 1] is 'R' and j != n - 1:
			count += 1
		elif j == n - 1:
			for k in s:
				if k is 'D':
					count += 1
	print(count)


def fix(grid, m, n):
	if grid == []:
		return 0
	c = 0
	for i in grid:
		if i[-1] == 'R':
			c = c + 1
	for i in grid[-1]:
		if i == 'D':
			c = c + 1
	return c
t = int(input())
while t > 0:
	(m, n) = [int(c) for c in input().split()]
	grid = []
	for i in range(m):
		grid.append(input())
	z = fix(grid, m, n)
	print(z)
	t -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(input())
	count = 0
	for j in range(m):
		if arr[n - 1][j] == 'D' and j != m - 1:
			count += 1
	for k in range(n):
		if arr[k][m - 1] == 'R' and k != n - 1:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	cnt = 0
	for i in range(n):
		linee = input()
		if linee[-1] != 'D':
			cnt += 1
	for i in linee:
		if i != 'R':
			cnt += 1
	print(cnt - 2)


for _ in range(int(input())):
	(n, _) = map(int, input().split())
	result = sum((input()[-1] == 'R' for _ in range(n - 1)))
	result += input().count('D')
	print(result)


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	Matrix = []
	for i in range(N):
		temp = input()
		Matrix.append([i for i in temp])
	Ans = 0
	for i in range(M - 1):
		if Matrix[N - 1][i] == 'D':
			Ans += 1
	for i in range(N - 1):
		if Matrix[i][M - 1] == 'R':
			Ans += 1
	print(Ans)


from sys import stdin, exit
from bisect import bisect_left as bl, bisect_right as br
input = lambda : stdin.readline()[:-1]
intput = lambda : int(input())
sinput = lambda : input().split()
intsput = lambda : map(int, sinput())

def dprint(*args, **kwargs):
	if debugging:
		print(*args, **kwargs)
debugging = 1
t = intput()
for _ in range(t):
	(n, m) = intsput()
	grid = []
	for i in range(n):
		grid.append(input())
	cnt = 0
	for i in range(n):
		if grid[i][-1] == 'R':
			cnt += 1
	for j in range(m):
		if grid[-1][j] == 'D':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, m) = [int(_) for _ in input().split()]
	mat = [input() for _ in range(n)]
	cnt = 0
	for r in range(n - 1):
		if mat[r][-1] != 'D':
			cnt += 1
	for c in range(m - 1):
		if mat[-1][c] != 'R':
			cnt += 1
	print(cnt)


n = int(input())
for _ in range(n):
	a = []
	count = 0
	(i, j) = map(int, input().split())
	for __ in range(i):
		x = input()
		a.append(x)
	if i == 1 and j == 1:
		print(0)
	else:
		for k in range(i):
			if a[k][-1] == 'R':
				count += 1
		y = a[-1].count('D')
		count += y
		print(count)


num = int(input())
for i in range(num):
	arr = input()
	arr = arr.split(' ')
	n = int(arr[0])
	m = int(arr[1])
	count = 0
	for j in range(n):
		text = input()
		if j != n - 1:
			if text[m - 1] != 'D':
				count += 1
		else:
			for k in range(m - 1):
				if text[k] != 'R':
					count += 1
	print(count)


t = int(input())
for _ in range(t):
	inp = input().split()
	n = int(inp[0])
	m = int(inp[1])
	lst = []
	for i in range(n):
		rw = input()
		lst.append(rw)
	cnt = 0
	for i in lst[-1]:
		if i == 'D':
			cnt += 1
	for i in lst:
		if i[-1] == 'R':
			cnt += 1
	print(cnt)


t = int(input())
for i in range(t):
	(m, n) = input().split()
	m = int(m)
	n = int(n)
	k = 0
	for i in range(m - 1):
		s = list(input())[-1]
		if s == 'D':
			k += 1
	s = list(input())
	p = s.count('R')
	print(n - p - 1 + (m - k - 1))


from sys import stdin, stdout
q = int(input())
for i in range(q):
	(n, m) = list(map(int, stdin.readline().split()))
	a = []
	for i in range(n):
		a.append(list(map(str, input())))
	cnt = 0
	for i in range(m - 1):
		if a[n - 1][i] == 'D':
			cnt += 1
	for i in range(n - 1):
		if a[i][m - 1] == 'R':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	M = []
	Cells = 0
	for i in range(n):
		M.append(input())
	for i in range(n - 1):
		if M[i][m - 1] != 'D':
			Cells += 1
	for i in range(m - 1):
		if M[n - 1][i] != 'R':
			Cells += 1
	print(Cells)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	k = 0
	for i in range(n):
		z = input()
		l.append(list(z))
	for j in range(m):
		if l[n - 1][j] == 'D':
			k += 1
	for i in range(n - 1):
		if l[i][m - 1] == 'R':
			k += 1
	print(k)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
while t > 0:
	(n, m) = invr()
	cnt = 0
	ans = 0
	for i in range(n):
		s = input()
		cnt += 1
		if cnt != n:
			if s[-2] == 'R':
				ans += 1
		else:
			for j in range(len(s)):
				if s[j] == 'D':
					ans += 1
	print(ans)
	t -= 1


t = int(input())
for T in range(t):
	(n, m) = [int(i) for i in input().split()]
	ans = 0
	ans += [input()[m - 1] for i in range(n - 1)].count('R')
	ans += input().count('D')
	print(ans)


for tt in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	c = 0
	for i in range(n):
		for j in range(m):
			if j == m - 1:
				if mat[i][j] == 'R':
					c += 1
	for i in range(n):
		for j in range(m):
			if i == n - 1:
				if mat[i][j] == 'D':
					c += 1
	print(c)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	(n, m) = MI()
	g = []
	for __ in range(n):
		g.append(SI())
	ans = 0
	for i in range(n):
		if g[i][m - 1] == 'R':
			ans += 1
	for i in range(m):
		if g[n - 1][i] == 'D':
			ans += 1
	print(ans)


t = int(input(''))
narr = []
for i in range(t):
	arr = []
	[m, n] = list(map(int, input().split()))
	for j in range(m):
		arr.append(input(''))
	narr.append(arr)
for i in narr:
	n = len(i)
	m = len(i[0])
	s = ''
	cnt = 0
	for j in i[n - 1]:
		if j == 'C':
			continue
		elif j == 'D':
			cnt += 1
	for j in range(n - 1):
		if i[j][m - 1] == 'R':
			cnt += 1
	print(cnt)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [input() for x in range(n)]
	count = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			count += 1
	for i in range(m):
		if a[-1][i] == 'D':
			count += 1
	print(count)


def solv():
	(x, y) = map(int, input().split())
	grid = [input() for n in range(x)]
	res = 0
	for n in range(x - 1):
		if grid[n][-1] == 'R':
			res += 1
	for n in range(y - 1):
		if grid[-1][n] != 'R':
			res += 1
	print(res)
for _ in range(int(input())):
	solv()


tc = int(input())
for _ in range(tc):
	(n, m) = map(int, input().split())
	matrix = []
	count = 0
	for i in range(n):
		matrix.append(list(input()))
	for i in range(n):
		if matrix[i][-1] == 'R':
			count += 1
			matrix[i][-1] = 'D'
	for i in range(m):
		if matrix[-1][i] == 'D':
			count += 1
			matrix[-1][i] == 'R'
	print(count)


from bisect import bisect_left, bisect_right
from itertools import combinations
from itertools import permutations
from bisect import bisect_left
from math import ceil
from math import radians
from heapq import heapify, heappush, heappop
import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li1():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0 and i % 2 == 1:
			s.add(i)
			n = n // i
	if n > 2 and n % 2 == 1:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def nextPowerOf2(n):
	count = 0
	if n and (not n & n - 1):
		return n
	while n != 0:
		n >>= 1
		count += 1
	return 1 << count

def cou(n):
	c = 0
	while n > 1:
		c += 1
		n //= 2
	return c

def sortsec(l):
	return sorted(l, key=lambda x: x[1])

def BinarySearch(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def subarray(A):
	r = set()
	p = {0}
	for x in A:
		p = {x | y for y in p} | {x}
		r |= p
	return len(r)
for _ in range(ii()):
	(n, m) = mi()
	l = []
	for i in range(n):
		l.append(si())
	c = 0
	for i in range(n):
		if l[i][-1] == 'R':
			c += 1
	for i in range(m):
		if l[-1][i] == 'D':
			c += 1
	print(c)


n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	ans = list()
	for i in range(a - 1):
		s = input()
		ans.append(s[-1])
	row = list(input())
	count_r = ans.count('R')
	count_d = row.count('D')
	print(count_r + count_d)


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	my_matrix = []
	for i in range(n):
		l = list(input())
		my_matrix.append(l)
	ans = 0
	for i in range(n):
		if my_matrix[i][m - 1] == 'R':
			ans += 1
	for j in range(m):
		if my_matrix[n - 1][j] == 'D':
			ans += 1
	print(ans)


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

def get_int():
	return int(input())
t = get_int()
for zzz in range(t):
	(n, m) = get_ints()
	adj = []
	for i in range(n):
		adj.append(input())
	ret = 0
	for i in range(n):
		if adj[i][m - 1] == 'R':
			ret += 1
	for j in range(m):
		if adj[n - 1][j] == 'D':
			ret += 1
	print(ret)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ls = [list(input()) for _ in range(n)]
	cnt = ls[-1].count('D')
	for i in range(n):
		if ls[i][-1] == 'R':
			cnt += 1
	print(cnt)


def main():
	cases = int(input())
	for case in range(cases):
		fix = 0
		nm = input()
		(n, m) = [int(x) for x in nm.split()]
		if n > 1:
			for j in range(n - 1):
				row = input()
				right = row[-1]
				if right == 'R':
					fix += 1
		bottom = input()
		if m > 1:
			fix += bottom.count('D')
		print(fix)
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ns = [list(input()) for _ in range(n)]
	res = 0
	for i in range(n - 1):
		if ns[i][-1] == 'R':
			res += 1
	for i in range(m - 1):
		if ns[-1][i] == 'D':
			res += 1
	print(res)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = 0
	for i in range(a):
		l = input()
		if i == a - 1:
			for k in l:
				if k == 'D':
					c += 1
		elif l[-1] == 'R':
			c += 1
	print(c)


test_cases = int(input())
for _ in range(test_cases):
	(rows, columns) = map(int, input().split())
	dir_belt = []
	count = 0
	for _ in range(rows):
		dir_belt.append(input())
	for row in range(rows):
		for column in range(columns):
			if row == rows - 1 and column == columns - 1:
				break
			if column == columns - 1 and row < rows - 1:
				if dir_belt[row][column].upper() == 'R':
					dir_belt[row] = dir_belt[row][0:column] + 'D'
					count += 1
			if row == rows - 1 and column < columns - 1:
				if dir_belt[row][column].upper() == 'D':
					dir_belt[row] = dir_belt[row][0:column] + 'R' + dir_belt[row][column + 1:]
					count += 1
	print(count)


from collections import *
from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(t,) = rl()
for _ in range(t):
	(n, m) = rl()
	a = [stdin.readline().rstrip() for _ in range(n)]
	r = 0
	for c in a[-1]:
		if c == 'D':
			r += 1
	for l in a:
		if l[-1] == 'R':
			r += 1
	print(r)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = []
	for i in range(n):
		a.append(input())
	counter = 0
	for i in range(m):
		if a[-1][i] == 'D':
			counter += 1
	for i in range(n):
		if a[i][-1] == 'R':
			counter += 1
	print(counter)


from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007
tc = ii1()
for _ in range(tc):
	(n, m) = iia()
	arr = []
	for i in range(n):
		arr.append(list(is1()))
	count = 0
	for i in arr[-1]:
		if i == 'D':
			count += 1
	for i in range(n):
		if arr[i][-1] == 'R':
			count += 1
	print(count)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	(n, m) = ria()
	l = []
	for i in range(n):
		s = rs()
		l.append(list(s))
	cnt = 0
	for i in range(n - 1):
		if l[i][-1] == 'R':
			cnt += 1
	for i in range(m - 1):
		if l[-1][i] == 'D':
			cnt += 1
	wi(cnt)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	count = 0
	for i in range(a):
		s1 = input()
		if i == a - 1:
			count += s1.count('D')
		elif s1[b - 1] == 'R':
			count += 1
	print(count)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		temp = list(str(input()))
		mat.append(temp)
	if n == 1 and m == 1:
		print(0)
	elif n == 1 and m == 2 and (mat[0][0] == 'R'):
		print(0)
	elif n == 2 and m == 1 and (mat[0][0] == 'D'):
		print(0)
	elif n == 1 and m != 1:
		count = 0
		for i in range(m - 1):
			if mat[0][i] != 'R':
				count += 1
		print(count)
	elif m == 1 and n != 1:
		count = 0
		for i in range(n - 1):
			if mat[i][0] != 'D':
				count += 1
		print(count)
	else:
		count = 0
		for i in range(n - 1):
			if mat[i][m - 1] != 'D':
				count += 1
		for i in range(m - 1):
			if mat[n - 1][i] != 'R':
				count += 1
		print(count)
	t -= 1


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ar = [[-1] * (m + 2) for _ in range(n + 2)]
	for i in range(1, n + 1):
		aa = input()
		for j in range(1, m + 1):
			ar[i][j] = aa[j - 1]
	cnt = 0
	for j in range(1, m + 1):
		if ar[n][j] == 'D':
			cnt += 1
	for i in range(1, n + 1):
		if ar[i][m] == 'R':
			cnt += 1
	print(cnt)


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

def multiple_input():
	return map(int, input().split())
for _ in range(int(input())):
	(n, k) = multiple_input()
	a = []
	b = []
	for i in range(n):
		m = list(input().strip())
		a.append(m[-1])
		if i == n - 1:
			b = m
	count = 0
	for i in range(len(a) - 1):
		if a[i] == 'R':
			count += 1
	for i in range(len(b) - 1):
		if b[i] == 'D':
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append(input())
	answer = 0
	reaches = [[0] * m for i in range(n)]
	reaches[-1][-1] = 1
	for i in reversed(range(n)):
		for j in reversed(range(m)):
			if i == n - 1 and j == m - 1:
				continue
			if grid[i][j] == 'R' and j < m - 1 and reaches[i][j + 1]:
				reaches[i][j] = 1
			elif grid[i][j] == 'D' and i < n - 1 and reaches[i + 1][j]:
				reaches[i][j] = 1
			else:
				reaches[i][j] = 1
				answer += 1
	print(answer)


def solve(n, m, a):
	changes = 0
	for i in range(n):
		if a[i][-1] != 'C':
			if a[i][-1] != 'D':
				changes += 1
	for j in range(m):
		if a[-1][j] != 'C':
			if a[-1][j] != 'R':
				changes += 1
	print(changes)
t = int(input())
while t:
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		line = input()
		a.append(line)
	solve(n, m, a)
	t -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = list((list(input().replace('', ' ').split()) for i in range(a)))
	s = 0
	for i in range(a - 1):
		if c[i][b - 1] != 'D':
			s += 1
	for i in range(b - 1):
		if c[a - 1][i] != 'R':
			s += 1
	print(s)


def moves(matrix):
	count = 0
	for i in range(0, len(matrix) - 1):
		if matrix[i][-1] == 'R':
			count += 1
	for j in range(0, len(matrix[0]) - 1):
		if matrix[-1][j] == 'D':
			count += 1
	return count
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		matrix.append(input())
	print(moves(matrix))


t = int(input())
ans = []
for _ in range(t):
	(n, m) = map(int, input().split(sep=' '))
	matr = []
	for _ in range(n):
		line = list(input())
		matr.append(line)
	ans.append(0)
	for i in range(n - 1):
		if matr[i][m - 1] == 'R':
			ans[-1] += 1
	for j in range(m - 1):
		if matr[n - 1][j] == 'D':
			ans[-1] += 1
for a in ans:
	print(a)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		l = list(str(input()))
		mat.append(l)
	count = 0
	for i in range(n):
		if i != n - 1:
			if mat[i][m - 1] == 'R':
				count += 1
		else:
			for j in range(m - 1):
				if mat[i][j] == 'D':
					count += 1
	print(count)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	R = []
	for r in range(n):
		y = input()
		R.append(y)
	if n == 1 and m == 1:
		print(0)
	else:
		change = 0
		for s in R:
			if s[m - 1] == 'R':
				change += 1
		for c in R[n - 1]:
			if c == 'D':
				change += 1
		print(change)


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	l = []
	for j in range(a):
		s = input()
		k = list(s)
		l.append(k)
	count = 0
	for j in range(0, a - 1):
		if l[j][b - 1] == 'R':
			count += 1
	for j in range(0, b - 1):
		if l[a - 1][j] == 'D':
			count += 1
	print(count)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

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

def solve():
	(n, m) = rl()
	grid = []
	for i in range(n):
		grid.append(input())
	change = 0
	for i in range(n):
		if grid[i][-1] == 'R':
			change += 1
	for j in range(m):
		if grid[-1][j] == 'D':
			change += 1
	print(change)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


t = int(input())
for i in range(t):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	count = 0
	for i in range(n - 1):
		s = input()
		if s[m - 1] == 'R':
			count += 1
	lastrow = input()
	count += lastrow.count('D')
	print(count)


t = int(input())
while t:
	t = t - 1
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		s = input()
		l.append(list(s))
	cnt = 0
	for i in range(0, n - 1):
		if l[i][m - 1] != 'D':
			cnt += 1
	for i in range(0, m - 1):
		if l[n - 1][i] != 'R':
			cnt += 1
	print(cnt)


import math
num_cases = int(input())
for _ in range(num_cases):
	(m, n) = list(map(int, input().strip().split()))
	arr = []
	for i in range(m):
		temp = list(input().strip())
		arr.append(temp)
	arr[m - 1][n - 1] = '1'
	count = 0
	for j in range(n - 2, -1, -1):
		if arr[m - 1][j] == 'D':
			count += 1
			arr[m - 1][j] = '1'
	for i in range(0, m - 1):
		if arr[i][n - 1] == 'R':
			count += 1
			arr[i][n - 1] = '1'
	print(count)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append(input())
	ans = 0
	for i in range(n):
		for j in range(m):
			if i == n - 1 and grid[i][j] == 'D':
				ans += 1
			if j == m - 1 and grid[i][j] == 'R':
				ans += 1
	print(ans)


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	(n, m) = I()
	l = []
	for i in range(n):
		s = I1()
		l.append(s)
	c = 0
	for i in range(n):
		for j in range(m):
			if j == m - 1 and l[i][j] == 'R':
				c += 1
			elif i == n - 1 and l[i][j] == 'D':
				c += 1
	print(c)


import sys
from collections import defaultdict
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	g = []
	for i in range(n):
		g.append(list(input()))
	c = 0
	for i in g[-1]:
		if i == 'D':
			c += 1
	for i in g:
		if i[-1] == 'R':
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	change = 0
	(n, m) = map(int, input().split())
	for i in range(n - 1):
		if input()[-1] != 'D':
			change += 1
	tmp = input()
	change += m - 1 - tmp[:-1].count('R')
	print(change)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = [input() for _ in range(n)]
	ans = 0
	ans += matrix[-1][:-1].count('D')
	ans += [row[-1] for row in matrix[:-1]].count('R')
	print(ans)


def travel(grid, traversed, i, j):
	count = 0
	while not traversed[i][j]:
		traversed[i][j] = True
		if grid[i][j] == 1:
			j += 1
		elif grid[i][j] == 0:
			i += 1
		else:
			return count
		if j == m:
			j -= 1
			grid[i][j] = 0
			count += 1
			i += 1
		elif i == n:
			i -= 1
			grid[i][j] = 1
			count += 1
			j += 1
	return count
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	traversed = [[False] * m for i in range(n)]
	grid = []
	d = {'R': 1, 'D': 0, 'C': -1}
	for i in range(n):
		temp = input()
		t2 = []
		for x in temp:
			t2.append(d[x])
		grid.append(t2)
	traversed[-1][-1] = True
	count = 0
	for (i, v) in enumerate(traversed):
		for (j, w) in enumerate(v):
			if not w:
				count += travel(grid, traversed, i, j)
	print(count)


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	for j in range(n):
		s = list(input())
		if s[-1] == 'R':
			ans += 1
		if j == n - 1:
			ans += s.count('D')
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [list(input()) for i in range(n)]
	ans = 0
	for i in range(n - 1):
		ans += a[i][m - 1] != 'D'
	for j in range(m - 1):
		ans += a[n - 1][j] != 'R'
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(input())
	ans = 0
	for j in range(m - 2, -1, -1):
		if mat[n - 1][j] == 'R':
			continue
		else:
			ans += 1
	for j in range(n - 2, -1, -1):
		if mat[j][m - 1] != 'D':
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = [int(i) for i in input().split()]
	matrix = []
	for i in range(n):
		matrix.append([i for i in input()])
	ds = 0
	for i in matrix[-1]:
		if i == 'D':
			ds += 1
	rs = 0
	for i in range(n):
		if matrix[i][-1] == 'R':
			rs += 1
	print(ds + rs)


t = int(input())
for __ in range(t):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append(input())
	c = 0
	for i in range(m - 1):
		if grid[-1][i] == 'D':
			c += 1
	for i in range(n - 1):
		if grid[i][-1] == 'R':
			c += 1
	print(c)


import sys
from math import sqrt, gcd, ceil, log, floor
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def f(n):
	return pow(2, n, MOD) - 1

def f2(n, i):
	ans = 0
	for j in range(1, i + 1):
		ans += ncr(n, j, MOD)
	return ans

def main():
	ans_ = []
	for _ in range(int(input())):
		(n, m) = read()
		mat = []
		for i in range(n):
			mat.append(list(input().strip()))
		ans = 0
		for i in range(n - 1):
			ans += mat[i][m - 1] != 'D'
		for j in range(m - 1):
			ans += mat[n - 1][j] != 'R'
		ans_.append(str(ans))
	print('\n'.join(ans_))
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	v = []
	cnt = 0
	for i in range(n):
		s = input()
		if s[-1] == 'R':
			cnt += 1
		v.append(s)
	cnt += v[-1].count('D')
	print(cnt)


t = int(input())
cnt = 0
while cnt < t:
	cnt += 1
	(n, m) = [int(i) for i in input().split()]
	total = 0
	a = [[i for i in input()] for j in range(n)]
	for i in range(m - 1):
		if a[n - 1][i] != 'R':
			total += 1
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			total += 1
	print(total)


import bisect
import math
import heapq
import random

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int, rev=False):
	return sorted(map(func, input().split()), reverse=rev)

def ml_unpack(n):
	return [int(input()) for _ in range(n)]

def range_n():
	return range(int(input()))

def getint():
	return int(input())

def counter(a):
	d = {}
	for x in a:
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	return d

def factor(n):
	d = {}
	while not n % 2:
		d[2] = d.get(2, 0) + 1
		n //= 2
	i = 3
	while i * i <= n:
		while not n % i:
			d[i] = d.get(i, 0) + 1
			n //= i
		i += 2
	if n > 1:
		d[n] = d.get(n, 0) + 1
	return d

def main():
	for _ in range_n():
		(n, m) = unpack()
		a = [input() for i in range(n)]
		cnt = 0
		for i in range(n):
			if a[i][m - 1] == 'R':
				cnt += 1
		cnt += a[n - 1].count('D')
		print(cnt)
main()


for _ in range(int(input())):
	(n, m) = list(map(int, input().split(' ')))
	s = ''
	count = 0
	for i in range(n):
		s = input()
		if i < n - 1:
			if s[-1] != 'D':
				count += 1
		else:
			for j in s:
				if j != 'R' and j != 'C':
					count += 1
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	downs = 0
	for i in range(n):
		row = input()
		if i < n - 1 and row[-1] != 'D':
			downs += 1
	rights = 0
	for c in row[:-1]:
		if c != 'R':
			rights += 1
	print(downs + rights)


import math
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(1, n + 1):
		tem = list(input())
		if i < n:
			if tem[m - 1] == 'R':
				ans += 1
		else:
			for i in range(m - 1):
				if tem[i] == 'D':
					ans += 1
	print(ans)


t = int(input())
ans = 0
for i in range(t):
	ans = 0
	(n, m) = list(map(int, input().split()))
	for j in range(n - 1):
		s = input()
		ans = ans + (s[len(s) - 1] == 'R')
	s = input()
	ans = ans + s.count('D')
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 0
	for i in range(0, a - 1):
		l = list(input())
		if l[-1] == 'R':
			ans += 1
	l = list(input())
	ans += l.count('D')
	print(ans)


t = int(input())

def Find(x, par):
	if par[x] < 0:
		return x
	else:
		par[x] = Find(par[x], par)
		return par[x]

def Unite(x, y, par, rank):
	x = Find(x, par)
	y = Find(y, par)
	if x != y:
		if rank[x] < rank[y]:
			par[y] += par[x]
			par[x] = y
		else:
			par[x] += par[y]
			par[y] = x
			if rank[x] == rank[y]:
				rank[x] += 1

def Same(x, y, par):
	return Find(x, par) == Find(y, par)

def Size(x, par):
	return -par[Find(x, par)]
for _ in range(t):
	(n, m) = map(int, input().split())
	A = [list(str(input())) for _ in range(n)]
	par = [-1] * (n * m)
	rank = [0] * (n * m)
	for i in range(n):
		for j in range(m):
			idx = i * m + j
			if A[i][j] == 'R':
				if j != m - 1:
					idx2 = i * m + j + 1
					Unite(idx, idx2, par, rank)
			elif A[i][j] == 'D':
				if i != n - 1:
					idx2 = (i + 1) * m + j
					Unite(idx, idx2, par, rank)
			else:
				pass
	cnt = 0
	for i in range(n * m):
		if par[i] < 0:
			cnt += 1
	print(cnt - 1)


for i in range(int(input())):
	(n, m) = tuple(map(int, input().split()))
	t = 0
	for j in range(1, n + 1):
		n1 = input()
		if j == n:
			t += n1.count('D')
		elif n1[-1] == 'R':
			t += 1
	print(t)


from io import BytesIO, IOBase
import sys
import math
import os
from collections import defaultdict as dd
from math import ceil
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

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

def mint():
	return map(int, input().split())

def mfloat():
	return map(float, input().split())

def solve():
	(n, m) = mint()
	lis = []
	for i in range(n):
		lis.append(input())
	res = 0
	for i in range(m - 1):
		if lis[n - 1][i] == 'D':
			res += 1
	for i in range(n - 1):
		if lis[i][m - 1] == 'R':
			res += 1
	print(res)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
from math import ceil, factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest, nsmallest
from itertools import groupby
MOD = 10 ** 9 + 7
INF = float('inf')
rl = lambda : list(map(int, sys.stdin.readline().split()))
rs = lambda : sys.stdin.readline().strip()

def check(i, j, cnt):
	if direction[i][j] == 'C':
		return cnt
	if direction[i][j] == 'D':
		if i + 1 >= n:
			direction[i][j] = 'R'
			return check(i, j + 1, cnt + 1)
		else:
			return check(i + 1, j, cnt)
	elif j + 1 >= m:
		direction[i][j] = 'D'
		return check(i + 1, j, cnt + 1)
	else:
		return check(i, j + 1, cnt)
for _ in range(int(input())):
	(n, m) = rl()
	direction = [[s for s in rs()] for _ in range(n)]
	cnt = 0
	for i in range(n):
		for j in range(m):
			cnt += check(i, j, 0)
	print(cnt)


n = int(input())
for i in range(n):
	result = 0
	(rows_in, cols_in) = map(int, input().split())
	data = [input() for i in range(rows_in)]
	for i in data[:-1]:
		if i[-1] == 'R':
			result += 1
	result += data[-1].count('D')
	print(result)


def solution(n, m, rows):
	count = 0
	for _ in range(n - 1):
		if rows[_][m - 1] == 'R':
			count += 1
	for _ in range(m - 1):
		if rows[n - 1][_] == 'D':
			count += 1
	return count
tests = int(input())
for _ in range(tests):
	(n, m) = list(map(int, input().strip().split()))
	rows = []
	for i in range(n):
		rows.append(input().strip())
	print(solution(n, m, rows))


t = int(input())
As = []
for e in range(t):
	(n, m) = [int(i) for i in input().split(' ')]
	A = []
	for i in range(n):
		arr = [ch for ch in input()]
		A.append(arr)
	As.append(A)
for A in As:
	Mem = [[0 for j in range(len(row))] for row in A]
	counter = 0
	for i in range(len(A)):
		for j in range(len(A[0])):
			if Mem[i][j]:
				continue
			(i1, j1) = (i, j)
			while True:
				if Mem[i][j]:
					break
				Mem[i1][j1] = 1
				if A[i1][j1] == 'R':
					j1 += 1
				elif A[i1][j1] == 'D':
					i1 += 1
				elif A[i1][j1] == 'C':
					break
				if i1 == len(A) and j1 == len(A[0]):
					break
				elif i1 == len(A):
					i1 -= 1
					A[i1][j1] = 'R'
					counter += 1
				elif j1 == len(A[0]):
					j1 -= 1
					A[i1][j1] = 'D'
					counter += 1
	print(counter)


from collections import Counter

def solve(n, m):
	step = 0
	for i in range(n):
		st = input()
		if st[m - 1] == 'R':
			step += 1
		if i == n - 1:
			for j in range(m):
				if st[j] == 'D':
					step += 1
	return step
t = int(input())
ans = []
for i in range(t):
	[n, m] = list(map(int, input().split()))
	ans.append(solve(n, m))
print(*ans, sep='\n')


n = int(input())
for __ in range(n):
	dim = [int(_) for _ in input().split()]
	grid = []
	for i in range(dim[0]):
		grid.append(input())
	lastcolumn = ''
	lastrow = grid[-1]
	for i in range(len(grid)):
		lastcolumn += grid[i][-1]
	print(lastcolumn.count('R') + lastrow.count('D'))


from math import gcd
from sys import stdin
from collections import Counter, deque
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	for i in range(n - 1):
		a = list(input())
		if a[m - 1] == 'R':
			c = c + 1
	a = list(input())
	for i in range(len(a)):
		if a[i] == 'D':
			c = c + 1
	print(c)


import sys, math
try:
	(sys.stdin, sys.stdout) = (open('input.txt', 'r'), open('out.txt', 'w'))
except:
	pass
from sys import stdin, stdout
mod = int(1000000000.0 + 7)
from statistics import mode
from collections import *
from math import ceil, floor, inf, factorial, gcd, log2, sqrt, log
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()

def lcm(a, b):
	return a * b // gcd(a, b)

def setbits(n):
	return bin(n).count('1')

def resetbits(n):
	return bin(n).count('0')

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r):
	(num, den) = (1, 1)
	r = min(n, n - r)
	for i in range(r):
		num *= n - i
		den *= i + 1
	return num // den

def ncr_p(n, r, p):
	(num, den) = (1, 1)
	r = min(r, n - r)
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * modinv(den, p) % p

def isPrime(num):
	if num <= 1:
		return False
	if num == 2 or n == 3:
		return True
	if num % 2 == 0 or num % 3 == 0:
		return False
	m = int(num ** 0.5) + 1
	for i in range(5, m, 6):
		if num % i == 0 or num % (i + 2) == 0:
			return False
	return True

def bin_search(arr, low, high, val):
	while low <= high:
		mid = low + (high - low) // 2
		if arr[mid] == val:
			return mid
		elif arr[mid] < val:
			low = mid + 1
		else:
			high = mid - 1
	return -1

def sumofdigit(num):
	count = 0
	while num:
		count += num % 10
		num //= 10
	return count

def inputmatrix():
	(r, c) = iia()
	mat = [0] * r
	for i in range(r):
		mat[i] = iia()
	return (r, c, mat)

def prefix_sum(n, arr):
	for i in range(1, n):
		arr[i] += arr[i - 1]
	return arr

def binomial(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def divisors(n):
	res = []
	for i in range(1, ceil(sqrt(n)) + 1):
		if n % i == 0:
			if i == n // i:
				res.append(i)
			else:
				res.append(i)
				res.append(n // i)
	return res
for i in range(ii1()):
	(n, m) = iia()
	arr = [[] for i in range(n)]
	for i in range(n):
		arr[i] = is1()
	ans = 0
	if arr[0][-1] == 'R':
		ans += 1
	for i in range(1, n - 1):
		if arr[i][-1] == 'R':
			ans += 1
	for i in range(m):
		if arr[n - 1][i] == 'D':
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	s = 0
	for i in range(n):
		a = input()
		if a[m - 1] == 'R' and i < n - 1:
			s += 1
		if i == n - 1:
			s += a.count('D')
	print(s)


import sys
import heapq
import math
from collections import deque
from collections import defaultdict
from collections import Counter
modH = int(10 ** 9) + 7
I = lambda : list(map(int, input().split(' ')))

def PRINT(lst, sep=' '):
	print(sep.join(map(str, lst)))
for _ in range(int(input())):
	(n, m) = I()
	lst = [list(input()) for i in range(n)]
	cnt = 0
	for i in range(n - 1):
		if lst[i][-1] == 'R':
			cnt += 1
	for i in range(m - 1):
		if lst[-1][i] == 'D':
			cnt += 1
	print(cnt)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	count = 0
	for i in range(n):
		ar = list(input())
		if ar[-1] == 'R':
			count += 1
		arr.append(ar)
	down = arr[-1].count('D')
	count += down
	print(count)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	(h, w) = MI()
	aa = [SI() for _ in range(h)]
	ans = 0
	for i in range(h - 1):
		if aa[i][-1] == 'R':
			ans += 1
	for j in range(w - 1):
		if aa[-1][j] == 'D':
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		s = list(input())
		arr.append(s)
	ans = 0
	for i in range(n):
		if i != n - 1:
			if arr[i][-1] != 'D':
				ans += 1
		else:
			for j in range(m - 1):
				if arr[i][j] == 'D':
					ans += 1
	print(ans)


t = int(input())
for i in range(t):
	x = input()
	n = int(x.split()[0])
	m = int(x.split()[1])
	k = 0
	for j in range(n - 1):
		y = input()
		if y[-1] == 'R':
			k = k + 1
	z = input()
	for j in range(m - 1):
		if z[j] == 'D':
			k = k + 1
	print(k)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = []
	c = 0
	for i in range(n):
		s = input()
		if s[-1] == 'R':
			c += 1
		li.append(s)
	for i in li[-1]:
		if i == 'D':
			c += 1
	print(c)


def main():
	ntests = int(input())
	for i in range(ntests):
		(n, m) = input().split()
		n = int(n)
		m = int(m)
		grid = []
		changes = 0
		for j in range(n):
			grid.append(list(input()))
		for j in range(n - 1):
			if grid[j][m - 1] != 'D':
				grid[j][m - 1] = 'D'
				changes += 1
		for letter in range(m - 1):
			if grid[n - 1][letter] != 'R':
				grid[n - 1][letter] = 'R'
				changes += 1
		print(changes)
main()


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	mat = []
	ans = 0
	for j in range(n):
		row = input()
		mat.append(row)
	for j in range(n - 1):
		if mat[j][m - 1] == 'R':
			ans += 1
	j = mat[n - 1]
	for k in range(len(j)):
		if j[k] == 'D':
			ans += 1
	print(ans)


import sys
import math
from math import *
from collections import defaultdict, Counter
import os
from io import BytesIO, IOBase
from collections import deque
import bisect
from copy import deepcopy

def main():
	(n, m) = list(map(int, input().split()))
	grid = []
	for i in range(n):
		grid.append(list(input()))
	c = 0
	for i in range(n):
		if grid[i][-1] == 'R':
			c += 1
	for i in range(m):
		if grid[-1][i] == 'D':
			c += 1
	print(c)
for i in range(int(input())):
	main()


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

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

def MI():
	return map(int, input().split())

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

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def Ra():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
show_flg = False
show_flg = True
ans = 0
for _ in range(I()):
	ans = 0
	(n, m) = LI()
	for i in range(n - 1):
		s = input()
		if s[-1] == 'R':
			ans += 1
	s = input()
	ans += s.count('D')
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = list(map(lambda x: int(x), input().split()))
	rows = []
	for i in range(n):
		rows.append(input())
	counter = 0
	for j in range(0, m - 1):
		if rows[-1][j] == 'D':
			counter += 1
	for j in range(0, n - 1):
		if rows[j][-1] == 'R':
			counter += 1
	print(counter)


t = int(input())
b = []
for i in range(t):
	(n, m) = map(int, input().split(' '))
	a = []
	for j in range(n):
		a.append(input())
	cnt = 0
	(ii, jj) = (0, 0)
	for p in range(max(n, m) * max(n, m)):
		try:
			if a[p][m - 1] == 'R':
				cnt += 1
		except:
			pass
		try:
			if a[n - 1][p] == 'D':
				cnt += 1
		except:
			pass
	b.append(cnt)
for i in b:
	print(i)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	s = 0
	if n > 1 and m > 1:
		st = str(input())
		if st[-1] == 'R':
			s += 1
		for i in range(1, n - 1):
			st = str(input())
			if st[-1] == 'R':
				s += 1
		st = str(input())
		for i in range(m - 1):
			if st[i] == 'D':
				s += 1
	elif n == 1 and m > 1:
		st = str(input())
		for i in range(m - 1):
			if st[i] == 'D':
				s += 1
	elif m == 1 and n > 1:
		for i in range(n):
			st = str(input())
			if st[-1] == 'R':
				s += 1
	else:
		st = str(input())
	print(s)


import math
testcases = int(input())
while testcases > 0:
	(n, m) = map(int, input().split())
	myArray = []
	for i in range(n):
		myString = input()
		myArray.append(myString)
	i = 0
	j = m - 1
	count = 0
	while i < n - 1:
		if myArray[i][j] == 'R':
			count += 1
		i += 1
	i = n - 1
	j = 0
	while j < m - 1:
		if myArray[i][j] == 'D':
			count += 1
		j += 1
	print(count)
	testcases -= 1


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	g = []
	for i in range(n):
		g.append([i for i in input().strip()])
	ct = 0
	for i in range(n):
		if g[i][-1] == 'R':
			ct += 1
	for j in range(m):
		if g[-1][j] == 'D':
			ct += 1
	print(ct)


def mine(lt):
	mi = lt[0]
	for i in range(len(lt)):
		if lt[i] < mi:
			mi = lt[i]
	return mi
q = int(input())
for d in range(q):
	(n, m) = map(int, input().split(' '))
	lt = []
	for i in range(n):
		temp = str(input())
		lt.append(temp)
	ans = 0
	for i in range(len(lt)):
		if lt[i][m - 1] == 'R':
			ans = ans + 1
	for i in range(m):
		if lt[n - 1][i] == 'D':
			ans = ans + 1
	print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		(n, m) = mi()
		a = []
		for i in range(n):
			a.append(si())
		ans = 0
		for i in range(m):
			if a[n - 1][i] == 'D':
				ans += 1
		for i in range(n):
			if a[i][m - 1] == 'R':
				ans += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	(n, m) = get_tuple()
	ans = 0
	for _ in range(n - 1):
		st = input()
		if st[-1] == 'R':
			ans += 1
	st = input()
	for val in st:
		if val == 'D':
			ans += 1
	print(ans)

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	last_column = []
	for i in range(n - 1):
		last_column.append(input()[m - 1])
	last_row = input()
	last_column.append(last_row[m - 1])
	print(last_row.count('D') + last_column.count('R'))


t = int(input())
for tc in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	k = []
	for i in range(n):
		s = input()
		s = list(s)
		k.append(s)
	for i in range(n):
		for j in range(m):
			p = k[i][j]
			if p == 'C':
				continue
			if i == n - 1 and p == 'D':
				ans += 1
			if j == m - 1 and p == 'R':
				ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	board = []
	for row in range(n):
		board.append(list(input()))
	mistakes = 0
	for j in range(m - 1):
		if board[n - 1][j] != 'R':
			mistakes += 1
	for i in range(n - 1):
		if board[i][m - 1] != 'D':
			mistakes += 1
	print(mistakes)


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(n, m) = map(int, input().split())
	ll = []
	cou = 0
	for i in range(n):
		ll.append(input().split()[0])
	for i in range(n):
		if ll[i][m - 1] == 'R':
			cou += 1
	for i in range(m):
		if ll[n - 1][i] == 'D':
			cou += 1
	print(cou)
	t -= 1


ls = []
t = int(input())
for z in range(t):
	mn = list(map(int, input().rstrip().split()))
	m = mn[0]
	n = mn[1]
	s = []
	count = 0
	for i in range(m):
		sin = input()
		s.append(sin)
	for i in range(m - 1):
		if s[i][-1] == 'R':
			count += 1
	for i in range(n - 1):
		if s[m - 1][i] == 'D':
			count += 1
	ls.append(count)
for i in ls:
	print(i)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	cnt = 0
	for i in range(n):
		x = input()
		if i != n - 1 and x[m - 1] != 'D':
			cnt += 1
		if i == n - 1:
			for j in range(m - 1):
				if x[j] != 'R':
					cnt += 1
	print(cnt)


def single(n, m):
	count = 0
	for i in range(n - 1):
		temp = input()
		if temp[-1] == 'R':
			count += 1
	temp = input()
	for char in temp:
		if char == 'D':
			count += 1
	print(count)
t = int(input())
for i in range(t):
	(n, m) = tuple(map(int, input().split(' ')))
	single(n, m)


for _ in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	l = []
	for i in range(a):
		k = list(input())
		l.append(k)
	count = 0
	count += l[-1].count('D')
	for i in l:
		if i[-1] == 'R':
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(input())
	count = 0
	for i in range(m - 1):
		if mat[-1][i] == 'D':
			count += 1
	for i in range(n - 1):
		if mat[i][-1] == 'R':
			count += 1
	print(count)


res = ''
for _ in range(int(input())):
	a = []
	(n, m) = map(int, input().split())
	for _ in range(n):
		a += [input()]
	(n, m) = (n - 1, m - 1)
	count = 0
	for (a, i) in zip(a, range(n + 1)):
		if a[m] == 'R':
			count += 1
		if i == n:
			for row in a:
				if row == 'D':
					count += 1
	res += f'{count}\n'
print(res)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		b = input().strip()
		a.append(b)
	count_1 = 0
	count_2 = 0
	for i in range(m - 1):
		if a[n - 1][i] != 'R':
			count_1 += 1
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			count_1 += 1
	print(count_1)


t = int(input())
for ex in range(t):
	(n, m) = [int(i) for i in input().split()]
	a = list()
	for i in range(n):
		a.append(input())
	ans = 0
	for i in range(n - 1):
		if a[i][m - 1] == 'R':
			ans += 1
	for i in range(m - 1):
		if a[n - 1][i] == 'D':
			ans += 1
	print(ans)


t = int(input())
ans = []
for _ in range(t):
	[n, m] = list(map(int, input().split()))
	belt = []
	for _ in range(n):
		belt.append(input())
	changes = 0
	for col in range(m - 1):
		changes += int(belt[n - 1][col] == 'D')
	for row in range(n - 1):
		changes += int(belt[row][m - 1] == 'R')
	ans.append(changes)
for no in ans:
	print(no)


T = int(input())
while T > 0:
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append(input())
	res = 0
	for i in range(n):
		if grid[i][-1] == 'R':
			res += 1
	for i in range(m):
		if grid[-1][i] == 'D':
			res += 1
	print(res)
	T -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split(' '))
	arr = []
	ans = 0
	for i in range(n):
		arr.append([w for w in input()])
	for j in range(m):
		if arr[n - 1][j] == 'D':
			ans = ans + 1
	for i in range(n):
		if arr[i][m - 1] == 'R':
			ans = ans + 1
	print(ans)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def solve(n, m, a):
	cnt = 0
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			cnt += 1
	for j in range(m - 1):
		if a[n - 1][j] != 'R':
			cnt += 1
	return cnt

def main():
	for _ in range(ri()):
		(n, m) = ria()
		a = []
		for i in range(n):
			a.append(rs())
		wi(solve(n, m, a))
main()


def followRoute(grid, r, c, m, n):
	if r == m - 1 and c == n - 1:
		return 0
	dir = abs(grid[r][c])
	if grid[r][c] > 0:
		grid[r][c] *= -1
	if dir == 1:
		(nr, nc) = (r, c + 1)
	else:
		(nr, nc) = (r + 1, c)
	if 0 <= nr < m and 0 <= nc < n:
		return followRoute(grid, nr, nc, m, n)
	else:
		if dir == 1:
			grid[r][c] = -2
			(nr, nc) = (r + 1, c)
		else:
			grid[r][c] = -1
			(nr, nc) = (r, c + 1)
		return 1 + followRoute(grid, nr, nc, m, n)

def makeFunctional(grid):
	if not grid or not grid[0]:
		return 0
	m = len(grid)
	n = len(grid[0])
	flips = 0
	for r in range(m):
		for c in range(n):
			if r == m - 1 and c == n - 1:
				break
			if grid[r][c] > 0:
				flips += followRoute(grid, r, c, m, n)
	return flips

def mapp(val):
	if val == 'R':
		return 1
	if val == 'D':
		return 2
	if val == 'C':
		return 3
N = int(input())
for g in range(N):
	[m, n] = list(map(int, input().split(' ')))
	grid = []
	for r in range(m):
		grid.append(list(map(mapp, list(input()))))
	print(makeFunctional(grid))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lastCol = ''
	lastRow = ''
	for i in range(n):
		if i == n - 1:
			lastRow = input()
			continue
		row = input()
		lastCol += row[m - 1]
	print(lastCol.count('R') + lastRow.count('D'))


T = int(input())
for _ in range(T):
	(N, M) = [int(x) for x in input().split()]
	arr1 = []
	for k in range(N - 1):
		arr1.append(list(input()).pop())
	arr2 = list(input())
	arr2.pop()
	print(arr1.count('R') + arr2.count('D'))


a = int(input())
for i in range(a):
	sch = 0
	f = str(input()).split(' ')
	for j in range(int(f[0]) - 1):
		c = list(str(input()))
		if str(c[int(f[1]) - 1]) == 'R':
			sch += 1
	c = list(str(input()))
	sch += c.count('D')
	print(sch)


I = input
exec('print(sum(I()[-1]=="R"for _ in[0]*(int(I().split()[0])-1))+I().count("D"));' * int(I()))


from sys import stdin, stdout
input = lambda : stdin.readline().strip()
for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	lst = []
	for i in range(0, n):
		lst.append(input())
	nd = 0
	for i in range(0, n - 1):
		if lst[i][m - 1] != 'D':
			nd += 1
	for i in range(0, m - 1):
		if lst[n - 1][i] != 'R':
			nd += 1
	print(nd)


for I in range(int(input())):
	(n, m) = map(int, input().split())
	count = 0
	for i in range(n):
		s = input()
		if s[-1] == 'R':
			count += 1
	count += s.count('D')
	print(count)


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	count = 0
	for i in range(r):
		s = input()
		if i + 1 == r:
			for j in s:
				if j != 'R':
					count += 1
		if s[-1] != 'D':
			count += 1
	print(count - 2)


from sys import stdin, stdout
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		t = input().strip()
		if t[-1] == 'R':
			ans += 1
	t = t[:-1]
	for i in t:
		if i == 'D':
			ans += 1
	print(ans)


for t in range(int(input())):
	(r, c) = map(int, input().split())
	mat = []
	for i in range(r):
		s = input()
		mat.append(s)
	cnt = 0
	if r == 1 and c == 1:
		print(0)
	else:
		for i in range(c - 1):
			if mat[r - 1][i] == 'D':
				cnt += 1
		for i in range(r - 1):
			if mat[i][c - 1] == 'R':
				cnt += 1
		print(cnt)


for _ in [0] * int(input()):
	(n, m) = map(int, input().split())
	arr = [list(input()) for i in [0] * n]
	print(len([j for j in range(n - 1) if arr[j][m - 1] != 'D']) + len([k for k in range(m - 1) if arr[n - 1][k] != 'R']))


test = int(input())
for _ in range(test):
	(n, m) = map(int, input().split())
	list1 = []
	for i in range(n):
		list1.append(list(input()))
	count = 0
	count1 = 0
	for i in range(n):
		if list1[i][m - 1] == 'R':
			count += 1
	for i in range(m):
		if list1[n - 1][i] == 'D':
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	a = []
	c = 0
	(n, m) = map(int, input().split(' '))
	a = [list(input()) for x in range(n)]
	for x in range(n):
		if x == n - 1:
			for xx in range(m - 1):
				if a[x][xx] == 'D':
					c = c + 1
		elif a[x][-1] != 'D':
			c = c + 1
	print(c)


import sys
import math

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, m) = get_ints()
	z = []
	for i in range(n):
		z.append(input())
	ans1 = 0
	ans2 = 0
	for j in range(n):
		if z[j][m - 1] == 'R':
			ans1 += 1
		else:
			continue
	for k in range(m):
		if z[n - 1][k] == 'D':
			ans2 += 1
		else:
			continue
	print(ans1 + ans2)


T = int(input())
for x in range(T):
	(n, m) = map(int, input().split(' '))
	grid = []
	for j in range(n):
		row = input()
		grid.append(row)
	(i, j) = (0, 0)
	changes = 0
	i = n - 1
	for j in range(m - 1):
		if grid[i][j] == 'D':
			changes += 1
		else:
			pass
	j = m - 1
	for i in range(n - 1):
		if grid[i][j] == 'R':
			changes += 1
		else:
			pass
	print(changes)


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

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

def inSList():
	return input().split()

def getTable(table, i, j):
	s = table[i]
	return s[j]

def solve(table, n, m):
	ret = 0
	if getTable(table, n - 1, m - 1) != 'C':
		ret += 1
	for i in range(0, n - 1):
		if getTable(table, i, m - 1) != 'D':
			ret += 1
	for i in range(0, m - 1):
		if getTable(table, n - 1, i) != 'R':
			ret += 1
	return ret
t = inInt()
for i in range(t):
	pair = inIList()
	n = pair[0]
	m = pair[1]
	table = []
	for i in range(n):
		table.append(inStr())
	print(solve(table, n, m))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def print_fract(p, q):
	g = math.gcd(p, q)
	p //= g
	q //= g
	print(str(p) + '/' + str(q))
p = 1000000007
T = inp()
for t in range(T):
	(N, M) = invr()
	grid = []
	for n in range(N):
		grid.append(insr())
	out = 0
	for m in range(M):
		if grid[-1][m] == 'D':
			out += 1
	for n in range(N):
		if grid[n][-1] == 'R':
			out += 1
	print(out)


n = int(input())
for i in range(n):
	(a, l) = [int(x) for x in input().split()]
	c = 0
	for i in range(a):
		w = input()
		if w[-1] == 'R':
			c += 1
	if 'D' in w:
		c += w.count('D')
	print(c)


from sys import stdin, stdout
for _ in ' ' * int(stdin.readline()):
	(a, b) = map(int, stdin.readline().split())
	s = 0
	for i in range(a):
		z = input()
		if i == a - 1:
			s += z.count('D')
		else:
			s += 1 if z[-1] == 'R' else 0
	print(s)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = ip()
for _ in range(t):
	(n, m) = inp()
	arr = []
	for i in range(n):
		s = ips()
		arr.append(s)
	ans = 0
	for i in range(n):
		if arr[i][-1] == 'R':
			ans += 1
	for i in range(m):
		if arr[-1][i] == 'D':
			ans += 1
	print(ans)


n = int(input())
for t in range(n):
	x = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for i in range(x[0]):
		s = input()
		l = list(s)
		if l[x[1] - 1] == 'R':
			count1 += 1
		if i == x[0] - 1:
			for j in range(x[1]):
				if l[j] == 'D':
					count2 += 1
	print(count1 + count2)


t = int(input())
for _ in range(t):
	(row, col) = map(int, input().split())
	mat = []
	count = 0
	for x in range(row):
		mat.append(list(input()))
	for i in range(col - 1):
		if mat[row - 1][i] == 'D':
			count += 1
	for i in range(row - 1):
		if mat[i][col - 1] == 'R':
			count += 1
	print(count)


import sys
input = sys.stdin.buffer.readline
from collections import deque as que, defaultdict as vector, Counter
from bisect import bisect as bsearch
from heapq import *
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
INF = float('inf')
_T_ = inin()
for _t_ in range(_T_):
	(n, m) = inar()
	belt = []
	for i in range(n):
		belt.append(inst())
	cnt = 0
	for i in range(n - 1):
		if belt[i][m - 1] == 'R':
			cnt += 1
	for j in range(m - 1):
		if belt[n - 1][j] == 'D':
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(input()))
	c = -1
	for i in range(n - 1):
		if l[i][-1] != 'D':
			c += 1
	for i in range(m):
		if l[-1][i] != 'R':
			c += 1
	print(c)


for i in range(int(input())):
	(r, c) = list(map(int, input().split()))
	ans = []
	for j in range(r):
		if j != r - 1:
			x = input()
			ans.append(x[-1])
		else:
			ans.append(input())
	if len(ans) == 1:
		ans = list(ans[-1])
		anss = ans.count('D')
		print(anss)
	else:
		anss = ans.count('R')
		ans = list(ans[-1])
		anss += ans.count('D')
		print(anss)


t = int(input())
sol = []
for i in range(t):
	(x, y) = map(int, input().split())
	l = []
	for i in range(x):
		j = input()
		l.append([a for a in j])
	moves = 0
	for i in range(x):
		if len(l[i]) != 0:
			if 'C' not in l[i]:
				if l[i][-1] == 'R':
					moves += 1
			else:
				moves += l[i].count('D')
	sol.append(moves)
for i in sol:
	print(i)


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

def p(ns):
	print(' '.join(map(str, ns)))
t = int(input())
for i in range(t):
	(n, m) = gns()
	mp = []
	for i in range(n):
		mp.append(input())
	ans = 0
	for j in range(m):
		if mp[-1][j] == 'D':
			ans += 1
	for i in range(n):
		if mp[i][-1] == 'R':
			ans += 1
	print(ans)


num = int(input())
while num:
	(n, m) = input().split()
	change = 0
	for i in range(int(n)):
		row = input()
		if row[int(m) - 1] == 'R':
			change += 1
		if i == int(n) - 1:
			for j in row:
				if j == 'D':
					change += 1
	print(change)
	num -= 1


for _ in range(int(input())):
	(n, m) = list(map(int, input().split(' ')))
	arr = []
	for i in range(n):
		next = list(input())
		arr.append(next)
	count = 0
	for i in range(n):
		if i == n - 1:
			for j in range(len(arr[i]) - 1):
				if arr[i][j] != 'R':
					count += 1
		elif arr[i][m - 1] != 'D':
			count += 1
	print(count)


for t in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	l = []
	for i in range(n):
		l.append([i for i in input()])
	if n == 1 and m == 1:
		print(0)
	else:
		count = 0
		for i in range(0, n - 1):
			if l[i][m - 1] != 'D':
				count += 1
		for i in range(0, m - 1):
			if l[n - 1][i] != 'R':
				count += 1
		print(count)


import math
from decimal import Decimal
import heapq
import copy
import heapq
from collections import deque
from collections import defaultdict

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(n):
	tc = []
	ans = {}
	d = 2
	while d * d <= n:
		if n % d == 0:
			tc.append(d)
			n //= d
		else:
			d += 1
	if n > 1:
		tc.append(n)
	for i in tc:
		ans[i] = ans.get(i, 0) + 1
	return ans

def to_zero(n, s):
	lst = s[0]
	ans = []
	for i in range(n):
		if lst == s[i]:
			continue
		elif lst == '0':
			lst = '1'
			ans.append(i)
		else:
			lst = '0'
			ans.append(i)
	if lst == '1':
		ans.append(n)
	return ans
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lst = ''
	ans = 0
	for i in range(n):
		s = input()
		lst = s
		if s[m - 1] == 'R':
			ans += 1
	ans += lst.count('D')
	print(ans)


from collections import defaultdict as dd
from sys import stdin, stdout
for t in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	for i in range(n - 1):
		temp = input()
		if temp[-1] == 'R':
			c += 1
	temp = input()
	c += temp.count('D')
	print(c)


t = int(input())
i = 0
while i < t:
	i += 1
	k = 0
	(n, m) = map(int, input().split())
	for j in range(n):
		s = input()
		if j != n - 1 and s[-1] == 'R':
			k = k + 1
	for j2 in range(m - 1):
		if s[j2] == 'D':
			k += 1
	print(k)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		A = input()
		a.append(A)
	c = 0
	for i in range(n):
		if a[i][m - 1] != 'D':
			c += 1
		if a[i][m - 1] == 'C':
			c -= 1
			break
	for i in range(m):
		if a[n - 1][i] != 'R':
			c += 1
		if a[n - 1][i] == 'C':
			c -= 1
			break
	print(c)


t = int(input())
for i in range(t):
	(m, n) = map(int, input().split())
	ans = 0
	for j in range(m):
		a = list(input())
		if j == m - 1:
			ans += a.count('D')
		if a[-1] == 'R' and j != m - 1:
			ans += 1
	print(ans)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
sys.setrecursionlimit(300000)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input())
	ans = 0
	for i in range(n):
		for j in range(m):
			if i == n - 1 and j == m - 1:
				continue
			if l[i][j] == 'R' and j == m - 1:
				ans += 1
			elif l[i][j] == 'D' and i == n - 1:
				ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(m, n) = map(int, input().split())
	list1 = [input() for i in range(m)]
	ans = sum((l[-1] == 'R' for l in list1)) + list1[-1].count('D')
	print(ans)


for i in range(int(input())):
	a = input().split()
	s = 0
	for j in range(int(a[0])):
		b = input()
		if b[int(a[1]) - 1] == 'R' and j != int(a[0]) - 1:
			s += 1
		if j == int(a[0]) - 1:
			s += b.count('D')
	print(s)


k = int(input())
for m in range(k):
	data = []
	(n, m) = list(map(int, input().split(' ')))
	for i in range(n):
		x = input()
		data.append(x)
	ans = 0
	for i in range(len(data)):
		if i == len(data) - 1:
			if 'D' in data[i]:
				ans += data[i].count('D')
		elif data[i][-1] == 'R':
			ans += 1
	print(ans)


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = inar()
		st = []
		ans = 0
		for i in range(n):
			taje = input()
			st.append(taje)
		for i in range(n):
			if st[i][m - 1] == 'R':
				ans += 1
		for i in range(m):
			if st[n - 1][i] == 'D':
				ans += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


q = int(input())
for _ in range(q):
	(h, w) = map(int, input().split())
	maze = []
	for _ in range(h):
		l = input()
		maze.append(l)
	res = 0
	res += maze[h - 1].count('D')
	for i in range(h - 1):
		if maze[i][w - 1] == 'R':
			res += 1
	print(res)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	belt = []
	for j in range(n):
		belt.append(input())
	count = 0
	for k in belt:
		if k[-1] == 'R':
			count += 1
	for l in belt[-1]:
		if l == 'D':
			count += 1
	print(count)


from collections import deque

def getInts():
	return [int(x) for x in input().split()]

def solve():
	[n, m] = getInts()
	con = []
	for i in range(n):
		s = input()
		con.append(s)
	count = 0
	for i in range(0, n - 1):
		if con[i][-1] != 'D':
			count += 1
	for i in range(0, m - 1):
		if con[-1][i] != 'R':
			count += 1
	print(count)
[tc] = getInts()
for i in range(tc):
	solve()


def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for _ in range(n):
	l = inlt()
	x = l[0]
	y = l[1]
	grid = []
	for i in range(x):
		grid.append(insr())
	res = 0
	for i in range(x - 1):
		if grid[i][y - 1] != 'D':
			res += 1
	for j in range(y - 1):
		if grid[x - 1][j] != 'R':
			res += 1
	print(res)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	mat = []
	c2 = 0
	for i in range(n):
		l = input()
		if l[-1] == 'R':
			c2 += 1
		mat.append(l)
	c1 = mat[-1].count('D')
	print(c1 + c2)


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	mat = [[0 for j in range(m)] for k in range(n)]
	c = 0
	for j in range(n):
		s = input()
		for k in range(m):
			mat[j][k] = s[k]
			if k == m - 1:
				if s[k] == 'R':
					c += 1
			if j == n - 1 and k != m - 1:
				if s[k] == 'D':
					c += 1
	print(c)


for i in range(int(input())):
	height = int(input().split(' ')[0])
	grid = []
	for i in range(height):
		grid.append(input())
	changes = sum([i == 'D' for i in grid[-1]])
	changes += sum([i[-1] == 'R' for i in grid])
	print(changes)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = []
	for j in range(n):
		s = input()
		ar.append(s[-1])
	c = s.count('D')
	d = ar.count('R')
	print(c + d)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(m, n) = map(int, input().split())
	l = []
	for i in range(m):
		l.append(input().strip())
	out = 0
	for i in range(m):
		if l[i][-1] == 'R':
			out += 1
	for c in l[-1]:
		if c == 'D':
			out += 1
	print(out)


t = int(input())
ret = []
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	v = []
	for _ in range(n):
		v.append(str(input()))
	lastCol = list(map(lambda x: x[m - 1], v))
	lastRow = [c for c in v[n - 1]]
	ret.append(str(lastRow.count('D') + lastCol.count('R')))
print('\n'.join(ret))


from sys import stdin, stdout
from collections import Counter, OrderedDict
import math
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(str(val) + ' ')
	cout('\n')
(t,) = mp()
for _ in range(t):
	(n, m) = mp()
	f = cnt = 0
	for i in range(n):
		s = chars()
		if i != n - 1 and s[-1] == 'R':
			cnt += 1
		elif i == n - 1:
			cnt += s.count('D')
	cout(str(cnt) + '\n')


for _ in range(int(input())):
	(row, col) = map(int, input().split())
	stk = []
	for _ in range(row):
		stk.append(input())
	print(stk[-1].count('D') + ''.join([stk[i][-1] for i in range(len(stk) - 1)]).count('R'))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		(n, m) = RL()
		gp = [input() for _ in range(n)]
		vis = [[-1] * m for _ in range(n)]
		canr = 0

		def c(x, y, col):
			nonlocal canr
			q = [(x, y)]
			vis[x][y] = col
			tag = False
			while q:
				(xx, yy) = q.pop()
				if gp[xx][yy] == 'R':
					(nx, ny) = (xx, yy + 1)
				else:
					(nx, ny) = (xx + 1, yy)
				if -1 < nx < n and -1 < ny < m:
					if vis[nx][ny] != -1:
						tag = True
						continue
					q.append((nx, ny))
					vis[nx][ny] = col
			if tag:
				canr += 1
		now = 0
		for i in range(n):
			for j in range(m):
				if vis[i][j] == -1:
					now += 1
					c(i, j, now)
		print(now - 1 - canr)
main()


for tugezer in range(int(input())):
	qus = []
	(nik, mut) = map(int, input().split())
	for pis in range(nik):
		iPHO = list(str(input()))
		if iPHO[-1] == 'R':
			qus.append(1)
		if pis == nik - 1:
			for hER in range(mut):
				if iPHO[hER] == 'D':
					qus.append(1)
	print(len(qus))


for _ in range(int(input())):
	(N, M) = list(map(int, input().split()))
	grid = []
	for i in range(N):
		t = input()
		grid.append(t)
	count = 0
	for k in range(M - 1):
		if grid[N - 1][k] != 'R':
			count += 1
	for k in range(N - 1):
		if grid[k][M - 1] != 'D':
			count += 1
	print(count)


def examA():
	T = I()
	ans = []
	for _ in range(T):
		N = I()
		cur = [i + 1 for i in range(N)]
		ans.append(cur)
	for v in ans:
		print(' '.join(map(str, v)))
	return

def examC():
	T = I()
	ans = []
	for _ in range(T):
		cur = 0
		ans.append(cur)
	for v in ans:
		print(v)
	return

def examB():
	T = I()
	ans = []
	for _ in range(T):
		(N, M) = LI()
		A = [SI() for _ in range(N)]
		cnt = 0
		for i in range(N):
			if A[i][M - 1] == 'R':
				cnt += 1
		for i in range(M):
			if A[N - 1][i] == 'D':
				cnt += 1
		ans.append(cnt)
	for v in ans:
		print(v)
	return

def examD():
	ans = 0
	print(ans)
	return

def examE():
	ans = 0
	print(ans)
	return

def examF():
	ans = 0
	print(ans)
	return
from decimal import getcontext, Decimal as dec
import sys, bisect, heapq
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def I():
	return int(input())

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

def DI():
	return dec(input())

def LDI():
	return list(map(dec, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = dec('0.000000000001')
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}
getcontext().prec = 28
sys.setrecursionlimit(2 * 10 ** 5)
examB()


testcase = int(input())
for test in range(testcase):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append([i for i in input()])
	count = 0
	for i in range(m - 1):
		count += grid[n - 1][i] != 'R'
	for i in range(n - 1):
		count += grid[i][m - 1] != 'D'
	print(count)


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = map(int, input().split())
	a = 0
	while n > 1:
		n = n - 1
		s = input()
		if s[-1] == 'R':
			a += 1
	if n == 1:
		b = input()
		a += b.count('D')
	print(a)


for i in range(int(input())):
	temp = input().split()
	row = int(temp[0])
	column = int(temp[1])
	matrix = [[0] * column for i in range(row)]
	for j in range(row):
		matrix[j] = list(input())
		matrix[j].reverse()
	matrix.reverse()
	count = 0
	for j in range(row):
		for k in range(column):
			if j == 0 and k == 0:
				continue
			elif j == 0 and matrix[j][k] != 'R':
				count += 1
			elif k == 0 and matrix[j][k] != 'D':
				count += 1
			else:
				continue
	print(count)


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	arr = []
	for _ in range(r):
		arr.append(list(input()))
	count = 0
	for i in range(r - 1):
		if arr[i][-1] == 'R':
			count += 1
	for i in range(c - 1):
		if arr[-1][i] == 'D':
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for _ in range(n):
		a.append(input())
	c = 0
	for i in range(len(a)):
		if a[i][-1] != 'D' and i != n - 1:
			c += 1
	c += a[n - 1].count('D')
	print(c)


R = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, m) = R()
	lug = []
	ch = 0
	for _1 in range(n):
		temp = [*input()]
		if temp[-1] == 'R':
			ch += 1
		lug.append(temp)
	ch += lug[-1].count('D')
	print(ch)


t = int(input(''))
for i in range(0, t):
	(n, m) = input('').split(' ')
	n = int(n)
	m = int(m)
	s = []
	u = 0
	for j in range(0, n):
		s.append(list(input('')))
		if s[j][-1] == 'R':
			u = u + 1
		if j + 1 == n:
			p = s[j].count('D')
			u = u + p
	print(u)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	count = 0
	l = []
	for i in range(n):
		d = str(input())
		l.append(d)
	for i in range(n):
		for j in range(m):
			d = l[i][j]
			if i == n - 1:
				if j < m - 1:
					if d == 'D':
						count += 1
			if j == m - 1:
				if i < n - 1:
					if d == 'R':
						count += 1
	print(count)
	t = t - 1


t = int(input())
for test in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(list(str(input())))
	if n == 1 and m == 1:
		print(0)
	elif n == 1:
		c = 0
		for i in range(m):
			if a[0][i] == 'D':
				c += 1
		print(c)
	elif m == 1:
		c = 0
		for i in range(n):
			if a[i][0] == 'R':
				c += 1
		print(c)
	else:
		c = 0
		for i in range(m):
			if a[-1][i] == 'D':
				c += 1
		for i in range(n):
			if a[i][-1] == 'R':
				c += 1
		print(c)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	mass = []
	for item in range(n):
		mass.append(list(input()))
	counter = 0
	for item in range(m):
		if mass[n - 1][item] == 'D':
			counter += 1
	for item in range(n):
		if mass[item][m - 1] == 'R':
			counter += 1
	print(counter)


for j in range(int(input())):
	(a, b) = map(int, input().split())
	d = 0
	for i in range(a - 1):
		c = input()
		if c[b - 1] == 'R':
			d += 1
	e = input()
	for i in e:
		if i == 'D':
			d += 1
	print(d)


a = int(input())
for g in range(a):
	(b, u) = [int(r) for r in input().split()]
	o = 0
	for j in range(b):
		x = input()
		if x[-1] == 'R':
			o += 1
	o += x.count('D')
	print(o)


for test in range(int(input())):
	(n, m) = map(int, input().strip().split(' '))
	row = []
	for i in range(n):
		coloum = list(input())
		row.append(coloum)
	count = 0
	for i in range(m):
		if row[n - 1][i] == 'D':
			count += 1
	for i in range(n):
		if row[i][m - 1] == 'R':
			count += 1
	print(count)


import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
input = sys.stdin.readline
getS = lambda : input().strip()
getN = lambda : int(input())
getList = lambda : list(map(int, input().split()))
getZList = lambda : [int(x) - 1 for x in input().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)

def nck(n, k, kaijyo):
	return npk(n, k, kaijyo) * divide(kaijyo[k]) % MOD

def npk(n, k, kaijyo):
	if k == 0 or k == n:
		return n % MOD
	return kaijyo[n] * divide(kaijyo[n - k]) % MOD

def fact_and_inv(SIZE):
	inv = [0] * SIZE
	fac = [0] * SIZE
	finv = [0] * SIZE
	inv[1] = 1
	fac[0] = fac[1] = 1
	finv[0] = finv[1] = 1
	for i in range(2, SIZE):
		inv[i] = MOD - MOD // i * inv[MOD % i] % MOD
		fac[i] = fac[i - 1] * i % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD
	return (fac, finv)

def renritsu(A, Y):
	A = np.matrix(A)
	Y = np.matrix(Y)
	Y = np.reshape(Y, (-1, 1))
	X = np.linalg.solve(A, Y)
	return X.flatten().tolist()[0]

class TwoDimGrid:

	def __init__(self, h, w, wall='#'):
		self.h = h
		self.w = w
		self.size = (h + 2) * (w + 2)
		self.wall = wall
		self.get_grid()

	def get_grid(self):
		grid = [self.wall * (self.w + 2)]
		for i in range(self.h):
			grid.append(self.wall + getS() + self.wall)
		grid.append(self.wall * (self.w + 2))
		self.grid = grid

	def init_cost(self):
		self.cost = [INF] * self.size

	def pos(self, x, y):
		return y * (self.w + 2) + x

	def getgrid(self, x, y):
		return self.grid[y][x]

	def get(self, x, y):
		return self.cost[self.pos(x, y)]

	def set(self, x, y, v):
		self.cost[self.pos(x, y)] = v
		return

	def show(self):
		for i in range(self.h + 2):
			print(self.cost[(self.w + 2) * i:(self.w + 2) * (i + 1)])

	def showsome(self, tgt):
		for t in tgt:
			print(t)
		return

	def showsomejoin(self, tgt):
		for t in tgt:
			print(''.join(t))
		return

	def search(self):
		grid = self.grid
		move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
		move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]

def solve():
	(n, m) = getList()
	g = []
	ans = 0
	for i in range(n):
		g.append(getS())
	for li in g[:-1]:
		if li[-1] == 'R':
			ans += 1
	for c in g[-1]:
		if c == 'D':
			ans += 1
	print(ans)

def main():
	n = getN()
	for _ in range(n):
		solve()
	return
main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	belt = [[x for x in input()] for y in range(n)]
	rightCol = [belt[x][-1] for x in range(n)]
	downRow = belt[-1]
	ans = downRow.count('D') + rightCol.count('R')
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	a = []
	for __ in range(n):
		a.append(list(input()))
	o = 0
	for i in range(n):
		if a[i][-1] == 'R':
			o += 1
	for i in range(m):
		if a[-1][i] == 'D':
			o += 1
	print(o)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	arr = []
	for __ in range(n):
		arr.append(input())
	cnt = 0
	for i in range(n):
		if arr[i][m - 1] == 'R':
			cnt += 1
	for i in range(m):
		if arr[n - 1][i] == 'D':
			cnt += 1
	print(cnt)


t = int(input())
for _ in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	s = []
	p = ''
	for i in range(n):
		sx = input()
		if i != n - 1:
			s.append(sx[m - 1])
		else:
			p = sx
	cnt = 0
	for i in range(n - 1):
		if s[i] != 'D':
			cnt += 1
	for i in range(m - 1):
		if p[i] != 'R':
			cnt += 1
	print(cnt)


t = int(input())
for i in range(t):
	count = 0
	(n, m) = map(int, input().split())
	matrix = [list(input()) for i in range(n)]
	if n == 1:
		for i in range(m - 1):
			if matrix[0][i] == 'D':
				count += 1
	elif m == 1:
		for i in range(n - 1):
			if matrix[i][0] == 'R':
				count += 1
	elif n == 1 and m == 1:
		pass
	else:
		for j in range(n):
			if matrix[j][m - 1] == 'R':
				count += 1
		for k in range(m):
			if matrix[n - 1][k] == 'D':
				count += 1
	print(count)


from sys import stdin, stdout
import math
from collections import deque

def solve():
	(n, m) = map(int, input().split())
	g = []
	for i in range(n):
		g.append(list(input()))
	count = 0
	for i in range(m - 1):
		if g[n - 1][i] != 'R':
			count += 1
	for i in range(n - 1):
		if g[i][m - 1] != 'D':
			count += 1
	print(count)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


def solve():
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(list(input()))
	ans = 0
	for i in range(n):
		ans += a[i][m - 1] == 'R'
	for i in range(m):
		ans += a[n - 1][i] == 'D'
	print(ans)
tst = int(input())
for i in range(tst):
	solve()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		s = input()
		if s[m - 1] == 'C':
			for j in range(m):
				if s[j] == 'D':
					ans += 1
		elif s[m - 1] == 'R':
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		a = input()
		mat.append(list(a))
	cnt = 0
	for i in range(m):
		if mat[n - 1][i] == 'D':
			cnt += 1
	for i in range(n):
		if mat[i][m - 1] == 'R':
			cnt += 1
	print(cnt)
	t -= 1


t = int(input())
for tc in range(t):
	line = input().split()
	(n, m) = (int(line[0]), int(line[1]))
	count = 0
	mat = []
	for i in range(n):
		line = input()
		mat.append(line)
	col = mat[-1]
	for i in range(m - 1):
		if col[i] != 'R':
			count += 1
	for i in range(n - 1):
		if mat[i][-1] != 'D':
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = [int(s) for s in input().split(' ')]
	matrix = []
	for i in range(n):
		row = []
		for ch in input():
			row.append(ch)
		matrix.append(row)
	downs = 0
	rights = 0
	for i in range(n - 1):
		if matrix[i][-1] != 'D':
			downs += 1
	for i in matrix[-1]:
		if i != 'R' and i != 'C':
			rights += 1
	print(downs + rights)


from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
	(n, m) = map(int, stdin.readline().strip().split())
	s = [stdin.readline().strip() for i in range(n)]
	ans = 0
	ans += s[-1].count('D')
	for i in s:
		if i[-1] == 'R':
			ans += 1
	print(ans)


import sys
input = sys.stdin.buffer.readline
print = lambda _, end='\n': sys.stdout.write(str(_) + end)
inst = lambda : input().decode().rstrip('\n\r')
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
_T_ = inin()
for _t_ in range(_T_):
	(n, m) = inar()
	belt = []
	for i in range(n):
		belt.append(inst())
	cnt = 0
	for i in range(n - 1):
		if belt[i][m - 1] == 'R':
			cnt += 1
	for j in range(m - 1):
		if belt[n - 1][j] == 'D':
			cnt += 1
	print(cnt)


def func():
	(m, n) = map(int, input().split())
	ar = []
	for i in range(m):
		ar.append(input())
	co = 0
	for i in range(m - 1):
		if ar[i][n - 1] == 'R':
			co += 1
	for i in range(n):
		if ar[m - 1][i] == 'D':
			co += 1
	print(co)
for _ in range(int(input())):
	func()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for _ in range(n):
		a.append(input())
	ans = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			ans += 1
	ans += a[n - 1].count('D')
	print(ans)


class Solution:

	def solve(self, m, n, grid):
		cnt = 0
		for i in range(m):
			if grid[i][-1] == 'R':
				cnt += 1
		for i in range(n):
			if grid[-1][i] == 'D':
				cnt += 1
		return cnt
tc = int(input())
for _ in range(tc):
	(m, n) = map(int, input().split())
	grid = []
	for _ in range(m):
		row = list(input().strip())
		grid.append(row)
	print(Solution().solve(m, n, grid))


def cov(j):
	s = 0
	for k in j:
		if k[-1] == 'R':
			s += 1
	for m in j[-1]:
		if m == 'D':
			s += 1
	return s
t = int(input())
l = []
for i in range(t):
	l1 = []
	(r, c) = input().split()
	for i in range(int(r)):
		s = input()
		l1.append(s)
	l.append(l1)
for j in l:
	print(cov(j))


import sys
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	A = []
	for i in range(n):
		A.append(list(input()))
	ans = 0
	for i in range(n):
		if A[i][m - 1] == 'R':
			ans = ans + 1
	for i in range(m):
		if A[n - 1][i] == 'D':
			ans = ans + 1
	print(ans)


def next_int():
	return int(input())

def next_ints():
	return [int(x) for x in input().split()]
t = next_int()
for i in range(0, t):
	(n, m) = next_ints()
	changes = 0
	for i in range(1, n):
		row = input()
		if row[-1] == 'R':
			changes += 1
	row = input()
	changes += row.count('D')
	print(changes)


for i in range(int(input())):
	matr = list(map(int, input().split()))
	count = 0
	for j in range(1, matr[0] + 1):
		s = str(input())
		if j < matr[0]:
			if s.endswith('R'):
				count += 1
		else:
			for k in range(len(s)):
				if s[k] == 'D':
					count += 1
	print(count)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append(input())
	ans = 0
	for i in range(m - 1):
		if grid[n - 1][i] != 'R':
			ans += 1
	for i in range(n - 1):
		if grid[i][m - 1] != 'D':
			ans += 1
	print(ans)
	t -= 1


def columnCount(Matrix, N, M):
	count = 0
	for i in range(M - 1):
		if Matrix[N - 1][i] == 'D':
			count += 1
	return count

def rowCount(Matrix, N, M):
	count = 0
	for i in range(N - 1):
		if Matrix[i][M - 1] == 'R':
			count += 1
	return count
T = int(input())
for x in range(T):
	(N, M) = map(int, input().split())
	List = []
	for i in range(N):
		t = input()
		List.append([i for i in t])
	print(rowCount(List, N, M) + columnCount(List, N, M))


for _ in range(int(input())):
	(r, c) = [int(x) for x in input().split()]
	m = []
	for i in range(r):
		m.append(input())
	ans = 0
	for i in range(c):
		if m[r - 1][i] == 'D':
			ans += 1
	for i in range(r):
		if m[i][c - 1] == 'R':
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	count = 0
	(n, m) = list(input().split())
	n = int(n)
	m = int(m)
	if m == 1 and n == 1:
		cur_str = input()
		count = 0
	elif n == 1:
		cur_str = input()
		for i1 in range(0, len(cur_str) - 1):
			if cur_str[i1] == 'D':
				count += 1
	elif m == 1:
		for i1 in range(1, n):
			cur_str = input()
			if cur_str == 'R':
				count += 1
		cur_str = input()
	else:
		for i1 in range(1, n):
			cur_str = input()
			if cur_str[-1] == 'R':
				count += 1
		cur_str = input()
		for i1 in range(0, len(cur_str) - 1):
			if cur_str[i1] == 'D':
				count += 1
	print(count)


from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
from math import sqrt
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	for _ in range(inin()):
		(n, k) = map(int, input().split())
		cnt = 0
		for i in range(n - 1):
			s = sin()
			if s[-1] == 'R':
				cnt += 1
		for i in range(1):
			t = sin()
			for i in range(k):
				if t[i] == 'D':
					cnt += 1
		print(cnt)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	(m, n) = [int(x) for x in input().split()]
	mat = []
	for iter in range(m):
		arr1 = [x for x in input()]
		mat.append(arr1)
	ans = 0
	for iter in range(m):
		if mat[iter][n - 1] == 'R':
			ans += 1
	for iter in range(n):
		if mat[m - 1][iter] == 'D':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(cr, cd) = (0, 0)
	for i in range(n - 1):
		s = input()
		if s[-1] == 'R':
			cr += 1
	s = input()
	cd = s.count('D')
	print(cd + cr)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	x = []
	c = 0
	for _ in range(m):
		x.append(input())
	for i in range(m):
		if x[i][n - 1] == 'R':
			c += 1
	for j in range(n):
		if x[m - 1][j] == 'D':
			c += 1
	print(c)


for _ in range(int(input().strip())):
	(n, m) = map(int, input().strip().split(' '))
	b = [input().strip()[-1] for _ in range(n - 1)]
	l = input().strip()
	print(b.count('R') + l.count('D'))


t1 = int(input())
for _ in range(t1):
	(n, m) = map(int, input().split())
	p = 0
	for i in range(n):
		s = str(input())
		if s[m - 1] == 'R':
			p += 1
		elif s[m - 1] == 'C':
			for j in s:
				if j == 'D':
					p += 1
	print(p)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	pasy = ['' for _ in range(n)]
	for x in range(n):
		pasy[x] = input()
	wynik = 0
	for x in range(n):
		for y in range(m):
			if pasy[x][y] == 'C':
				continue
			if pasy[x][y] == 'R' and y == m - 1:
				wynik += 1
			if pasy[x][y] == 'D' and x == n - 1:
				wynik += 1
	print(wynik)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	count = 0
	ans = ''
	for i in range(n - 1):
		s = input()
		ans += s
	last = input()
	count_last = last.count('D')
	for i in range(m - 1, (n - 1) * m, m):
		if ans[i] != 'D':
			count += 1
	print(count + count_last)


x = int(input())
for z in range(x):
	(n, m) = map(int, input().split())
	l = []
	c = 0
	for i in range(n):
		l.append(input())
	for i in range(n):
		if l[i][-1] == 'R':
			c += 1
	c = c + l[-1].count('D')
	print(c)


R = lambda : map(int, input().split())
t = int(input())
answers = []
for i in range(0, t):
	nm = list(R())
	n = nm[0]
	m = nm[1]
	countR = 0
	countD = 0
	mas = []
	for row in range(0, n):
		r = input()
		if r[-1] == 'D':
			countD += 1
		if row == n - 1:
			countR = len([x for x in r if x == 'R'])
	answers.append(n - 1 - countD + m - 1 - countR)
for a in answers:
	print(a)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		matrix.append(list(input()))
	res = 0
	for i in range(n - 1):
		if matrix[i][-1] == 'D':
			pass
		else:
			res += 1
	for i in range(m - 1):
		if matrix[-1][i] == 'R':
			pass
		else:
			res += 1
	print(res)


import os
from collections import defaultdict, deque
is_dev = 'vscode' in os.environ
if is_dev:
	inF = open('in.txt', 'r')
	outF = open('out.txt', 'w')

def ins():
	return list(map(int, input_().split(' ')))

def inss():
	return list(input_().split(' '))

def input_():
	if is_dev:
		return inF.readline()[:-1]
	else:
		return input()

def ranin():
	return range(int(input_()))

def print_(data):
	if is_dev:
		outF.write(str(data) + '\n')
	else:
		print(data)
for _ in ranin():
	(n, m) = ins()
	arr = []
	for i in range(n):
		arr.append(input_())
	total = 0
	for i in range(n - 1):
		if arr[i][m - 1] != 'D':
			total += 1
	for j in range(m - 1):
		if arr[n - 1][j] != 'R':
			total += 1
	print_(total)
if is_dev:
	outF.close()

	def compare_file():
		print(open('out.txt', 'r').read() == open('outactual.txt', 'r').read())
	compare_file()


def maink():
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	a = []
	for i in range(n):
		b = [u for u in input()]
		a.append(b)
	flag = 0
	for i in range(m - 1):
		if a[n - 1][i] == 'D':
			flag += 1
	for i in range(n - 1):
		if a[i][m - 1] == 'R':
			flag += 1
	return flag
t = int(input())
c = []
for i in range(t):
	c.append(maink())
for k in c:
	print(k)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		t = list(input())
		l.append(t)
	cr = 0
	cc = 0
	for i in range(n - 1):
		if l[i][m - 1] == 'R':
			l[i][m - 1] = 'D'
			cc += 1
	for j in range(m - 1):
		if l[n - 1][j] == 'D':
			l[n - 1][j] = 'R'
			cr += 1
	print(cc + cr)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 1000000007

def value():
	return tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(r, c) = value()
	a = []
	for i in range(r):
		a.append(input())
	ans = 0
	for i in range(r - 1):
		ans += a[i][-1] == 'R'
	for i in range(c - 1):
		ans += a[-1][i] == 'D'
	print(ans)


t = int(input())
for i in range(t):
	(m, n) = map(int, input().split())
	mat = []
	for j in range(m):
		arr = []
		s = input()
		for k in s:
			arr.append(k)
		mat.append(arr)
	c = 0
	c1 = 0
	for x in range(n):
		if mat[m - 1][x] == 'D':
			c += 1
	for y in range(m):
		if mat[y][n - 1] == 'R':
			c1 += 1
	print(c + c1)


t = int(input())
for i in range(t):
	res = 0
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	for j in range(n - 1):
		r = input()
		if r[m - 1] == 'R':
			res += 1
	r = input()
	for c in r:
		if c == 'D':
			res += 1
	print(res)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		line = input()
		if i != n - 1:
			if line[-1] == 'R':
				ans += 1
		else:
			for ch in line:
				if ch == 'D':
					ans += 1
	print(ans)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = [list(input().strip()) for _ in range(n)]
	ans = 0
	for y in range(n - 1):
		if a[y][m - 1] != 'D':
			ans += 1
	for x in range(m - 1):
		if a[n - 1][x] != 'R':
			ans += 1
	print(ans)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	(n, m) = map(int, input().split())
	r = 0
	s = 0
	for i in range(n):
		r = input()
		if r[-2] == 'R':
			s += 1
	for x in r:
		if x == 'D':
			s += 1
	print(s)


t = int(input())
for case in range(t):
	conveyer = []
	count = 0
	(n, m) = [int(x) for x in input().split()]
	for i in range(n):
		conveyer.append(input())
	for i in range(n - 1):
		if conveyer[i][m - 1] != 'D':
			count += 1
	for i in range(m - 1):
		if conveyer[n - 1][i] != 'R':
			count += 1
	print(count)


for nt in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	ans = 0
	for i in range(n - 1, -1, -1):
		for j in range(m - 1, -1, -1):
			if i == n - 1 and m == -1:
				continue
			if i == n - 1 and mat[i][j] == 'D':
				ans += 1
			if j == m - 1 and mat[i][j] == 'R':
				ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	b = []
	e = []
	f = []
	for i in range(n):
		l = list(map(str, input()))
		a.append(l[m - 1])
		if i == n - 1:
			b.extend(l)
	a.pop(len(a) - 1)
	b.pop(len(b) - 1)
	c = 0
	d = 0
	for i in range(len(a)):
		if a[i] == 'R':
			c += 1
	for j in range(len(b)):
		if b[j] == 'D':
			d += 1
	print(c + d)


import sys, threading, os.path
import string
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('in.rtf'):
		input = open('in.rtf', 'r')
	else:
		input = sys.stdin
	n = int(input.readline())
	results = []
	for i in range(n):
		(n1, n2) = list(map(int, input.readline().split()))
		board = []
		for j in range(n1):
			board.append(str(input.readline().rstrip('\n')))
		counter = 0
		for k in range(n1):
			if board[k][n2 - 1] == 'R':
				counter += 1
		for k in range(n2):
			if board[n1 - 1][k] == 'D':
				counter += 1
		results.append(counter)
	output = '\n'.join(map(str, results))
	if os.path.exists('out.rtf'):
		open('out.rtf', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


def resolve():
	N = int(input())
	for _ in range(N):
		(X, Y) = map(int, input().split(' '))
		counter = 0
		for _ in range(X - 1):
			labels = [x for x in list(input())]
			if labels[-1] == 'R':
				counter += 1
		labels = [x for x in list(input())]
		counter += labels.count('D')
		print(counter)
resolve()


cases = int(input())
for i in range(cases):
	l1 = input().split(' ')
	n = int(l1[0])
	m = int(l1[1])
	grid = []
	for j in range(n):
		row = input()
		grid.append(row)
	count = 0
	for g in grid:
		if g[-1] == 'R':
			count += 1
	lastrow = grid[-1]
	for k in range(len(lastrow)):
		if lastrow[k] == 'D':
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	t2 = []
	t4 = 0
	if n == 1:
		t1 = input()
		t3 = t1.count('R')
		t4 += m - t3 - 1
	else:
		for i in range(n):
			if i != n - 1:
				t1 = input()
				if t1[m - 1] != 'D':
					t4 += 1
			else:
				t1 = input()
				t3 = t1.count('R')
				t4 += m - t3 - 1
	print(t4)


t = int(input())
while t:
	(n, m) = list(map(int, input().split()))
	grid = []
	for i in range(n):
		a = input()
		grid.append(a)
	ans = grid[-1].count('D')
	for g in grid:
		if g[-1] == 'R':
			ans += 1
	print(ans)
	t -= 1


def solve(n, m, belt):
	total = 0
	for row in range(n - 1):
		if belt[row][-1] != 'D':
			total += 1
	for i in range(m - 1):
		if belt[n - 1][i] != 'R':
			total += 1
	print(total)
t = int(input())
for test in range(t):
	(n, m) = map(int, input().split())
	belt = []
	for i in range(n):
		l = list(input())
		belt.append(l)
	solve(n, m, belt)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split())
	mat = [None] * n
	cnt = 0
	for i in range(n):
		mat[i] = input()
		if i != n - 1:
			if mat[i][m - 1] == 'R':
				cnt += 1
		else:
			cnt += mat[i].count('D')
	print(cnt)
	t -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = ''
	for i in range(n):
		l += input()
	c = list(l)
	f = 0
	for j in range(m - 1, n * m, m):
		if c[j] == 'R':
			c[j] = 'D'
			f += 1
	for k in range((n - 1) * m, n * m):
		if c[k] == 'D':
			c[k] = 'R'
			f += 1
	print(f)


for i in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	arr = []
	for i in range(n):
		k = list(input())
		arr.append(k)
	num = 0
	for i in range(n):
		if arr[i][m - 1] == 'R':
			num += 1
	for i in range(m):
		if arr[n - 1][i] == 'D':
			num += 1
	print(num)


t_case = int(input())
for _ in range(t_case):
	(n, m) = map(int, input().split())
	board = []
	for i in range(n):
		board.append([j for j in input()])
	count = 0
	for i in range(n):
		for j in range(m):
			if j == m - 1 and board[i][j] == 'R':
				count += 1
			elif i == n - 1 and board[i][j] == 'D':
				count += 1
	print(count)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
while t > 0:
	t -= 1
	(n, m) = inlt()
	i = 0
	res = 0
	arr = []
	while i < n:
		arr.append(insr())
		i += 1
	for i in range(n):
		if arr[i][m - 1] == 'R':
			res += 1
	for i in range(m):
		if arr[n - 1][i] == 'D':
			res += 1
	print(res)


t = int(input())
for _ in range(t):
	(r, c) = map(int, input().split())
	mat = [list(map(str, input().strip())) for i in range(r)]
	ctr = 0
	for i in range(0, c - 1):
		if mat[r - 1][i] == 'D':
			ctr += 1
	for i in range(0, r - 1):
		if mat[i][c - 1] == 'R':
			ctr += 1
	print(ctr)


t = int(input())
i = 0
while i < t:
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	k = []
	b = 0
	for s in range(n - 1):
		a = list(input())
		k.append(a[m - 1])
	a1 = list(input())
	k = k + a1
	k.pop(len(k) - 1)
	v = 0
	for o in k:
		v += 1
		if v <= n - 1 and o != 'D':
			b += 1
		elif v > n - 1 and o != 'R':
			b += 1
	print(b)
	i += 1


T = int(input())
for case in range(T):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n - 1):
		a = input()
		if a[-1] == 'R':
			ans += 1
	a = input()[:-1]
	ans += a.count('D')
	print(ans)


def fix(n, m, matrix):
	r = matrix[-1].count('D')
	d = 0
	for s in matrix:
		if s[-1] == 'R':
			d += 1
	return r + d
t = int(input())
array = []
for i in range(t):
	(n, m) = list(map(int, input().split(' ')))
	matrix = []
	for j in range(n):
		matrix.append(input())
	array.append([n, m, matrix])
for x in array:
	print(fix(*x))


from sys import stdin
for _ in range(int(input())):
	l = []
	(n, k) = map(int, stdin.readline().rstrip().split(' '))
	for i in range(n - 1):
		a = list(stdin.readline().rstrip())
		l.append(a[-1])
	z = list(stdin.readline().rstrip())
	c = z.count('D') + l.count('R')
	print(c)


(z, zz, dgraphs) = (input, lambda : list(map(int, z().split())), {})
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	z = input
	(n, m) = zz()
	c = 0
	for i in range(n):
		l = z()
		if n - 1 == i:
			for i in l:
				if i == 'D':
					c += 1
			break
		if l[-1] != 'D':
			c += 1
	print(c)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n, m) = I()
	an = 0
	for i in range(n):
		x = input().strip()
		if i == n - 1:
			an += x[:m - 1].count('D')
		if i != n - 1:
			an += x[-1] != 'D'
	print(an)


for t in range(int(input())):
	(n, m) = list(map(int, str.split(input())))
	lists = []
	for _ in range(n):
		lists.append(list(input()))
	rslt = 0
	for i in range(n):
		for j in range(m):
			if i == n - 1 and j < m - 1 and (lists[i][j] != 'R'):
				rslt += 1
			if j == m - 1 and i < n - 1 and (lists[i][j] != 'D'):
				rslt += 1
	print(rslt)


test_cnt = int(input())
for tn in range(test_cnt):
	raw = input()
	(n, m) = map(int, raw.split(' '))
	mx = []
	for ri in range(n):
		mx += [input()]
	rez = 0
	for ri in range(n - 1):
		if mx[ri][-1] == 'R':
			rez += 1
	for ci in range(m - 1):
		if mx[-1][ci] == 'D':
			rez += 1
	print(rez)


for _ in range(int(input())):
	c = 0
	for _ in range(list(map(int, input().split()))[0] - 1):
		c += input()[-1] == 'R'
	print(input().count('D') + c)


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	for _ in range(ii()):
		(n, m) = mi()
		a = []
		for i in range(n):
			a.append(si())
		ans = 0
		for i in range(n):
			if a[i][m - 1] == 'R':
				ans += 1
		for i in range(m):
			if a[n - 1][i] == 'D':
				ans += 1
		print(ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	(n, m) = arrIN()
	a = [input() for i in range(n)]
	x = [[0 for i in range(m + 1)] for j in range(n + 1)]
	x[n - 1][m - 1] = 1
	cnt = 0
	for i in range(n - 1, -1, -1):
		for j in range(m - 1, -1, -1):
			if i == n - 1 and j == m - 1:
				continue
			if a[i][j] == 'R':
				if x[i][j + 1] == 0:
					cnt += 1
			elif a[i][j] == 'D':
				if not x[i + 1][j]:
					cnt += 1
			x[i][j] = 1
	print(cnt)


t = int(input())
for h in range(t):
	(n, m) = map(int, input().split())
	s = list()
	for i in range(n):
		s.append(input())
	ans = 0
	for i in range(n):
		for j in range(m):
			if s[i][j] == 'R':
				if j + 1 >= m:
					ans += 1
			elif s[i][j] == 'D':
				if i + 1 >= n:
					ans += 1
	print(ans)


def solve():
	(n, m) = map(int, input().split())
	lst = [list(input()) for i in range(n)]
	res = 0
	for x in range(n - 1):
		if lst[x][m - 1] == 'R':
			res += 1
	for y in range(m - 1):
		if lst[n - 1][y] == 'D':
			res += 1
	print(res)
for i in range(int(input())):
	solve()


test_cases = int(input())
for e in range(test_cases):
	(n, m) = map(int, input().split())
	c = 0
	for i in range(n):
		direction = list(input())
		if direction[m - 1] == 'R':
			c += 1
	for i in range(m):
		if direction[i] == 'D':
			c += 1
	print(c)


t = int(input())
for z in range(t):
	(n, m) = map(int, input().split())
	a = [list(input()) for i in range(n)]
	kol = 0
	for i in range(n):
		if a[i][-1] == 'R':
			kol += 1
	for i in range(m):
		if a[-1][i] == 'D':
			kol += 1
	print(kol)


t = int(input())
for tt in range(t):
	(n, m) = map(int, input().split())
	f = []
	for i in range(n):
		f.append(input())
	ans = 0
	for i in range(0, m - 1):
		if f[n - 1][i] != 'R':
			ans += 1
	for i in range(0, n - 1):
		if f[i][m - 1] != 'D':
			ans += 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		a = input().rstrip()
		if a[m - 1] == 'R':
			ans += 1
		if i == n - 1:
			for j in a:
				if j == 'D':
					ans += 1
	print(ans)


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	ls = [[j for j in input()] for i in range(r)]
	print(sum([1 for i in ls if i[-1] == 'R']) + ls[-1].count('D'))


for t in range(int(input())):
	(n, m) = [int(k) for k in input().split()]
	mat = []
	for i in range(n):
		mat.append([str(k) for k in input()])
	step = 0
	for i in range(n - 1):
		if mat[i][m - 1] == 'R':
			step += 1
	for i in range(m - 1):
		if mat[n - 1][i] == 'D':
			step += 1
	print(step)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def block():
	(n, m) = inlt()
	b = []
	t = 0
	for j in range(0, n):
		b.append(insr())
	for i in range(0, n - 1):
		if b[i][-1] == 'R':
			t += 1
	for j in range(0, m - 1):
		if b[-1][j] == 'D':
			t += 1
	return t

def main():
	nc = inp()
	for i in range(0, nc):
		b = block()
		print(b)
main()


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	l = []
	for i in range(n):
		l.append(list(input()))
	ans = 0
	for i in range(n):
		if l[i][m - 1] == 'R':
			ans += 1
	for i in range(m):
		if l[n - 1][i] == 'D':
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(tate, yoko) = list(map(int, input().split()))
	mp = []
	ans = 0
	for i in range(tate):
		rd = list(map(str, input().split()))
		if rd[0][-1] == 'R':
			ans += 1
		if i == tate - 1:
			ans += rd[0].count('D')
	print(ans)


import sys
from collections import Counter

def main():
	t = int(sys.stdin.readline())
	for _ in range(t):
		(n, m) = [int(x) for x in sys.stdin.readline().split(' ')]
		count = 0
		for i in range(n - 1):
			if sys.stdin.readline().rstrip()[-1] == 'R':
				count += 1
		count += Counter(sys.stdin.readline().rstrip())['D']
		print(count)
main()


import math
t = int(input())
for z in range(t):
	(n, m) = map(int, input().split())
	a = []
	ans = 0
	for i in range(n):
		p = input()
		if p[-1] == 'R':
			ans += 1
		if i == n - 1:
			x = p.count('D')
			ans += x
	print(ans)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, M) = [int(x) for x in input().split()]
		C = [input().strip() for _ in range(N)]
		ans = 0
		for j in range(M):
			if C[N - 1][j] == 'D':
				ans += 1
		for i in range(N):
			if C[i][M - 1] == 'R':
				ans += 1
		print(ans)
main()


T = int(input())
for _ in range(0, T):
	(n, m) = map(int, input().split())
	L = []
	for i in range(0, n):
		s = input()
		L.append(s)
	dp = []
	for i in range(n):
		h = []
		for j in range(m):
			h.append(0)
		dp.append(h)
	dp[n - 1][m - 1] = 1
	c = 0
	for i in range(n - 1, -1, -1):
		for j in range(m - 1, -1, -1):
			if dp[i][j] == 0:
				if L[i][j] == 'R':
					if j == m - 1:
						c += 1
					elif dp[i][j + 1] == 0:
						c += 1
				elif i == n - 1:
					c += 1
				elif dp[i + 1][j] == 0:
					c += 1
				dp[i][j] = 1
	print(c)


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	matrix = []
	ans = 0
	a = 0
	b = 0
	for j in range(n):
		s = str(input())
		matrix.append(s)
		if s[-1] == 'R':
			ans += 1
		if j == n - 1:
			for p in range(m - 1):
				if s[p] != 'R':
					ans += 1
	print(ans)


TN = int(input())
for TI in range(TN):
	(rn, cn) = [int(x) for x in input().split()]
	rows = []
	for ri in range(rn):
		rows.append(input())
	ans = len([0 for ci in range(cn - 1) if rows[-1][ci] == 'D']) + len([0 for ri in range(rn - 1) if rows[ri][-1] == 'R'])
	print(ans)


cases = int(input())
answers = [] * 0
for problems in range(cases):
	a = [int(x) for x in input().split()]
	n = a[0]
	m = a[1]
	count = 0
	for i in range(n):
		line = str(input())
		if i == n - 1:
			for ch in line:
				if ch == 'D':
					count += 1
		elif line[len(line) - 1] == 'R':
			count += 1
	answers.append(count)
for answer in answers:
	print(answer)


T = int(input())
result = []
for t in range(T):
	(n, m) = map(int, input().split())
	RD = []
	for i in range(n):
		RD.append(input())
	res = 0
	for i in range(n):
		if i != n - 1:
			if RD[i][m - 1] == 'R':
				res += 1
		else:
			for j in range(m - 1):
				if RD[i][j] == 'D':
					res += 1
	print(res)


for case in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	grid = []
	for i in range(n):
		temp = [x for x in input()]
		grid.append(temp)
	ans = 0
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'C':
				break
			if grid[i][j] == 'R':
				if j == m - 1:
					ans += 1
			if grid[i][j] == 'D':
				if i == n - 1:
					ans += 1
		if grid[i][j] == 'c':
			break
	print(ans)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		s = input()
		arr.append(s)
	ct = arr[n - 1].count('D')
	for j in range(n):
		if arr[j][m - 1] == 'R':
			ct += 1
	print(ct)


def rn():
	a = int(input())
	return a

def rl():
	a = list(map(int, input().split()))
	return a
for _ in range(rn()):
	[n, m] = rl()
	ans = 0
	aa = ''
	for i in range(n):
		aa = input()
		if aa[-1] == 'R':
			ans += 1
	for i in aa:
		if i == 'D':
			ans += 1
	print(ans)


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for i in range(int(input())):
	(n, m) = map(int, input().split())
	mas = []
	for i in range(n):
		mas.append(input())
	ans = 0
	for i in range(n):
		if mas[i][-1] != 'D':
			ans += 1
	for i in range(m):
		if mas[-1][i] == 'D':
			ans += 1
	print(ans - 1)


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	(n, m) = ip()
	mat = [input().strip() for i in range(n)]
	print(mat[-1].count('D') + sum([1 if i[-1] == 'R' else 0 for i in mat]))


from collections import Counter

def main():
	T = int(input().strip())
	for case in range(T):
		(n, m) = [int(x) for x in input().strip().split()]
		change = 0
		for row in range(n):
			inp = [s for s in input().strip()]
			if row != n - 1 and inp[-1] == 'R':
				change += 1
			if row == n - 1:
				c = Counter(inp)
				change += c['D']
		print(change)
	return
main()


n = input()
a = []
x = 0
y = 0
count = 0
res = [n]
for i in range(int(n)):
	a = []
	(y, x) = map(int, input().split())
	for j in range(y):
		a.append(input())
	if y > 1:
		for j in range(y - 1):
			if a[j][x - 1] == 'R':
				count += 1
	if x > 1:
		for j in range(x - 1):
			if a[y - 1][j] == 'D':
				count += 1
	print(count)
	count = 0


t = int(input())
for _ in range(t):
	(r, c) = [int(i) for i in input().split()]
	arr = []
	for _ in range(r):
		arr.append(input())
	out = 0
	for i in range(c - 1):
		if arr[r - 1][i] == 'D':
			out += 1
	for i in range(r - 1):
		if arr[i][c - 1] == 'R':
			out += 1
	print(out)


for i in range(int(input())):
	we = [int(x) for x in input().split()]
	n = we[0]
	k = we[1]
	count = 0
	for j in range(n - 1):
		a = input()
		if a[len(a) - 1] != 'D':
			count += 1
	a = input()
	for j in range(len(a)):
		if a[j] != 'R':
			count += 1
	print(count - 1)


import sys, math, cmath, time
start_time = time.time()

def solve():
	(n, m) = invr()
	c = 0
	for i in range(n):
		s = insr()
		if s[-1] == 'R':
			c = c + 1
	print(c + s.count('D'))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

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

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = (q[ord(a[i]) - 97], 1)
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


def solve():
	(n, m) = map(int, input().split())
	b = [input() for _ in range(n)]
	bottom = b[-1][:-1]
	right = ''.join([r[-1] for r in b[:-1]])
	print(bottom.count('D') + right.count('R'))

def main():
	cases()

def cases():
	for _ in range(int(input())):
		solve()
main()


for _ in range(int(input())):
	(r, c1) = map(int, input().split())
	a = []
	for i in range(r):
		b = list(input())
		a.append(b)
	c = 0
	c += a[r - 1].count('D')
	for i in range(r):
		if a[i][c1 - 1] == 'R':
			c += 1
	print(c)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	c = 0
	for j in range(n):
		k = input()
		if j != n - 1 and k[-1] == 'R':
			c += 1
		elif j == n - 1:
			c += k.count('D')
	print(c)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		x = list(input())
		arr.append(x)
	change = 0
	for i in range(m):
		if arr[n - 1][i] == 'D':
			arr[n - 1][i] = 'R'
			change += 1
	for i in range(n):
		if arr[i][m - 1] == 'R':
			arr[i][m - 1] = 'D'
			change += 1
	print(change)


n = int(input())
for x in range(n):
	listt = []
	ij = list(map(int, input().split()))
	(i, j) = (ij[0], ij[1])
	ans = 0
	for y in range(i):
		listt.append(list(input()))
	for i in listt:
		if i[-1] == 'R':
			ans += 1
	for i in listt[-1]:
		if i == 'D':
			ans += 1
	print(ans)


t = int(input())
for case in range(t):
	inp = list(map(int, str.split(input(), ' ')))
	n = inp[0]
	m = inp[1]
	ans = 0
	a = [0] * n
	for i in range(n):
		a[i] = list(input())
	for i in range(n):
		if a[i][m - 1] == 'R':
			ans += 1
	for j in range(m):
		if a[n - 1][j] == 'D':
			ans += 1
	print(ans)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(input()))
	count = 0
	for i in l:
		if i[-1] != 'C' and i[-1] == 'R':
			count += 1
	p = l[-1]
	for i in p:
		if i != 'C' and i == 'D':
			count += 1
	print(count)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	for j in range(n - 1):
		if input()[-1] == 'R':
			c += 1
	p = input()
	for k in p:
		if k == 'D':
			c += 1
	print(c)


def solve():
	n = [int(i) for i in input().split()]
	row = n[0]
	col = n[1]
	lis = []
	for i in range(row):
		a = list(input())
		lis.append(a)
	count = 0
	for i in range(row):
		for j in range(col):
			if j == col - 1 and i != row - 1:
				if lis[i][j] == 'R':
					count += 1
			if i == row - 1 and j != col - 1:
				if lis[i][j] == 'D':
					count += 1
	print(count)
test = int(input())
while test:
	solve()
	test -= 1


for _ in range(int(input())):
	(n, m) = [int(__) for __ in input().split()]
	l1 = []
	for i in range(n - 1):
		l1.append(input()[-1])
	l2 = list(input())
	l2.pop()
	print(l1.count('R') + l2.count('D'))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		row = input()
		matrix.append(row)
	c = 0
	if n == 1 and m == 1:
		print(0)
	elif n == 1:
		for i in range(m - 1):
			if matrix[0][i] != 'R':
				c += 1
		print(c)
	elif m == 1:
		for i in range(n - 1):
			if matrix[i][0] != 'D':
				c += 1
		print(c)
	else:
		if matrix[n - 1][0] != 'R':
			c += 1
		if matrix[0][m - 1] != 'D' and n != 1:
			c += 1
		for i in range(1, m - 1):
			if matrix[n - 1][i] != 'R':
				c += 1
		for i in range(1, n - 1):
			if matrix[i][m - 1] != 'D':
				c += 1
		print(c)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		b = input()
		a.append(list(b))
	ans = 0
	for i in range(m - 1):
		if a[n - 1][i] != 'R':
			ans += 1
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lis = []
	ans = 0
	for i in range(n):
		temp = input()
		if i != n - 1 and temp[m - 1] == 'R':
			ans += 1
		if i == n - 1:
			for j in temp:
				if j == 'D':
					ans += 1
	print(ans)


def solve():
	(n, m) = map(int, input().split())
	lastline = []
	lastcol = []
	for _ in range(n):
		s = input()
		if _ + 1 < n:
			lastcol.append(s[-1])
		else:
			lastline = list(s)[:-1]
	print(lastcol.count('R') + lastline.count('D'))
t = int(input())
for _ in range(t):
	solve()


test = int(input())
for _ in range(test):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		r = list(input())
		mat.append(r)
	count = 0
	last = mat[-1]
	for i in range(m - 1):
		if last[i] != 'R':
			count += 1
	for i in range(n - 1):
		if mat[i][-1] != 'D':
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	st = ''.join((input() for _ in range(n)))
	res = 0
	for i in range(n):
		for j in range(m):
			index = j + i * m
			if st[index] == 'R' and j == m - 1:
				res += 1
			elif st[index] == 'D' and i == n - 1:
				res += 1
	print(res)


N = int(input())
for _ in range(N):
	(n, m) = map(int, input().strip().split())
	count = 0
	for i in range(n - 1):
		string = input()
		if string[m - 1] == 'R':
			count += 1
	last_string = input()
	for ele in last_string:
		if ele == 'D':
			count += 1
	print(count)


def min_cell(arr, n, m):
	count = 0
	for i in range(n):
		for j in range(m):
			if i != n - 1 and j == m - 1 and (arr[i][j] == 'R'):
				count += 1
			if i == n - 1 and arr[i][j] == 'D':
				count += 1
	return count
t = int(input())
for _ in range(t):
	nm = input().split()
	n = int(nm[0])
	m = int(nm[1])
	arr = []
	for i in range(n):
		s = input()
		arr.append(s)
	print(min_cell(arr, n, m))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a += [[k for k in input()]]
	ans = 0
	for i in range(n):
		for j in range(m):
			if j == m - 1 and i != n - 1 and (a[i][j] != 'D'):
				ans += 1
			elif i == n - 1 and j != m - 1 and (a[i][j] != 'R'):
				ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = 0
	a = []
	for _ in range(0, n):
		a.append(input())
	c = a[-1].count('D')
	for _ in a:
		if _[-1] == 'R':
			c += 1
	print(c)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	a = [input() for j in range(m)]
	cnt = 0
	for i in range(m - 1):
		if a[i][n - 1] != 'D':
			cnt += 1
	for i in range(n - 1):
		if a[m - 1][i] == 'D':
			cnt += 1
	print(cnt)


inp = lambda : map(int, input().split(' '))
(t,) = inp()
for _ in range(t):
	(n, m) = inp()
	res = 0
	for i in range(n - 1):
		temp = input()
		if temp[-1] == 'R':
			res += 1
	temp = input()
	for i in temp:
		if i == 'D':
			res += 1
	print(res)


for t in range(int(input())):
	a = list(map(int, input().split()))
	(n, m) = (a[0], a[1])
	field = [['a'] * m] * n
	cnt = 0
	bad = 0
	for i in range(n):
		s = str(input())
		s = list(s)
		field[i] = s
	for i in range(m - 1):
		if field[n - 1][i] != 'R':
			bad += 1
	for i in range(n - 1):
		if field[i][m - 1] != 'D':
			bad += 1
	print(bad)


from functools import lru_cache
from sys import stdin, stdout
import sys
for __ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = []
	dp = []
	for i in range(n):
		ar.append(input())
		dp.append([0] * (m + 1))
	dp.append([0] * (m + 1))
	count = 0
	dp[n - 1][m - 1] = 1
	for i in range(n - 1, -1, -1):
		for j in range(m - 1, -1, -1):
			if i == n - 1 and j == m - 1:
				continue
			elif ar[i][j] == 'R':
				if dp[i][j + 1] != 1:
					count += 1
				dp[i][j] = 1
			else:
				if dp[i + 1][j] != 1:
					count += 1
				dp[i][j] = 1
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	mat = [0 for x in range(n)]
	for i in range(n):
		mat[i] = input()
	ans = 0
	for i in mat[-1]:
		if i != 'R':
			ans += 1
	for i in range(n):
		if mat[i][-1] != 'D':
			ans += 1
	print(ans - 2)


t = int(input())
counter = []
for num in range(t):
	(n, m) = map(int, input().split())
	direction = []
	for i in range(n):
		a = input().split()
		a_array = []
		for j in range(m):
			a_array.append(a[0][j])
		direction.append(a_array)
	count = 0
	for i in range(m):
		if direction[n - 1][i] == 'D':
			count += 1
	for i in range(n):
		if direction[i][m - 1] == 'R':
			count += 1
	counter.append(count)
for i in range(len(counter)):
	print(counter[i])


t = int(input())
for x in range(t):
	matrix = []
	(n, m) = map(int, input().split())
	cnt_col = 0
	cnt_row = 0
	for i in range(n):
		s = input()
		a = []
		for j in range(m):
			a.append(s[j])
		matrix.append(a)
	for i in range(n):
		if matrix[i][m - 1] == 'R':
			cnt_col += 1
	for i in range(m):
		if matrix[n - 1][i] == 'D':
			cnt_row += 1
	print(cnt_col + cnt_row)


TC = int(input())
for tc in range(TC):
	(N, M) = map(int, input().split())
	A = [input() for _ in range(N)]
	ans = 0
	for r in range(N - 1):
		if A[r][-1] != 'D':
			ans += 1
	for c in range(M - 1):
		if A[-1][c] != 'R':
			ans += 1
	print(ans)


for rt in range(int(input())):
	(n, m) = map(int, input().split())
	s = [input() for i in range(n)]
	q = 0
	for i in range(n - 1):
		if s[i][m - 1] == 'R':
			q += 1
	for i in range(m - 1):
		if s[n - 1][i] == 'D':
			q += 1
	print(q)


for j in range(int(input())):
	(row, col) = map(int, input().split())
	li = []
	for j in range(row):
		li.append(input())
	mi = 0
	for j in range(0, len(li) - 1):
		if li[j][-1] == 'R':
			mi = mi + 1
	cou = 0
	for i in li[len(li) - 2]:
		if i == 'D':
			break
		else:
			cou = cou + 1
	for l in li[len(li) - 1]:
		if l == 'D':
			mi = mi + 1
	if li[row - 1][col - 1] != 'C':
		mi = mi + 1
	print(mi)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, m) = map(int, input().split())
	MAP = [input().strip() for i in range(n)]
	ANS = 0
	for i in range(n):
		if MAP[i][m - 1] == 'R':
			ANS += 1
	for j in range(m):
		if MAP[n - 1][j] == 'D':
			ANS += 1
	print(ANS)


import math
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = []
	E = 0
	for i in range(n):
		arr.append(list(str(input())))
	for i in range(m):
		if arr[n - 1][i] == 'D':
			E += 1
	for i in range(n):
		if arr[i][-1] == 'R':
			E += 1
	print(E)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	c = []
	for _ in range(a):
		d = input()
		c.append(d)
	e = c[-1].count('D')
	for _ in c:
		if _[-1] == 'R':
			e += 1
	print(e)


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

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

def inSList():
	return input().split()

def solve(rows, cols, grid):
	top = grid[-1]
	counter = 0
	for c in range(cols - 1):
		if top[c] == 'D':
			counter += 1
	for r in range(rows - 1):
		if grid[r][-1] == 'R':
			counter += 1
	print(counter)
tests = inInt()
for case in range(tests):
	dim = inIList()
	rows = dim[0]
	cols = dim[1]
	grid = []
	for r in range(rows):
		grid.append(inStr())
	solve(rows, cols, grid)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
for case in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	ans = 0
	for y in range(n):
		line = input().strip()
		if line[-1] == 'R':
			ans += 1
		if y == n - 1:
			ans += line.count('D')
	print(ans)


for i in range(int(input())):
	(n, m) = [int(num) for num in input().split()]
	lst = list()
	c = 0
	c1 = 0
	for i in range(n):
		x = input()
		if i == n - 1:
			y = x
		lst.append(x[-1])
	if len(y) != 0:
		for i in range(len(y) - 1):
			if y[i] == 'D':
				c = c + 1
	for i in range(len(lst)):
		if lst[i] == 'R':
			c1 = c1 + 1
	print(c + c1)


def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		a = [0] * n
		for i in range(n):
			a[i] = list(input())
		ans = 0
		for i in range(n):
			if a[i][-1] == 'R':
				ans += 1
		for i in range(m):
			if a[-1][i] == 'D':
				ans += 1
		print(ans)
main()


t = int(input())
for case in range(t):
	(n, m) = [int(a) for a in input().split(' ')]
	grid = []
	counter = 0
	for line in range(n):
		new_line = input()
		if new_line[-1] == 'R':
			counter += 1
		grid.append(new_line)
	counter += grid[-1].count('D')
	print(counter)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	b = []
	an = 0
	for j in range(n):
		b.append(list(input()))
	for j in range(n):
		if b[j][m - 1] == 'R':
			an += 1
	for j in range(m):
		if b[n - 1][j] == 'D':
			an += 1
	print(an)


for _ in range(int(input())):
	(n, m) = [int(j) for j in input().split()]
	k = 0
	for _ in range(n):
		s = input()
		if s[m - 1] == 'R':
			k += 1
	k += s.count('D')
	print(k)


import math
import os
import random
import re
import string
from sys import *
from collections import *

def bs(arr, x, l, r):
	if l <= r:
		mid = (r + l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return bs(arr, x, l, mid - 1)
		else:
			return bs(arr, x, mid + 1, r)
	else:
		return -1

def solve():
	for _ in range(int(stdin.readline())):
		(r, c) = map(int, stdin.readline().strip().split())
		mat = [list(input()) for i in range(r)]
		co = 0
		i = r - 1
		for j in range(c):
			if mat[i][j] == 'D':
				co += 1
		j = c - 1
		for i in range(r):
			if mat[i][j] == 'R':
				co += 1
		print(co)
solve()


t = int(input())
while t > 0:
	mat = []
	(n, m) = map(int, input().split(' '))
	for i in range(0, n):
		row = input()
		mat.append([char for char in row])
	last_row = mat[-1]
	last_col = [row[-1] for row in mat]
	result = last_row.count('D') + last_col.count('R')
	if mat[-1][-1] != 'C':
		result += 1
	print(result)
	t -= 1


from sys import stdin
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [[i for i in input()] for i in range(n)]
	cnt = 0
	for i in range(m - 1):
		if a[n - 1][i] != 'R':
			cnt += 1
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			cnt += 1
	print(cnt)


T = int(input())
for z in range(T):
	(n, m) = [int(x) for x in input().split()]
	count = 0
	for i in range(n - 1):
		s = input()
		if s[m - 1] == 'R':
			count += 1
	s = input()
	for i in range(m - 1):
		if s[i] == 'D':
			count += 1
	print(count)


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	a = []
	for i in range(r):
		a.append([str(x) for x in input().strip()])
	ans = 0
	for i in range(r - 1):
		if a[i][-1] == 'R':
			ans += 1
	for i in a[-1][:-1]:
		if i == 'D':
			ans += 1
	print(ans)


t = int(input())
while t > 0:
	(n, m) = map(int, input().split(' '))
	a = []
	for i in range(n):
		a.append(input())
	res = 0
	res += a[n - 1].count('D')
	var = ''
	for i in a:
		var += i[m - 1]
	res += var.count('R')
	print(res)
	t -= 1


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	(n, m) = num_input()
	mat = []
	for _ in range(n):
		mat.append(list(input()))
	count = 0
	for j in range(m - 1):
		if mat[n - 1][j] != 'R':
			count += 1
	for i in range(n - 1):
		if mat[i][m - 1] != 'D':
			count += 1
	print(count)
t = 1
t = int(input())
for _ in range(t):
	solve()


from sys import stdin

def input():
	return stdin.readline().rstrip()
T = int(input())
for i in range(T):
	res = 0
	(r, c) = map(int, input().split())
	for j in range(r):
		line = input()
		if j == r - 1:
			res += line.count('D')
		else:
			res += int(line[-1] == 'R')
	print(res)


t = int(input())
for q in range(t):
	(n, m) = map(int, input().split())
	matr = []
	for i in range(n):
		matr.append(input())
	kol = 0
	for j in range(m - 1):
		if matr[n - 1][j] != 'R':
			kol += 1
	for i in range(n - 1):
		if matr[i][m - 1] != 'D':
			kol += 1
	print(kol)


import sys
read = sys.stdin.readline
for _ in range(int(read())):
	(rows, cols) = map(int, read().split())
	step = 0
	for i in range(rows - 1):
		row_end = read().strip()[-1]
		if row_end == 'R':
			step += 1
	last_row = list(read().strip())
	for c in last_row:
		if c == 'D':
			step += 1
	print(step)


def process():
	(r, c) = map(int, input().split())
	mat = [[0] * c for _ in range(r)]
	arr = [input() for i in range(r)]
	mat[-1][-1] = 1
	changes = 0
	for row in range(r - 1, -1, -1):
		for col in range(c - 1, -1, -1):
			if row == r - 1 and col == c - 1:
				continue
			if arr[row][col] == 'R':
				try:
					if mat[row][col + 1] == 0:
						changes += 1
				except:
					changes += 1
			else:
				try:
					if mat[row + 1][col] == 0:
						changes += 1
				except:
					changes += 1
			mat[row][col] = 1
	print(changes)
for i in range(int(input())):
	process()


t = int(input())
for case in range(1, t + 1):
	(n, m) = list(map(int, input().split()))
	lines = [input() for _ in range(n)]
	changes = 0
	for x in range(n - 1):
		if lines[x][-1] != 'D':
			changes += 1
	for x in range(m - 1):
		if lines[-1][x] != 'R':
			changes += 1
	print(changes)


t = lambda : range(int(input()))
A = lambda : list(map(int, input().split()))
for _ in t():
	(n, m) = A()
	a = [input() for _ in range(n)]
	cD = 0
	for i in range(n - 1):
		if a[i][m - 1] != 'D':
			cD = cD + 1
	cR = 0
	for i in range(m - 1):
		if a[n - 1][i] != 'R':
			cR = cR + 1
	print(cD + cR)


def soln():
	(n, m) = map(int, input().split())
	li = []
	for i in range(n):
		li.append(input())
	count = 0
	for i in range(n):
		if i == n - 1:
			continue
		if li[i][m - 1] == 'R':
			count += 1
	for i in range(m):
		if i == m - 1:
			continue
		if li[n - 1][i] == 'D':
			count += 1
	print(count)
for i in range(int(input())):
	soln()


t = int(input())
for _ in range(t):
	count = 0
	(row, col) = list(map(int, input().strip().split()))
	mainarray = []
	for i in range(row):
		array = list(input())
		mainarray.append(array)
	for i in range(row):
		for j in range(col):
			if j == col - 1:
				if mainarray[i][j] == 'R':
					count += 1
			if i == row - 1:
				if mainarray[i][j] == 'D':
					count += 1
	print(count)


n = int(input())
list = []
for i in range(n):
	cr = 0
	cd = 0
	l = []
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	for i in range(x):
		l.append(input())
	if l == ['C']:
		list.append(0)
		continue
	for j in range(len(l) - 1):
		if l[j][-1] == 'R':
			cr += 1
	for j in range(y):
		if l[len(l) - 1][j] == 'D':
			cd += 1
	list.append(cr + cd)
for i in list:
	print(i)


t = int(input())
while t:
	t -= 1
	(n, m) = [int(x) for x in input().split()]
	arr = []
	for i in range(n):
		s = input()
		arr.append(s)
	ans = 0
	for i in range(n - 1):
		if arr[i][m - 1] != 'D':
			ans += 1
	for i in range(m - 1):
		if arr[n - 1][i] != 'R':
			ans += 1
	print(ans)


import math
from collections import Counter, defaultdict, deque
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for __ in range(I()):
	(n, m) = M()
	c = 0
	for i in range(n):
		s = input()
		if s[-1] == 'R':
			c += 1
		if i == n - 1:
			c += s.count('D')
	print(c)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = [list(input()) for i in range(n)]
	count = 0
	for i in range(m):
		if l[n - 1][i] == 'D':
			count += 1
	for i in range(n):
		if l[i][m - 1] == 'R':
			count += 1
	print(count)


f = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, m) = f()
	count = 0
	s = list()
	for i in range(n):
		temp = input()
		s.append(temp)
	for i in range(n):
		if i != n - 1:
			if s[i][m - 1] == 'R':
				count += 1
		else:
			count += s[i].count('D')
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	matrix = []
	if n == 1 and m == 1:
		s = input()
		print(0)
	else:
		ans = 0
		for i in range(n):
			x = list(input())
			matrix.append(x)
			if x[-1] != 'D' and i != n - 1:
				ans += 1
			if i == n - 1:
				for i in x[:-1]:
					if i != 'R':
						ans += 1
		print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	right_most = []
	for i in range(n - 1):
		right_most.append(list(input())[-1])
	bottom = list(input())
	print(right_most.count('R') + bottom.count('D'))


t = int(input())
results = []
for i in range(t):
	(n, m) = list(map(int, input().split()))
	count = 0
	for j in range(n):
		row = input()
		if row[-1] == 'R':
			count += 1
		if j == n - 1:
			nm = row
	for direction in nm:
		if direction == 'D':
			count += 1
	results.append(str(count))
print('\n'.join(results))


for _ in range(int(input())):
	X = list(map(int, input().split()))
	LastColumn = []
	for i in range(X[0] - 1):
		LastColumn.append(input()[-1])
	print(input().count('D') + LastColumn.count('R'))


T = int(input())
for _ in range(T):
	(n, m) = (int(i) for i in input().split())
	arr = []
	ans = 0
	for i in range(n):
		arr.append([i for i in input()])
	for i in range(n):
		if arr[i][-1] == 'R':
			ans += 1
	for i in arr[-1]:
		if i == 'D':
			ans += 1
	print(ans)


for t in range(int(input())):
	q = []
	(n, m) = map(int, input().split())
	for p in range(n):
		i = list(str(input()))
		if p == n - 1:
			for h in range(m):
				if i[h] == 'D':
					q.append(1)
		if i[-1] == 'R':
			q.append(1)
	print(len(q))


T = int(input())
while T > 0:
	list_i = [int(x) for x in input().split()]
	n = list_i[0]
	m = list_i[1]
	list_grid = []
	for i in range(n):
		list_grid.append(input())
	count = 0
	for i in range(len(list_grid) - 1):
		if list_grid[i][-1] == 'R':
			count += 1
	count += list_grid[-1].count('D')
	print(count)
	T -= 1


t = int(input())
for _ in range(t):
	inp = input().split()
	n = int(inp[0])
	m = int(inp[1])
	result = 0
	for i in range(n):
		s = input()
		if i != n - 1:
			if s[-1] == 'R':
				result += 1
		else:
			result += s.count('D')
	print(result)


def solve():
	line = input().split()
	n = int(line[0])
	m = int(line[1])
	count = 0
	for _ in range(n - 1):
		line = input()
		if line[-1] != 'D':
			count += 1
	line = input()
	for i in range(m - 1):
		if line[i] != 'R':
			count += 1
	print(count)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	count = 0
	for i in range(a - 1):
		c = input()
		if c[-1] == 'R':
			count += 1
	c = input()
	for i in range(b - 1):
		if c[i] == 'D':
			count += 1
	print(count)


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k)))) % NUMBER
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def get_num_2_5(n):
	twos = 0
	fives = 0
	while n > 0 and n % 2 == 0:
		n //= 2
		twos += 1
	while n > 0 and n % 5 == 0:
		n //= 5
		fives += 1
	return (twos, fives)

def shift(a, i, num):
	for _ in range(num):
		(a[i], a[i + 1], a[i + 2]) = (a[i + 2], a[i], a[i + 1])

def equal(x, y):
	return abs(x - y) <= 1e-09

def getAngle(a, b, c):
	ang = math.degrees(math.atan2(c[1] - b[1], c[0] - b[0]) - math.atan2(a[1] - b[1], a[0] - b[0]))
	return ang + 360 if ang < 0 else ang

def getLength(a, b):
	return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
from heapq import heapify, heappush, heappop

def bfs(adj):
	s = set()
	d = defaultdict(set)
	q = deque([])
	s.add(0)
	d[0].add(0)
	q.append((0, 0))
	while len(q) > 0:
		(v, depth) = q.popleft()
		for u in adj[v]:
			if u not in s:
				s.add(u)
				d[depth + 1].add(u)
				q.append((u, depth + 1))
	return d

def isSubsetSum(arr, n, summ):
	subarr = [[False for i in range(summ + 1)] for i in range(n + 1)]
	for i in range(n + 1):
		subarr[i][0] = True
	for i in range(1, summ + 1):
		subarr[0][i] = False
	for i in range(1, n + 1):
		for j in range(1, summ + 1):
			if j < arr[i - 1]:
				subarr[i][j] = subarr[i - 1][j]
			if j >= arr[i - 1]:
				subarr[i][j] = subarr[i - 1][j] or subarr[i - 1][j - arr[i - 1]]
	return subarr[n][summ]

def bfs(v, adj, onpath):
	s = set()
	d = defaultdict(set)
	q = deque([])
	s.add(0)
	d[0].add(0)
	q.append((0, 0))
	while len(q) > 0:
		(v, depth) = q.popleft()
		for u in adj[v]:
			if u not in s:
				s.add(u)
				d[depth + 1].add(u)
				q.append((u, depth + 1))
	return d

def solution(a, n, m):
	cnt = 0
	for i in range(m - 1):
		cnt += int(a[n - 1][i] == 'D')
	for i in range(n - 1):
		cnt += int(a[i][m - 1] == 'R')
	return cnt

def main():
	T = 1
	T = ri()
	for i in range(T):
		(n, m) = ria()
		a = []
		for i in range(n):
			a.append(rs())
		x = solution(a, n, m)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	lst = list()
	for i in range(n):
		lst.append([j for j in input()])
	count = 0
	if n != 1 and m != 1:
		for i in range(n - 1):
			if lst[i][m - 1] == 'R':
				count += 1
		for i in range(m - 1):
			if lst[n - 1][i] == 'D':
				count += 1
	elif n == 1:
		for i in range(m - 1):
			if lst[0][i] == 'D':
				count += 1
	elif m == 1:
		for i in range(n - 1):
			if lst[i][0] == 'R':
				count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	count1 = 0
	count2 = 0
	for x in range(n):
		st = input()
		if st[m - 1] == 'R':
			count1 = count1 + 1
	for x in st:
		if x == 'D':
			count2 = count2 + 1
	print(count2 + count1)


for u in range(int(input())):
	(n, m) = map(int, input().split())
	x = []
	for i in range(n):
		s = input()
		x.append(s)
	if n == 1:
		print(x[0].count('D'))
	else:
		ans = 0
		ans += x[-1].count('D')
		for i in range(n):
			if x[i][-1] == 'R':
				ans += 1
		print(ans)


t = int(input())
while t:
	(n, m) = map(int, input().split())
	l = []
	c = 0
	for i in range(n):
		l.append(list(input()))
	if n == 1 and m == 1:
		print(0)
		t -= 1
		continue
	for i in range(m):
		if l[n - 1][i] == 'D':
			l[n - 1][i] = 'R'
			c += 1
	for i in range(n):
		if l[i][m - 1] == 'R':
			l[i][m - 1] = 'D'
			c += 1
	print(c)
	t -= 1


t = int(input())
for i in range(t):
	(r, c) = map(int, input().split())
	l = []
	for j in range(r):
		st = input()
		l.append(st)
	sti = 0
	stj = 0
	cnt = 0
	for i in range(r - 1):
		if l[i][-1] == 'R':
			cnt += 1
	for k in l[-1]:
		if k == 'D':
			cnt += 1
	print(cnt)


def run():
	(row, column) = [int(i) for i in input().split()]
	ans = 0
	for i in range(row):
		temp = input()
		if i == row - 1:
			ans += temp.count('D')
			break
		if temp[-1] == 'R':
			ans += 1
	print(ans)
n = int(input())
for i in range(n):
	run()


for test in range(int(input())):
	(r, c) = map(int, input().split())
	l = []
	con = []
	ans = 0
	for i in range(r):
		s = input()
		l.append(s)
		if 'C' in s:
			con.append(i)
			con.append(s.index('C'))
	for i in range(r):
		for j in range(c):
			if l[i][j] != 'C':
				if i == con[0] and j < con[1] and (l[i][j] != 'R'):
					ans = ans + 1
				elif i < con[0] and j == con[1] and (l[i][j] != 'D'):
					ans = ans + 1
	print(ans)


def search(l, m, n):
	count = 0
	for i in range(m):
		if l[i][n - 1] == 'R':
			count = count + 1
		if i == m - 1:
			x = l[i].count('D')
			count = count + x
	return count
t = int(input())
s = []
for i in range(t):
	l = []
	(m, n) = map(int, input().split())
	for i in range(m):
		x = input()
		l.append(x)
	v = search(l, m, n)
	s.append(v)
for i in s:
	print(i)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, m) = LI()
		aa = [[c for c in S()] for _ in range(n)]
		r = 0
		for i in range(n - 1):
			if aa[i][-1] == 'R':
				r += 1
		for j in range(m - 1):
			if aa[-1][j] == 'D':
				r += 1
		rr.append(r)
	return JA(rr, '\n')
print(main())


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	l = []
	count = 0
	for i in range(n):
		temp = list(input())
		l.append(temp)
	(row, col) = (0, 0)
	i = 0
	while i < n:
		if l[i][m - 1] == 'R':
			count += 1
		i += 1
	i = 0
	while i < m:
		if l[n - 1][i] == 'D':
			count += 1
		i += 1
	print(count)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	ans = 0
	arr = []
	s = ''
	for i in range(n):
		s = input()
		arr.append(s[-1])
		if i == n - 1:
			for j in range(m - 1):
				if s[j] == 'D':
					ans += 1
	arr.pop()
	for i in range(len(arr)):
		if arr[i] == 'R':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	arr = list()
	for _ in range(m - 1):
		arr.append(input()[-1])
	row = list(input())
	cd = arr.count('R')
	cr = row.count('D')
	print(cd + cr)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	MX = []
	temp = list()
	for i in range(n):
		YYY = str(input())
		yy = list(YYY)
		a = []
		for j in range(len(yy)):
			a.append(yy[j])
		MX.append(a)
	count = 0
	for i in range(n):
		for j in range(m):
			if j == m - 1 and i < n - 1:
				if MX[i][j] == 'R':
					count += 1
			if i == n - 1:
				if MX[i][j] == 'D':
					count += 1
	print(count)


def solve(mat, n, m):
	if n > 1 and m > 1:
		cnt = 0
		for col in range(m):
			if mat[n - 1][col] == 'D':
				cnt += 1
		for row in range(n):
			if mat[row][m - 1] == 'R':
				cnt += 1
	elif m == 1:
		cnt = 0
		for row in range(n):
			if mat[row][m - 1] == 'R':
				cnt += 1
	else:
		cnt = 0
		for col in range(m):
			if mat[n - 1][col] == 'D':
				cnt += 1
	return cnt

def read():
	t = int(input())
	for i in range(t):
		mat = []
		(n, m) = list(map(int, input().strip().split()))
		for j in range(n):
			s = input().strip()
			mat.append(s)
		ans = solve(mat, n, m)
		print(ans)
read()


production = True
import sys, math, collections, bisect, itertools, heapq, decimal, random, copy, re

def input(f=0, m=0):
	if m > 0:
		return [input(f) for i in range(m)]
	else:
		l = sys.stdin.readline()[:-1]
		if f >= 10:
			u = False
			f = int(str(f)[-1])
		else:
			u = True
		if f == 0:
			p = [l]
		elif f == 1:
			p = list(map(int, l.split()))
		elif f == 2:
			p = list(map(float, l.split()))
		elif f == 3:
			p = list(l)
		elif f == 4:
			p = list(map(int, list(l)))
		elif f == 5:
			p = l.split()
		return p if u else p[0]

def out(l, f=0, n=True):
	if f == 0:
		p = str(l)
	elif f == 1:
		p = ' '.join(map(str, l))
	elif f == 2:
		p = '\n'.join(map(str, l))
	elif f == 3:
		p = ''.join(map(str, l))
	print(p, end='\n' if n else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enu = enumerate
ter = lambda a, b, c: b if a else c
ceil = lambda a, b: -(-a // b)

def mapl(i, f=0):
	if f == 0:
		return list(map(int, i))
	elif f == 1:
		return list(map(str, i))
	elif f == 2:
		return list(map(list, i))

def solve():
	(n, m) = input(1)
	a = input(3, n)
	t = 0
	for i in a[-1]:
		if i == 'D':
			t += 1
	for i in range(n):
		if a[i][-1] == 'R':
			t += 1
	out(t)
	log()
	return
for i in range(input(11)):
	solve()


import sys
import string
from collections import defaultdict
from functools import lru_cache
from collections import Counter

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def solve(mat):
	c = 0
	for i in range(len(mat) - 1):
		if mat[i][-1] == 'R':
			c += 1
	for j in range(len(mat[-1]) - 1):
		if mat[-1][j] == 'D':
			c += 1
	print(c)

def main(mats):
	for mat in mats:
		solve(mat)
mats = []
mat = []
x = 0
for (e, line) in enumerate(sys.stdin.readlines()):
	if e == 0:
		continue
	elif x == 0:
		if mat:
			mats.append(mat)
		(x, _) = mi(line)
		mat = []
	else:
		mat.append(line.strip())
		x -= 1
if mat:
	mats.append(mat)
main(mats)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	li = []
	for i in range(n):
		s = input()
		li.append(s)
	ans = li[n - 1].count('D')
	for i in range(n):
		if li[i][m - 1] == 'R':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	grid = []
	for jj in range(n):
		row = list(input())
		grid.append(row)
	to_change = 0
	for j in range(0, len(grid[0])):
		if grid[n - 1][j] == 'D':
			to_change += 1
	for i in range(0, len(grid)):
		if grid[i][-1] == 'R':
			to_change += 1
	print(to_change)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append(list(input())[:m])
	c = 0
	for i in range(n):
		for j in range(m):
			if i == n - 1 and grid[i][j] == 'D':
				c += 1
			if j == m - 1 and grid[i][j] == 'R':
				c += 1
	print(c)


def func(grid: list, c: tuple) -> int:
	count = 0
	(i, ind) = c
	for k in range(ind):
		if grid[i][k] == 'D':
			count += 1
	for k in range(i):
		if grid[k][ind] == 'R':
			count += 1
	return count
T = int(input())
grid_list = list(list(str()))
c_list = list(tuple())
for _ in range(T):
	grid = list(str())
	(n, m) = map(int, input().split())
	for i in range(n):
		num = input()
		if 'C' in num:
			c_list.append((i, num.index('C')))
		grid.append(num)
	grid_list.append(grid)
for i in range(len(c_list)):
	print(func(grid_list[i], c_list[i]))


import math
import sys
import bisect
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(input()))
	cnt = 0
	for i in range(n):
		if l[i][m - 1] == 'R':
			cnt += 1
	for j in range(m):
		if l[n - 1][j] == 'D':
			cnt += 1
	print(cnt)


t = int(input())
while t:
	t = t - 1
	ans = 0
	(n, m) = map(int, input().split())
	for i in range(n):
		w = input()
		if i < n - 1:
			if w[m - 1] == 'R':
				ans = ans + 1
		else:
			for q in range(m - 1):
				if w[q] == 'D':
					ans = ans + 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	(n, m) = RL()
	res = 0
	for _ in range(n - 1):
		s = input()
		if s[-1] != 'D':
			res += 1
	s = input()
	res += s[:-1].count('D')
	print(res)


def solve():
	count = 0
	(n, m) = list(map(int, input().split()))
	for i in range(n):
		S = input()
		if i != n - 1:
			if S[m - 1] == 'R':
				count += 1
		else:
			for j in range(m - 1):
				if S[j] == 'D':
					count += 1
	print(count)

def main():
	t = int(input())
	for i in range(t):
		solve()
main()


for k in range(int(input())):
	(n, m) = map(int, input().split())
	u = 0
	if n == 1:
		y = list(input())
		for j in range(m):
			if y[j] == 'D':
				u += 1
		if y[-1] == 'R':
			u += 1
	else:
		for j in range(n):
			y = list(input())
			if j == 0:
				if y[-1] == 'R':
					u += 1
			elif j == n - 1:
				if y[-1] == 'R':
					u += 1
				for r in range(m - 1):
					if y[r] == 'D':
						u += 1
			elif y[-1] == 'R':
				u += 1
	print(u)


t = int(input())
for i in range(t):
	temp = [int(x) for x in input().split()]
	n = temp[0]
	m = temp[1]
	a = []
	for i in range(n):
		a.append(input().strip())
	result = 0
	for i in range(n):
		if a[i][-1] == 'R':
			result += 1
	result += a[-1].count('D')
	print(result)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	mt = []
	for i in range(n):
		li = list(input())
		mt.append(li)
	c = 0
	for r in range(n - 1):
		if mt[r][m - 1] == 'R':
			c += 1
	for i in range(m - 1):
		if mt[n - 1][i] == 'D':
			c += 1
	print(c)


j = int(input())
for _ in range(j):
	(l, k) = map(int, input().split())
	chances = 0
	for i in range(l):
		word = input()
		if word[-1] != 'D' and word[-1] != 'C':
			chances += 1
		elif i == l - 1:
			y = 0
			while y < len(word):
				if word[y] != 'R' and word[y] != 'C':
					chances += 1
				y += 1
	print(chances)


import sys
input = sys.stdin.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def prog():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		grid = [input().strip() for i in range(n)]
		change = 0
		for j in range(m):
			if grid[n - 1][j] == 'D':
				change += 1
		for i in range(n):
			if grid[i][m - 1] == 'R':
				change += 1
		print(change)
prog()


from collections import defaultdict
import itertools
import statistics
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		h = input()
		if h[-1] == 'R':
			ans += 1
	for i in h:
		if i == 'D':
			ans += 1
	print(ans)


tc = int(input())
for ctr in range(tc):
	(r, c) = map(int, input().split())
	m = [input().strip() for i in range(r)]
	count = 0
	for i in range(0, r - 1):
		if m[i][c - 1] == 'R':
			count += 1
	for j in range(0, c - 1):
		if m[r - 1][j] == 'D':
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = [int(_) for _ in input().split()]
	A = []
	c = 0
	for _ in range(n):
		x = input()
		A.append(x)
		if x[-1] == 'R':
			c += 1
	print(c + A[-1].count('D'))


import sys
import math

def addtodic(a, n):
	d = {}
	for i in range(n):
		if a[i] in d:
			d[a[i]] += 1
		else:
			d[a[i]] = 1
	return d

def testcase(a):
	count = 0
	for i in range(n - 1):
		if a[i][-1] == 'R':
			count += 1
	for i in range(m - 1):
		if a[-1][i] == 'D':
			count += 1
	return count
for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	a = []
	for i in range(n):
		s = input()
		temp = []
		for i in range(len(s)):
			temp.append(s[i])
		a.append(temp)
	print(testcase(a))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	c = 0
	for i in range(n):
		e = list(str(input()))
		if e[m - 1] == 'R':
			c += 1
		elif i == n - 1:
			for i in e:
				if i == 'D':
					c += 1
				if i == 'C':
					break
	print(c)


t = int(input())
for _ in range(t):
	a = []
	ans = 0
	(n, m) = map(int, input().split())
	for i in range(n):
		x = input()
		a.append(x)
	if n == 1 and m == 1:
		print(0)
	else:
		for k in range(n):
			if a[k][-1] == 'R':
				ans += 1
		y = a[-1].count('D')
		ans += y
		print(ans)


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

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

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
mo = 1000000007
t = inn()
while t:
	t -= 1
	(n, m) = value()
	a = []
	for i in range(n):
		l = [str(x) for x in input()]
		a += [l]
	c = 0
	for i in range(n):
		if a[i][-1] == 'R':
			c += 1
	for i in range(m):
		if a[n - 1][i] == 'D':
			c += 1
	print(c)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	for t in range(I()):
		(n, m) = In()
		c = 0
		for i in range(n):
			s = input()
			if i != n - 1:
				if s[m - 1] == 'R':
					c += 1
			else:
				for j in range(m):
					if j != m - 1:
						if s[j] == 'D':
							c += 1
		print(c)
main()


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	do = []
	ri = []
	for j in range(n):
		st = input()
		do.append(st[m - 1])
		if j == n - 1:
			ri = list(st)
	c = 0
	for k in range(n - 1):
		if do[k] == 'R':
			c = c + 1
	for k in range(m - 1):
		if ri[k] == 'D':
			c = c + 1
	print(c)


t = int(input())
while t != 0:
	(n, m) = map(int, input().split())
	grid = list((list(input().replace('', ' ').split()) for i in range(n)))
	count = 0
	for i in range(n - 1):
		if grid[i][m - 1] != 'D':
			count += 1
	for i in range(m - 1):
		if grid[n - 1][i] != 'R':
			count += 1
	print(count)
	t = t - 1


def inp2():
	ar = input()
	ar = ar.split(' ')
	(a, b) = (int(ar[0]), int(ar[1]))
	return (a, b)
t = int(input())
for i in range(t):
	(n, m) = inp2()
	ans = 0
	for i in range(n - 1):
		s = input()
		if s[m - 1] == 'R':
			ans += 1
	s = input()
	for i in range(m - 1):
		if s[i] == 'D':
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	ans = 0
	for i in range(a):
		l = input()
		if i == a - 1:
			ans += l.count('D')
		elif l[b - 1] == 'R':
			ans += 1
		else:
			continue
	print(ans)


t = int(input())
while t:
	t -= 1
	(r, c) = input().split()
	arr = [input() for x in range(int(r))]
	q = arr[-1]
	ans = 0
	for x in q:
		if x == 'D':
			ans += 1
	for x in range(len(arr)):
		if arr[x][-1] == 'R':
			ans += 1
	print(ans)


for test in range(0, int(input())):
	(n, m) = [int(x) for x in input().split()]
	count = 0
	for i in range(0, n):
		s = input()
		if i == n - 1:
			for j in range(0, len(s)):
				if s[j] == 'D':
					count += 1
		elif s[-1] == 'R':
			count += 1
	print(count)


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
	(n, m) = f()
	a = []
	ans = 0
	for i in range(0, n):
		a.append(list(si()))
	for i in range(0, n):
		if a[i][m - 1] == 'R':
			ans = ans + 1
	for j in range(0, m):
		if a[n - 1][j] == 'D':
			ans = ans + 1
	print(ans)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		s = input()
		a.append(s)
	k = 0
	c = 0
	if m == 1 and n == 1:
		print(0)
	elif n == 1 or m == 1:
		if n == 1:
			for i in range(m - 1):
				if a[0][i] == 'D':
					c = c + 1
			print(c)
		if m == 1:
			for i in range(n - 1):
				if a[i][0] == 'R':
					c = c + 1
			print(c)
	else:
		for i in range(n - 1):
			if a[i][m - 1] == 'R':
				c = c + 1
		for i in range(m - 1):
			if a[n - 1][i] == 'D':
				c = c + 1
		print(c)


t = int(input())
while t > 0:
	t -= 1
	(row, col) = map(int, input().split())
	p = []
	for i in range(row):
		s = input()
		p.append(s)
	c = 0
	for i in range(row - 1):
		if p[i][col - 1] == 'R':
			c += 1
	for i in range(col - 1):
		if p[row - 1][i] == 'D':
			c += 1
	print(c)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [list(input()) for _ in range(n)]
	ans = 0
	for i in range(m - 1):
		if a[-1][i] != 'R':
			a[-1][i] = 'R'
			ans += 1
	for i in range(n - 1):
		if a[i][-1] != 'D':
			a[i][-1] = 'D'
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	cnt_d = 0
	(n, m) = list(map(int, input().split(' ')))
	for i in range(n - 1):
		l = input()
		if l[-1] == 'R':
			cnt_d += 1
	l = input()
	for i in l:
		if i == 'D':
			cnt_d += 1
	print(cnt_d)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
num = inp()
for t in range(num):
	pair = inlt()
	n = pair[0]
	m = pair[1]
	counter = 0
	for i in range(n):
		s = insr()
		if s[m - 1] == 'R':
			counter += 1
		if i == n - 1:
			for char in s:
				if char == 'D':
					counter += 1
	print(counter)


def solve(grid):
	n = len(grid)
	m = len(grid[0])
	ans = 0
	for i in range(m - 1):
		ans += 1 if grid[n - 1][i] != 'R' else 0
	for i in range(n - 1):
		ans += 1 if grid[i][m - 1] != 'D' else 0
	return ans
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for _ in range(n):
		row = list(input())
		grid.append(row)
	ans = solve(grid)
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	co = 0
	for i in range(n):
		s = input()
		if i == n - 1:
			co += s.count('D')
		elif s[-1] == 'R':
			co += 1
	print(co)


for _ in range(int(input())):
	mat = []
	ans = 0
	(r, c) = map(int, input().split())
	for i in range(r):
		mat.append(input())
		if i < r - 1 and mat[i][c - 1] == 'R':
			ans += 1
		elif i == r - 1:
			for j in mat[i][:-1]:
				if j == 'D':
					ans += 1
	print(ans)


T = int(input())
while T:
	(n, m) = map(int, input().split())
	X = []
	for i in range(n):
		X.append(list(input()))
	c = 0
	for i in range(n - 1):
		if X[i][m - 1] == 'R':
			c += 1
	for j in range(m - 1):
		if X[n - 1][j] == 'D':
			c += 1
	print(c)
	T = T - 1


def main():
	(n, m) = map(int, input().split(' '))
	res = 0
	for i in range(n):
		line = input()
		if i != n - 1:
			if line[-1] != 'D':
				res += 1
		else:
			for j in range(0, m - 1):
				if line[j] != 'R':
					res += 1
	return res
for _ in range(int(input())):
	print(main())


for tc in range(int(input())):
	(N, M) = map(int, input().split())
	A = [list(input()) for i in range(N)]
	ans = 0
	for i in range(M):
		if A[-1][i] == 'D':
			ans += 1
	for i in range(N):
		if A[i][-1] == 'R':
			ans += 1
	print(ans)


def main():
	for _ in range(int(input())):
		(n, m) = list(map(int, input().split()))
		a = [input() for _ in range(n)]
		print(sum([a[i][-1] != 'D' for i in range(n - 1)]) + sum([a[-1][j] != 'R' for j in range(m - 1)]))
main()


t = int(input())
while t > 0:
	t -= 1
	line = input().split(' ')
	n = int(line[0])
	m = int(line[1])
	graph = []
	for i in range(0, n):
		line = input()
		graph.append(line)
	changes = 0
	if graph[0][m - 1] != 'D' and graph[0][m - 1] != 'C':
		changes += 1
	for i in range(1, n - 1):
		if graph[i][m - 1] != 'D':
			changes += 1
	for i in range(0, m - 1):
		if graph[n - 1][i] != 'R':
			changes += 1
	print(changes, flush=True)


def main():
	from sys import stdin, stdout
	N = int(input())
	lines = [a.strip() for a in stdin.readlines()]
	count = 0
	k = 0
	while k < len(lines):
		(row, col) = lines[k].split(' ')
		(row, col) = (int(row), int(col))
		k += 1
		grid = []
		for _ in range(row):
			grid.append(lines[k])
			k += 1
		for i in range(row - 2, -1, -1):
			if grid[i][-1] != 'D':
				count += 1
		for j in range(col - 2, -1, -1):
			if grid[-1][j] != 'R':
				count += 1
		print(count)
		count = 0
main()


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
t = int(input())
for tc in range(t):
	(n, m) = list(map(int, stdin.readline().split()))
	table = []
	for nc in range(n):
		row = [x for x in stdin.readline().strip()]
		table.append(row)
	sorted = ['r', 'd', 'C']
	res = 0
	for i in range(n):
		for j in range(m):
			x = i
			y = j
			while True:
				c = table[x][y]
				if c in sorted:
					break
				elif c == 'D' and x == n - 1:
					res += 1
					table[x][y] = 'd'
					break
				elif c == 'R' and y == m - 1:
					res += 1
					table[x][y] = 'r'
					break
				elif c == 'D':
					table[x][y] = 'd'
					x += 1
				else:
					table[x][y] = 'r'
					y += 1
	stdout.write(str(res) + '\n')


testcases = int(input())
for i in range(testcases):
	n = list(map(int, input().split()))
	moves = 0
	for i in range(n[0] - 1):
		temp = input()
		if temp[-1] == 'R':
			moves += 1
	temp = input()
	for i in range(len(temp) - 1):
		if temp[i] == 'D':
			moves += 1
	print(moves)


for _ in '*' * int(input()):
	(x, y) = map(int, input().split())
	print(sum((1 for i in range(x - 1) if input()[-1] == 'R')) + input().count('D'))


t = int(input())
while t > 0:
	t -= 1
	ss = ''
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n - 1):
		sq = input()
		if sq[len(sq) - 1] == 'R':
			ans += 1
	ss = input()
	for i in range(m - 1):
		if ss[i] == 'D':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	al = [list(input()) for _ in range(n)]
	ans = 0
	for ni in range(n):
		if al[ni][-1] == 'R':
			ans += 1
	for mi in range(m):
		if al[-1][mi] == 'D':
			ans += 1
	print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	(n, m) = rinput()
	a = []
	for i in range(n):
		a.append(input())
	if n == 1 and m == 1:
		print(0)
		continue
	ans = 0
	for j in range(m - 1):
		if a[-1][j] != 'R':
			ans += 1
	for i in range(n - 1):
		if a[i][-1] != 'D':
			ans += 1
	print(ans)


def main():
	for i in range(int(input())):
		change = 0
		(row, column) = list(map(int, input().split()))
		for i in range(row - 1):
			r = input()
			change += 1 if r[-1] == 'R' else 0
		last = input()
		change += sum([1 for i in last if i == 'D'])
		print(change)
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	x = 0
	for i in range(n):
		s = input()
		if i != n - 1:
			if s[m - 1] == 'R':
				x += 1
		else:
			for j in s:
				if j == 'D':
					x += 1
	print(x)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	res = 0
	i = j = 0
	val = []
	for _ in range(n):
		val.append(list(input()))
	while i < n:
		if val[i][m - 1] == 'R':
			res += 1
		i += 1
	while j < m:
		if val[n - 1][j] == 'D':
			res += 1
		j += 1
	print(res)


t = int(input())
for tt in range(t):
	dim = list(map(int, input().split()))
	m = dim[0]
	n = dim[1]
	chnges = 0
	for j in range(m - 1):
		strange = input()
		if strange[-1] == 'R':
			chnges += 1
	strange = input()
	for (i, j) in enumerate(strange):
		if i == len(strange) - 1:
			break
		if j == 'D':
			chnges += 1
	print(chnges)


t = 1
t = int(input())
while t:
	t -= 1
	(n, m) = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		temp = input()
		if i == n - 1:
			ans += temp.count('D')
		else:
			ans = ans + 1 if temp[-1] == 'R' else ans
	print(ans)


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

def getNM():
	return map(int, input().split())

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

def input():
	return sys.stdin.readline().rstrip()

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return False
for _ in range(int(input())):
	(n, m) = getNM()
	table = []
	for i in range(n):
		table.append(input())
	ans = 0
	for i in range(n):
		if table[i][m - 1] == 'R':
			ans += 1
	for i in table[-1]:
		if i == 'D':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(m, n) = list(map(int, input().split()))
	count = 0
	for __ in range(m):
		a = input()
		if a[n - 1] == 'R':
			count += 1
	count += a.count('D')
	print(count)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	box = []
	for k in range(n):
		box.append(list(map(str, input().split())))
	changes = 0
	for k in range(m):
		if box[n - 1][0][k] == 'D':
			changes += 1
	for k in range(n):
		if box[k][0][m - 1] == 'R':
			changes += 1
	print(changes)


def min_steps(arr, m, n):
	steps = 0
	for s in arr[-1]:
		if s == 'D':
			steps += 1
	for i in range(m):
		if arr[i][-1] == 'R':
			steps += 1
	print(steps)
tests = int(input())
for t in range(tests):
	(m, n) = list(map(int, input().split()))
	arr = []
	for i in range(m):
		words = input()
		arr.append(words)
	min_steps(arr, m, n)


test = int(input())
while test:
	(n, m) = map(int, input().split())
	ans = 0
	down = 0
	for i in range(1, n + 1):
		str = input()
		for ind in range(0, len(str)):
			if ind is m - 1 and str[ind] is 'R':
				ans += 1
		down = str.count('D')
	print(ans + down)
	test -= 1


def solve():
	args = [int(x) for x in input().split()]
	n = args[0]
	m = args[1]
	l = ''
	ct = 0
	for i in range(n):
		l = input()
		if l[-1] == 'R':
			ct += 1
		if i == n - 1:
			for ch in l:
				if ch == 'D':
					ct += 1
	print(ct)
t = int(input())
for i in range(t):
	solve()


def main():
	(r, c) = list(map(int, input().split()))
	grid = [input() for _ in range(r)]
	count = 0
	for i in range(len(grid) - 1):
		if grid[i][-1] != 'D':
			count += 1
	for i in grid[-1][:-1]:
		if i != 'R':
			count += 1
	return count
for i in range(int(input())):
	print(main())


from sys import stdin, stdout
from math import gcd, sqrt, factorial
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(r, c) = R()
	a = []
	cnt = 0
	for i in range(r):
		x = S()
		if x[-1] == 'R':
			cnt += 1
		a += (x,)
	print(cnt + a[-1].count('D'))


import sys

def read(s):
	return list(s[:len(s) - 1])
groups = sys.stdin.readline()
for i in range(int(groups)):
	a = 0
	n = sys.stdin.readline()
	n = n.split(' ')
	lines = int(n[0])
	for j in range(lines - 1):
		l = read(sys.stdin.readline())
		if l[-1] == 'R':
			a += 1
	l = read(sys.stdin.readline())
	for i in l:
		if i == 'D':
			a += 1
	print(a)


a = int(input())
for _ in range(a):
	(n, m) = [int(i) for i in input().split()]
	(l, c, s, k) = ([], 0, '', [])
	for i in range(n):
		l.append(input())
	for i in range(n - 1):
		if l[i][m - 1] == 'R':
			c += 1
	for i in range(m):
		if l[n - 1][i] == 'D':
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	last_c = []
	last_r = ''
	for _ in range(n):
		last_r = input()
		last_c.append(last_r[-1])
	c = 0
	for x in last_r[:-1]:
		if x != 'R':
			c += 1
	for x in last_c[:-1]:
		if x != 'D':
			c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [list(input()) for i in range(n)]
	res = 0
	if n == 1 and m > 1:
		for i in a[0]:
			if i != 'C' and i == 'D':
				res += 1
	elif m == 1 and n == 1:
		res = 0
	else:
		for i in range(n):
			if a[i][-1] != 'C' and a[i][-1] == 'R':
				res += 1
		for i in range(m):
			if a[-1][i] != 'C' and a[-1][i] == 'D':
				res += 1
	print(res)


for test in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(input())
	coun = 0
	coun += arr[-1].count('D')
	for i in range(n):
		if arr[i][-1] == 'R':
			coun += 1
	print(coun)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lst = [input() for i in range(n)]
	print(lst[-1].count('D') + sum((i[-1] == 'R' for i in lst)))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	ans = 0
	a = []
	for i in range(n):
		a.append(list(input()))
	for ai in range(n):
		for aj in range(m):
			(i, j) = (ai, aj)
			flag = False
			while flag:
				if i == n - 1 and a[i][j] == 'D':
					flag = False
				elif j == m - 1 and a[i][j] == 'R':
					flag = False
				elif a[i][j] == 'R':
					j += 1
					flag = True
				elif a[i][j] == 'D':
					i += 1
					flag = True
				if i == n - 1 and j == m - 1:
					break
			if flag == False:
				if i == n - 1:
					for k in range(j, m - 1):
						if a[i][k] == 'D':
							a[i][k] = 'R'
							ans += 1
				elif j == m - 1:
					for k in range(i, n - 1):
						if a[k][j] == 'R':
							a[k][j] = 'D'
							ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	conv = []
	for i in range(n):
		row = list(input())
		conv.append(row)
	ans = 0
	for i in range(n):
		if conv[i][m - 1] == 'R':
			ans += 1
	for i in range(m):
		if conv[n - 1][i] == 'D':
			ans += 1
	print(ans)


for i in range(int(input())):
	(row, col) = map(int, input().split())
	m = []
	for j in range(row):
		st = input()
		m.append([x for x in st])
	ch = 0
	if m[row - 1][col - 1] != 'C':
		ch += 1
	for j in range(row):
		if m[j][col - 1] == 'R':
			ch += 1
	for j in range(col):
		if m[row - 1][j] == 'D':
			ch += 1
	print(ch)


T = int(input())
for t in range(T):
	(n, m) = list(map(int, input().split()))
	li = []
	for i in range(n):
		li.append(input())
	i = 0
	j = 0
	count = 0
	while i < n and j < m:
		if li[i][j] == 'R' and j != m - 1:
			j += 1
		elif li[i][j] == 'R' and j == m - 1:
			count += 1
			i += 1
			j = 0
		elif li[i][j] == 'D' and i == n - 1:
			count += 1
			j += 1
		elif li[i][j] == 'D' and i != n - 1 and (j == m - 1):
			j = 0
			i += 1
		elif li[i][j] == 'D' and i != n - 1:
			j += 1
		elif li[i][j] == 'C':
			break
	print(count)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())
sys.setrecursionlimit(1500)

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, m) = In()
		l = []
		for x in range(n):
			temp = list(input())
			l.append(temp.copy())
		cnt = 0
		for x in range(n - 1):
			if l[x][-1] != 'D':
				cnt += 1
		for x in range(m - 1):
			if l[-1][x] != 'R':
				cnt += 1
		print(cnt)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


import sys
t = int(sys.stdin.readline())
ans_arr = []
for x in range(t):
	[n, m] = [int(i) for i in sys.stdin.readline().split()]
	arr = []
	for i in range(n):
		s = sys.stdin.readline().strip()
		arr.append(s)
	ctr = 0
	for a in range(m):
		if arr[n - 1][a] == 'D':
			ctr += 1
	for b in range(n):
		if arr[b][m - 1] == 'R':
			ctr += 1
	ans_arr.append(str(ctr))
print('\n'.join(ans_arr))


results = []
tests = int(input())
for _x in range(tests):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = []
	for i in range(n):
		a.append(input())
	count = 0
	for i in range(n):
		if a[i][m - 1] == 'R':
			count += 1
	for i in range(m):
		if a[n - 1][i] == 'D':
			count += 1
	results.append(count)
print(*results, sep='\n')


t = int(input())
for i in range(t):
	changes = 0
	(n, m) = map(int, input().split())
	for i in range(n - 1):
		if input()[-1] != 'D':
			changes += 1
	a = input()
	for i in a[:-1]:
		if i != 'R':
			changes += 1
	print(changes)


import sys
input = sys.stdin.readline
I = lambda : list(map(str, input().split()))
(m,) = I()
m = int(m)
while m:
	m -= 1
	(a, b) = I()
	a = int(a)
	b = int(b)
	s = 0
	for i in range(a):
		(arr,) = I()
		if arr[b - 1] == 'C':
			for j in range(b):
				if arr[j] == 'D':
					s += 1
		elif arr[b - 1] == 'R':
			s += 1
	print(s)


from sys import stdin, stdout
import bisect
import math
from collections import deque, Counter
mod = 10 ** 9 + 7

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def DFS(dictionary, vertex, visited):
	visited[vertex] = True
	stack = [vertex]
	print(vertex)
	while stack:
		a = stack.pop()
		for i in dictionary[a]:
			if not visited[i]:
				print(i)
				visited[i] = True
				stack.append(i)

def BFS(dictionary, vertex, visited):
	visited[vertex] = True
	q = deque()
	q.append(vertex)
	while q:
		a = q.popleft()
		for i in dictionary[a]:
			if not visited[i]:
				visited[i] = True
				q.append(i)
				print(i)

def soe(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def solve():
	(n, m) = mp()
	x = []
	y = []
	for i in range(n):
		s = list(input())
		if i != n - 1:
			x.append(s[-1])
		else:
			y = list(s[:-1])
	print(x.count('R') + y.count('D'))
for _ in range(inp()):
	solve()


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	l = []
	for i in range(m):
		l.append(list(map(str, input().strip())))
	cnt = 0
	if m == 1:
		for x in range(n):
			if l[0][x] != 'R':
				cnt += 1
		print(cnt - 1)
	else:
		for x in range(n - 1):
			if l[m - 1][x] != 'R':
				cnt += 1
		for y in range(m - 1):
			if l[y][n - 1] == 'R':
				cnt += 1
		print(cnt)


import sys
input = sys.stdin.readline

def main():
	(n, m) = map(int, input().split())
	conv = [input().strip() for _ in range(n)]
	ans = 0
	for i in range(m - 1):
		if conv[n - 1][i] == 'D':
			ans += 1
	for i in range(n - 1):
		if conv[i][m - 1] == 'R':
			ans += 1
	print(ans)
for _ in range(int(input())):
	main()


t = int(input())
for ii in range(t):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		l = list(input())
		mat.append(l)
	cnt = 0
	for i in range(n - 1):
		if mat[i][m - 1] != 'D':
			cnt += 1
	for i in range(m - 1):
		if mat[n - 1][i] != 'R':
			cnt += 1
	print(cnt)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	(n, m) = mi()
	ans = 0
	for i in range(n - 1):
		s = input()
		if s[-1] == 'R':
			ans += 1
	ans += input().count('D')
	print(ans)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	(n, m) = map(int, input().split())
	lis = []
	for i in range(n):
		lis.append(input())
	answer = 0
	for i in range(n):
		if lis[i][m - 1] == 'R':
			answer += 1
	for i in range(m):
		if lis[n - 1][i] == 'D':
			answer += 1
	print(answer)


import math
import sys
import itertools
import random
import bisect
import heapq
import collections

def lcm(x, y):
	return x * y // math.gcd(x, y)

def hcf(x, y):
	return math.gcd(x, y)

def primes(n):
	prime = [True for _ in range(0, n + 1)]
	res = []
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[p] = False
		p += 1
	for i in range(0, n + 1):
		if prime[i] == True:
			res.append(i)
	return res

def primeFactors(n):
	res = []
	while n % 2 == 0:
		res.append(2)
		n //= 2
	for i in range(3, math.sqrt(n) + 1, 2):
		while n % i == 0:
			res.append(i)
			n //= i
	if n > 2:
		res.append(n)
	return res
for _ in range(0, int(input())):
	(n, m) = map(int, input().strip().split())
	mat = []
	for i in range(0, n):
		mat.append(list(input().strip()))
	last_row = mat[-1]
	res = 0
	for i in last_row:
		if i != 'C':
			if i == 'D':
				res += 1
	last_col = []
	for i in range(0, n):
		last_col.append(mat[i][-1])
	for i in last_col:
		if i != 'C':
			if i == 'R':
				res += 1
	print(res)


T = int(input())
for j in range(T):
	(n1, m1) = map(int, input().split())
	mat1 = []
	c = 0
	for i in range(n1):
		l = input()
		if l[-1] == 'R':
			c += 1
		mat1.append(l)
	c1 = mat1[-1].count('D')
	print(c1 + c)


import sys
input = sys.stdin.readline
tc = int(input())
for _ in range(tc):
	(r, c) = map(int, input().split())
	map_ = [list(input().rstrip()) for _ in range(r)]
	count = 0
	for i in range(r):
		if map_[i][c - 1] == 'R':
			count += 1
	for i in range(c):
		if map_[r - 1][i] == 'D':
			count += 1
	print(count)


t = int(input())
while t:
	t += -1
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		s = list(input())
		if i < n - 1:
			if s[m - 1] != 'D':
				ans -= -1
		else:
			for j in s[:m - 1]:
				if j != 'R':
					ans -= -1
	print(ans)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input())
	s = 0
	for i in range(n):
		if i < n - 1:
			if l[i][-1] == 'R':
				s += 1
		else:
			for j in range(len(l[i])):
				if l[i][j] == 'D':
					s += 1
	print(s)


def solve():
	(n, m) = [int(i) for i in input().split()]
	ans = 0
	for i in range(n):
		a = input()
		if i == n - 1:
			ans += a.count('D')
		if a[-1] == 'R':
			ans += 1
	return ans
t = int(input())
ans = []
while t:
	ans.append(str(solve()))
	t -= 1
print('\n'.join(ans))


rr = lambda : input().strip()
rrm = lambda : map(int, rr().split())

def solve():
	(n, m) = rrm()
	ans = 0
	for i in range(n):
		s = rr()
		if s[-1] == 'R':
			ans += 1
	ans += s.count('D')
	return ans
T = int(rr())
for _ in range(T):
	ans = solve()
	print(ans)


t = int(input())
for i in range(t):
	ans1 = 0
	(n, m) = list(map(int, input().split()))
	for j in range(n):
		s = input()
		if s[len(s) - 1] == 'R':
			ans1 = ans1 + 1
	ans2 = s.count('D')
	print(ans1 + ans2)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = list()
	for i in range(0, n):
		a = list(input())
		matrix.append(a)
	count = 0
	for i in range(n):
		if matrix[i][m - 1] == 'R':
			count += 1
			matrix[i][m - 1] = 'D'
		else:
			continue
	for i in range(m):
		if matrix[n - 1][i] == 'D':
			count += 1
			matrix[n - 1][i] = 'R'
	print(count)


import sys, math, heapq, collections, itertools, bisect
sys.setrecursionlimit(101000)

def solve(n, m, a):
	sol = 0
	for i in range(m - 1):
		if a[n - 1][i] == 'D':
			sol += 1
	for i in range(n - 1):
		if a[i][m - 1] == 'R':
			sol += 1
	return sol
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [input() for _ in range(n)]
	print(solve(n, m, a))


for i in range(int(input())):
	(n, m) = [int(elem) for elem in input().split()]
	board = ['0'] * n
	counter = 0
	for i in range(n):
		board[i] = input()
	for j in range(m - 1):
		if board[n - 1][j] != 'R':
			counter += 1
	for i in range(n - 1):
		if board[i][m - 1] != 'D':
			counter += 1
	print(counter)


test_cnt = int(input())
tests = []
for _ in range(test_cnt):
	(m, n) = list(map(int, input().split()))
	conv = []
	for i in range(m):
		conv.append(list(input()))
	tests.append((m, n, conv))
for test in tests:
	(m, n, conv) = test
	count = 0
	count += n - 1 - conv[m - 1].count('R')
	down = [line[n - 1] for line in conv]
	count += m - 1 - down.count('D')
	print(count)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	array = []
	total = 0
	for x in range(n):
		array.append(input())
	for x in range(n - 1):
		if array[x][m - 1] == 'R':
			total += 1
	for x in array[n - 1]:
		if x == 'D':
			total += 1
	print(total)


def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		s = []
		for _ in range(n):
			s.append(input())
		if n == m == 1:
			print(0)
		else:
			cnt = 0
			for i in range(n):
				if s[i][m - 1] == 'R':
					cnt += 1
			for j in range(m):
				if s[n - 1][j] == 'D':
					cnt += 1
			print(cnt)
main()


def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		total = 0
		for i in range(n - 1):
			line = input()
			if line[-1] != 'D':
				total += 1
		bottom = input()
		total += bottom.count('D')
		print(total)
main()


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(H, W) = MAP()
	grid = [[]] * H
	for i in range(H):
		grid[i] = list(input())
	ans = 0
	for i in range(H):
		if grid[i][-1] == 'R':
			ans += 1
	for i in range(W):
		if grid[-1][i] == 'D':
			ans += 1
	print(ans)


def solve(n, m, grid):
	to_be_changed = 0
	for i in range(0, m):
		if grid[n - 1][i] == 'D':
			to_be_changed += 1
	for j in range(0, n):
		if grid[j][m - 1] == 'R':
			to_be_changed += 1
	return to_be_changed
t = int(input())
for i in range(0, t):
	(n, m) = map(int, input().split())
	grid = list()
	for j in range(0, n):
		row = input()
		grid.append(row)
	print(solve(n, m, grid))


t = int(input())
while t:
	(n, m) = map(int, input().split())
	l = []
	(c1, c2) = (0, 0)
	for i in range(n):
		s = input()
		l.append(s)
	for i in range(len(l) - 1):
		if l[i][m - 1] == 'R':
			c1 += 1
	c2 = l[-1].count('D')
	print(c1 + c2)
	t = t - 1


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	need = 0
	for i in range(n):
		curr = input()
		need += curr[-1] == 'R'
		if i == n - 1:
			need += curr.count('D')
	print(need)


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	for _ in range(IP()):
		(n, m) = MP()
		ans = 0
		for i in range(n):
			st = IPS()
			if i != n - 1:
				ans += st[-1] != 'D'
			else:
				for j in range(m - 1):
					ans += st[j] != 'R'
		print(ans)
solve()


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')
MOD = 1000000007

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

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

def bs(arr, num):
	l = 0
	r = len(arr)
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= num:
			r = m - 1
		else:
			l = m + 1
	return l

def main():
	(n, m) = vars()
	mat = []
	for i in range(n):
		mat.append(input())
	ans = 0
	for i in range(n - 1):
		if mat[i][-1] == 'R':
			ans += 1
	for i in range(m - 1):
		if mat[-1][i] == 'D':
			ans += 1
	print(ans)
t = int(input())
for _ in range(t):
	main()


import math
import collections
import bisect

def arrPrint(a):
	return ' '.join([str(i) for i in a])

def gridPrint(a):
	return '\n'.join([' '.join([str(j) for j in a[i]]) for i in range(len(a))])

def isPalindrome(s):
	for i in range(len(s) // 2):
		if not s[i] == s[-i - 1]:
			return False
	return True

def primeCheck(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def solve(n, m, grid):
	ans = 0
	for i in range(n):
		if grid[i][-1] == 'R':
			ans += 1
	for i in range(m):
		if grid[-1][i] == 'D':
			ans += 1
	return ans
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	grid = []
	for _ in range(n):
		grid.append(list(input()))
	print(solve(n, m, grid))


for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	board = []
	t = 0
	for i in range(n):
		board.append(input())
	for row in board:
		if row[-1] == 'R':
			t += 1
	t += board[-1].count('D')
	print(t)


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	i = 0
	grid = []
	while i < n:
		row = input()
		row = list(row)
		grid.append(row)
		i += 1
	ans = 0
	i = 0
	while i < n - 1:
		if grid[i][m - 1] != 'D':
			ans += 1
		i += 1
	i = 0
	while i < m - 1:
		if grid[n - 1][i] != 'R':
			ans += 1
		i += 1
	print(ans)


t = int(input())
for i in range(0, t):
	inp = input().split()
	n = int(inp[0])
	m = int(inp[1])
	belt = []
	for j in range(0, n):
		belt.append(list(input()))
	prod = m * n
	r = 0
	for z in range(0, n):
		if belt[z][m - 1] == 'R':
			belt[z][m - 1] = 'D'
			r = r + 1
	for w in range(0, m):
		if belt[-1][w] == 'D':
			belt[-1][w] = 'R'
			r = r + 1
	print(r)


t = int(input())
while t:
	(n, m) = [int(i) for i in input().split()]
	l = []
	x = 0
	y = 0
	for i in range(n):
		n1 = input()
		l.append(n1)
	for i in range(n - 1):
		if l[i][m - 1] != 'D':
			x += 1
	for j in range(m - 1):
		if l[-1][j] != 'R':
			y += 1
	print(x + y)
	t -= 1


t = int(input())

def cekubah(Tab, bar, kol):
	ubah = 0
	for i in range(bar):
		if Tab[i][kol - 1] == 'R' and i != bar - 1:
			ubah += 1
		if i == bar - 1:
			for j in range(kol):
				if Tab[i][j] == 'D':
					ubah += 1
	return ubah
output = []
for i in range(t):
	TabInput = []
	barkol = input().split(' ')
	for j in range(int(barkol[0])):
		satubaris = input()
		TabInput += [list(satubaris)]
	output += [cekubah(TabInput, int(barkol[0]), int(barkol[1]))]
for row in output:
	print(row)


import sys
input = sys.stdin.readline
from bisect import bisect_left
from bisect import bisect_right
from math import ceil, factorial

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, m) = int_array()
	a = []
	for __ in range(n):
		a.append(list(input().strip()))
	ans = 0
	for i in range(n - 1):
		if a[i][m - 1] == 'R':
			ans += 1
	for i in range(m - 1):
		if a[n - 1][i] == 'D':
			ans += 1
	print(ans)


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		(N, M) = map(int, input().split())
		A = [input() for _ in [0] * N]
		ans = A[-1].count('D')
		for i in range(N):
			if A[i][-1] == 'R':
				ans += 1
		print(ans)
main()


from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(n, m) = map(int, stdin.readline().split())
	s = []
	for i in range(n):
		tmp = stdin.readline()
		s.append(tmp[:-1])
	ans = 0
	for i in range(n):
		for j in range(m):
			if i == n - 1 and s[i][j] == 'D':
				ans += 1
			elif j == m - 1 and s[i][j] == 'R':
				ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	ls = []
	ctr = 0
	for j in range(n):
		ls.append([a for a in input()])
	for j in range(m):
		if ls[-1][j] == 'D':
			ctr += 1
	for j in range(n):
		if ls[j][-1] == 'R':
			ctr += 1
	print(ctr)


n = int(input())
for i in range(n):
	(a, b) = [int(i) for i in input().split()]
	e = 1
	f = 0
	for j in range(a):
		s = str(input())
		if e == a:
			f = f + s.count('D')
		elif s[len(s) - 1] == 'R':
			f = f + 1
		e = e + 1
	print(f)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	list1 = []
	counter = 0
	for i in range(n):
		st = input()
		list1.append(st)
		if st[-1] == 'R':
			counter += 1
	counter += list1[-1].count('D')
	print(counter)


import math
t = int(input())
for test in range(t):
	(n, m) = map(int, input().split())
	A = []
	ans = 0
	for i in range(n):
		s = input()
		A.append(s)
		if s[-1] == 'R':
			ans += 1
	for j in range(m):
		if A[n - 1][j] == 'D':
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	count = 0
	for j in range(n):
		s = input()
		if s[m - 1] != 'D' and j != n - 1:
			count += 1
	count += s.count('D')
	print(count)


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 6)
	t = int(input())
	for _ in range(t):
		(n, m) = [int(x) for x in input().strip().split()]
		ans = 0
		for i in range(n - 1):
			if input().strip()[-1] == 'R':
				ans += 1
		ans += input().strip().count('D')
		print(ans)
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	lst = []
	for i in range(n):
		lst.append(str(input()))
	ans = 0
	for i in range(n):
		if lst[i][m - 1] == 'R':
			ans += 1
	for i in range(m):
		if lst[n - 1][i] == 'D':
			ans += 1
	print(ans)


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		s = input()
		ls = [x for x in s]
		mat.append(ls)
	count = 0
	for i in range(len(mat)):
		if mat[i][-1] == 'R':
			count += 1
	count += mat[-1].count('D')
	print(count)


nt = int(input())
for test in range(nt):
	inp = input().strip().split()
	(n, m) = (int(inp[0]), int(inp[1]))
	mat = []
	for i in range(n):
		mat.append(input().strip())
	ans = 0
	for j in range(m):
		if mat[-1][j] == 'D':
			ans += 1
	for i in range(n):
		if mat[i][-1] == 'R':
			ans += 1
	print(ans)


import math
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	cnt = 0
	for i in range(n):
		a = input()
		if i != n - 1:
			if a[-1] != 'D':
				cnt += 1
		else:
			cnt += a.count('D')
	print(cnt)


T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	mat = [input() for i in range(n)]
	ans = 0
	for j in range(m):
		if mat[n - 1][j] == 'D':
			ans += 1
	for i in range(n):
		if mat[i][m - 1] == 'R':
			ans += 1
	print(ans)


query = int(input())
for _ in range(query):
	count = 0
	(n, m) = map(int, input().split())
	for i in range(n):
		belt = input()
		if i == n - 1:
			count += belt.count('D')
		elif belt[m - 1] == 'R':
			count += 1
	print(count)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	lista = []
	cont = 0
	for i in range(n):
		r = input()
		if r[m - 1] == 'R':
			cont += 1
		lista.append(r)
	print(cont + lista[n - 1].count('D'))


n = int(input())
for i in range(n):
	r = -2
	(x, y) = input().split()
	for i in range(int(x)):
		a = input()
		if a[-1] != 'D':
			r += 1
	for j in a:
		if j != 'R':
			r += 1
	print(r)


a = int(input())
for _ in range(a):
	(x, y) = map(int, input().split())
	li = [0] * x
	count = 0
	for i in range(x):
		li[i] = input()
	for i in range(x):
		if li[i][y - 1] == 'R':
			count += 1
	for i in range(y):
		if li[x - 1][i] == 'D':
			count += 1
	print(count)


from sys import stdin
from collections import defaultdict
import math
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().rstrip().split(' ')))
	grid = []
	for i in range(n):
		grid.append(input().rstrip())
	change = 0
	change += grid[n - 1].count('D')
	for i in range(n):
		if grid[i][m - 1] == 'R':
			change += 1
	print(change)


import sys
TEST = 0
if TEST == 1:
	input_file = open('inputB.txt', 'r')
	input_from_file = input_file.readlines()

def read_int():
	if TEST:
		return int(input_from_file.pop(0))
	else:
		return int(sys.stdin.readline())

def read_ints():
	if TEST:
		return list(map(int, input_from_file.pop(0).rstrip().split()))
	else:
		return list(map(int, sys.stdin.readline().split()))

def read_str():
	if TEST:
		in1 = input_from_file.pop(0).rstrip()
	else:
		in1 = sys.stdin.readline().rstrip()
	return in1

def read_str_to_list():
	if TEST:
		in1 = input_from_file.pop(0).rstrip()
	else:
		in1 = sys.stdin.readline().rstrip()
	return [x for x in in1]

def going_bfs(i, j, grid):
	node_queue = [(i, j)]
	num_ok = 0
	while len(node_queue) > 0:
		(node_i, node_j) = node_queue.pop(0)
		if node_i > 0:
			if grid[node_i - 1][node_j] == 'D':
				num_ok += 1
				node_queue.append((node_i - 1, node_j))
		if node_j > 0:
			if grid[node_i][node_j - 1] == 'R':
				num_ok += 1
				node_queue.append((node_i, node_j - 1))
	return num_ok
tests = read_int()
for test in range(tests):
	(n, m) = read_ints()
	grid = []
	num_bad = 0
	for _ in range(n):
		str1 = read_str_to_list()
		if str1[m - 1] == 'R':
			num_bad += 1
	for j in range(m - 1):
		if str1[j] == 'D':
			num_bad += 1
	print(num_bad)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
sys.setrecursionlimit(10 ** 6)
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		s = list(input())
		l.append(s)
	vis = set()
	mini1 = 10 ** 18
	mini2 = 10 ** 18
	for i in range(n):
		for j in range(m):
			(x, y) = (i, j)
			if (x, y) in vis:
				pass
			else:
				while True:
					if (x, y) in vis:
						break
					vis.add((x, y))
					if l[x][y] == 'D':
						if x + 1 >= n:
							mini1 = min(y, mini1)
							break
						else:
							x += 1
					elif y + 1 >= m:
						mini2 = min(x, mini2)
						break
					else:
						y += 1
	ans = 0
	for i in range(mini1, m - 1):
		if l[n - 1][i] != 'R':
			ans += 1
	for i in range(mini2, n - 1):
		if l[i][m - 1] != 'D':
			ans += 1
	print(ans)


tc = int(input())
while tc > 0:
	tc -= 1
	(n, m) = map(int, input().split())
	ans = 0
	k = list()
	for i in range(n):
		s = input()
		if s[m - 1] == 'R':
			ans += 1
		k.append(s)
	ans += k[n - 1].count('D')
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = [[str(x) for x in input()] for i in range(n)]
	c = 0
	for i in range(m):
		if a[n - 1][i] == 'D':
			c += 1
	for i in range(n):
		if a[i][m - 1] == 'R':
			c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = [int(i) for i in input().split()]
	matrix = []
	ans = 0
	str = ''
	for i in range(n):
		str = input()
		if str[m - 1] == 'R':
			ans += 1
	for i in range(m):
		if str[i] == 'D':
			ans += 1
	print(ans)


ll = lambda : list(map(int, input().split()))
lls = lambda : list(map(str, input().split()))
st = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
from math import *
from datetime import datetime
from sys import stdin, stdout

def lcm(a, b):
	return a * b // gcd(a, b)
from collections import *
for _ in range(ii()):
	(n, m) = v()
	l = []
	for i in range(n):
		l.append(st())
	c = 0
	for i in l:
		if i[-1] == 'R':
			c += 1
	c += l[-1].count('D')
	print(c)


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
input = stdin.readline
letters = ascii_letters[:26]
direction = {'R': (0, 1), 'D': (1, 0)}
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [list(input().strip()) for i in range(n)]
	count = 0
	for i in range(n):
		if arr[i][-1] == 'R':
			count += 1
	for i in range(m):
		if arr[-1][i] == 'D':
			count += 1
	print(count)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
for _ in range(L()[0]):
	(n, m) = L()
	A = [input() for i in range(n)]
	ans = 0
	for i in range(n - 1):
		if A[i][-1] != 'D':
			ans += 1
	for j in range(m - 1):
		if A[-1][j] != 'R':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	res = 0
	for _ in range(n):
		s = input()
		if s[-1] == 'R':
			res += 1
		elif s[-1] == 'C':
			res += s.count('D')
	print(res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class union_find:

	def __init__(self, n):
		self.n = n
		self.rank = [0] * n
		self.parent = [int(j) for j in range(n)]

	def union(self, i, j):
		i = self.find(i)
		j = self.find(j)
		if self.rank[i] == self.rank[j]:
			self.parent[i] = j
			self.rank[j] += 1
		elif self.rank[i] > self.rank[j]:
			self.parent[j] = i
		else:
			self.parent[i] = j

	def find(self, i):
		temp = i
		if self.parent[temp] != temp:
			self.parent[temp] = self.find(self.parent[temp])
		return self.parent[temp]
from math import log2, ceil
from collections import deque, Counter as CC

def main():
	for t in range(int(input())):
		(n, m) = [int(j) for j in input().split()]
		l = []
		for i in range(n):
			l.append(list(input()))
		ans = 0
		for i in range(n - 1):
			if l[i][m - 1] == 'R':
				ans += 1
		for i in range(m - 1):
			if l[n - 1][i] == 'D':
				ans += 1
		print(ans)
main()


t = int(input())
d = {}
for s in range(t):
	k = str(input()).split(' ')
	ar = []
	for i in range(int(k[0])):
		b = str(input())
		bb = []
		for j in range(len(b)):
			bb.append(b[j])
		ar.append(bb)
	d[s] = (k, ar)
for key in d.keys():
	step = 0
	for j in range(len(d[key][1])):
		if len(d[key][1]) == 1:
			for i in range(int(d[key][0][1]) - 1):
				if d[key][1][j][i] != 'R':
					d[key][1][j][i] = 'R'
					step += 1
			break
		else:
			if d[key][1][j][int(d[key][0][1]) - 1] != 'D' and d[key][1][j][int(d[key][0][1]) - 1] != 'C':
				d[key][1][j][int(d[key][0][1]) - 1] = 'D'
				step += 1
			if d[key][1][j][int(d[key][0][1]) - 1] == 'C':
				for i in range(int(d[key][0][1]) - 1):
					if d[key][1][j][i] != 'R':
						d[key][1][j][i] = 'R'
						step += 1
	print(step)


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	c = 0
	for x in range(n - 1):
		p = input()
		if p[-1] == 'R':
			c += 1
	p = input()
	for x in p:
		if x == 'D':
			c += 1
	print(c)


t = int(input())
while t:
	t = t - 1
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(1, n + 1):
		str = input()
		if i == n:
			for j in range(0, m - 1):
				if str[j] == 'D':
					ans += 1
		elif str[m - 1] == 'R':
			ans += 1
	print(ans)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

def Int():
	return int(sys.stdin.readline())

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

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

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

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def solution():
	for _ in range(Int()):
		(n, m) = Mint()
		ans = 0
		for i in range(n):
			s = input()
			if i == n - 1:
				ans += s.count('D')
			elif s[-1] == 'R':
				ans += 1
		print(ans)
solution()


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

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

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def main():
	t = inp()
	for _ in range(t):
		(n, m) = invr()
		change = 0
		for i in range(n - 1):
			temp = input()
			if temp[-1] != 'D':
				change += 1
		temp = input()
		for i in range(m - 1):
			if temp[i] != 'R':
				change += 1
		print(change)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().strip().split()))
	a = [list(input()) for i in range(n)]
	c = 0
	i = n - 1
	for j in range(m - 1):
		if a[i][j] != 'R':
			c += 1
	j = m - 1
	for i in range(n - 1):
		if a[i][j] != 'D':
			c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	result = 0
	for i in range(n - 1):
		line = input()
		if line[-1] == 'R':
			result += 1
	line = input()
	for i in line:
		if i == 'D':
			result += 1
	print(result)


t = int(input())
change = 0
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	arr = [[''] * m] * n
	for j in range(n):
		arr[j] = input()
	for j in range(m):
		if arr[n - 1][j] == 'D':
			change += 1
	for j in range(n):
		if arr[j][m - 1] == 'R':
			change += 1
	print(change)
	change = 0


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = []
	for j in range(n):
		b = input()
		a.append(b)
		if j == n - 1:
			d = b.count('D')
	c = [a[j][m - 1] for j in range(n)]
	r = c.count('R')
	print(r + d)


import io
import os
from collections import Counter, defaultdict, deque

def solve(R, C, grid):
	count = 0
	for r in range(R):
		for c in range(C):
			if r == R - 1 and c == C - 1:
				continue
			elif r == R - 1:
				if grid[r][c] == 'D':
					count += 1
			elif c == C - 1:
				if grid[r][c] == 'R':
					count += 1
	return count
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, M) = [int(x) for x in input().split()]
	grid = [input().decode().rstrip() for i in range(N)]
	ans = solve(N, M, grid)
	print(ans)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 0
	for i in range(n):
		temp = list(input())
		if i == n - 1:
			for j in range(m - 1):
				if temp[j] != 'R':
					ans += 1
		elif temp[-1] != 'D':
			ans += 1
	print(ans)


for _ in range(int(input())):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	l = []
	for i in range(n):
		a = input()
		l.append(a)
	count = 0
	for i in range(n - 1):
		if l[i][m - 1] == 'R':
			count += 1
	for i in range(m - 1):
		if l[n - 1][i] == 'D':
			count += 1
	print(count)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	g = [input()[:-1] for i in range(n)]
	ans = 0
	for i in range(n):
		ans += g[i][-1] == 'R'
	print(ans + g[-1].count('D'))


t = int(input())
while t:
	line = input().split()
	(n, m) = (int(line[0]), int(line[1]))
	cnt = 0
	for i in range(n):
		s = input()
		if i != n - 1:
			cnt += s[-1] == 'R'
		else:
			for j in range(m):
				cnt += s[j] == 'D'
	print(cnt)
	t -= 1


val = int(input())
for i in range(val):
	(n, m) = list(map(int, input().split()))
	down = []
	right = []
	for i in range(n):
		x = input()
		right += x[-1]
		if i == n - 1:
			down += x
	c = 0
	for i in down:
		if i == 'D':
			c += 1
	for i in right:
		if i == 'R':
			c += 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = ''.join((input() for row in range(n)))
	answer = 0
	for x in range(m):
		if grid[(n - 1) * m + x] == 'D':
			answer += 1
	for x in range(n):
		if grid[x * m + m - 1] == 'R':
			answer += 1
	print(answer)


i = int(input())
for counter in range(0, i):
	inputs = input().split(' ')
	rows = int(inputs[0])
	characters = int(inputs[1])
	list = []
	for count in range(0, rows):
		inp = input()
		list.append(inp)
	changes = 0
	for elem in list:
		if elem[-1] == 'R':
			changes += 1
	for elem in list[-1]:
		if elem == 'D':
			changes += 1
	print(changes)


t = int(input())
c = []
for _ in range(t):
	changes = 0
	(n, m) = list(map(int, input().split()))
	for i in range(n):
		row = input()
		if i != n - 1 and row[-1] == 'R':
			changes += 1
		elif i == n - 1:
			changes += row.count('D')
	c.append(changes)
for _ in c:
	print(_)


for x in range(int(input())):
	(n, m) = map(int, input().split())
	(r, d) = (0, 0)
	matrix = []
	for i in range(n):
		b = list(input())
		matrix.append(b)
	for z in range(n):
		if matrix[z][m - 1] == 'R':
			r += 1
	for z in range(m):
		if matrix[n - 1][z] == 'D':
			d += 1
	print(r + d)


dr = [0, 1]
dc = [1, 0]
t = int(input())
for _ in range(t):
	(N, M) = map(int, input().split())
	bd = [list(input()) for _ in range(N)]

	def changer():
		cnt = 0
		for i in range(M - 1):
			if bd[N - 1][i] == 'D':
				cnt += 1
		for i in range(N - 1):
			if bd[i][M - 1] == 'R':
				cnt += 1
		return cnt
	print(changer())


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	gd = []
	cnt = 0
	for i in range(n):
		t = list(input())
		if t[-1] == 'R':
			cnt += 1
		if i == n - 1:
			cnt += t.count('D')
	print(cnt)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = list()
	res = 0
	for _ in range(n):
		s = input()
		mat.append(s)
	for i in range(0, m - 1):
		if mat[n - 1][i] == 'D':
			res += 1
	for i in range(n - 1):
		if mat[i][m - 1] == 'R':
			res += 1
	print(res)


import sys
import math

def II():
	return int(sys.stdin.readline())

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	(n, m) = MI()
	count = 0
	for i in range(n):
		l = list(SI())
		for j in range(m):
			if i == n - 1 and j != m - 1 and (l[j] == 'D'):
				count += 1
			if i != n - 1 and j == m - 1 and (l[j] == 'R'):
				count += 1
	print(count)


from collections import *
from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	g = []
	for i in range(n):
		s = input()
		a = []
		for i in s:
			a.append(i)
		g.append(a)
	vis = [[0 for i in range(m)] for j in range(n)]
	Q = deque([(n - 1, m - 1)])
	cn = 0
	xr = [-1, 0]
	yr = [0, -1]
	while Q:
		l = len(Q)
		for i in range(l):
			(x, y) = Q.popleft()
			(r, d) = (0, 0)
			if x + 1 < n:
				d = 1
			if y + 1 < m:
				r = 1
			if r == 1 and d == 0:
				if g[x][y] == 'D':
					cn += 1
					g[x][y] = 'R'
			elif d == 1 and r == 0:
				if g[x][y] == 'R':
					cn += 1
					g[x][y] = 'D'
			for i in range(2):
				(p, q) = (x + xr[i], y + yr[i])
				if p >= 0 and q >= 0 and (vis[p][q] == 0):
					vis[p][q] = 1
					Q.append((p, q))
	stdout.write(str(cn) + '\n')


def answer(n, m, A):
	count = 0
	for i in range(0, n - 1):
		if A[i][m - 1] == 'R':
			count += 1
	for i in range(0, m - 1):
		if A[n - 1][i] == 'D':
			count += 1
	return count
t = int(input())
for i in range(t):
	l = []
	(n, m) = map(int, input().split())
	for j in range(n):
		l.append(input())
	print(answer(n, m, l))


t = int(input())
for k in range(t):
	changes = 0
	(n, m) = (int(i) for i in input().split())
	for i in range(n):
		line = input()
		if line[-1] == 'R':
			changes += 1
	changes += line.count('D')
	print(changes)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(a, result) = ([], 0)
	for i in range(n):
		a.append(input())
	for i in range(n):
		if i == n - 1:
			for k in range(m):
				if a[n - 1][k] == 'D':
					a[n - 1] = a[i][:k] + 'R' + a[i][k + 1:]
					result += 1
		elif a[i][m - 1] == 'R':
			a[i] = a[i][:-1] + 'D'
			result += 1
	print(result)


t = int(input())
while t != 0:
	(n, m) = [int(i) for i in input().split()]
	a = []
	for i in range(n):
		s = input()
		a.append(s)
	count = 0
	for i in range(len(a) - 1, len(a)):
		for j in range(len(a[i])):
			if a[i][j] == 'D':
				count += 1
	for i in range(len(a)):
		if a[i][m - 1] == 'R':
			count += 1
	print(count)
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
for q in range(t):
	(n, m) = map(int, input().split())
	a = [[None for _ in range(m)] for j in range(n)]
	for i in range(n):
		s = str(input())
		for j in range(m):
			a[i][j] = s[j]
	ans = 0
	for i in range(n - 1):
		if a[i][m - 1] == 'R':
			ans += 1
	for j in range(m - 1):
		if a[n - 1][j] == 'D':
			ans += 1
	print(ans)


def ans(A):
	ret = 0
	for c in A[-1][:-1]:
		if c != 'R':
			ret += 1
	for row in A[:-1]:
		if row[-1] != 'D':
			ret += 1
	return ret
T = int(input())
for _ in range(T):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	A = []
	for _ in range(n):
		A += [input()]
	print(ans(A))


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
import math
import heapq
i_m = 9223372036854775807

def inin():
	return int(input())

def stin():
	return input()

def spin():
	return map(int, stin().split())

def lin():
	return list(map(int, stin().split()))

def matrix(n):
	return [list(map(int, input().split())) for i in range(n)]

def count2Dmatrix(i, list):
	return sum((c.count(i) for c in list))

def modinv(n, p):
	return pow(n, p - 2, p)

def GCD(x, y):
	x = abs(x)
	y = abs(y)
	if min(x, y) == 0:
		return max(x, y)
	while y:
		(x, y) = (y, x % y)
	return x

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
prime = []

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j
for _ in range(inin()):
	(n, m) = spin()
	c = 0
	for i in range(n):
		a = list(input())
		if i == n - 1:
			c += a.count('D')
		elif a[m - 1] == 'R':
			c += 1
	print(c)


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, m) = M()
	x = []
	vis = defaultdict(int)
	ans = 0
	for j in range(n):
		s = input().strip()
		l = []
		for i in s:
			l.append(i)
		x.append(l)
	for i in range(n):
		if x[i][m - 1] == 'R':
			ans += 1
	for i in range(m):
		if x[n - 1][i] == 'D':
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(r, c) = tuple(map(int, input().split()))
	count = 0
	for j in range(r):
		row = list(input())
		if j < r - 1 and row[c - 1] == 'R':
			count += 1
		if j == r - 1:
			for k in range(c):
				if row[k] == 'D':
					count += 1
	print(count)


for t in range(int(input())):
	(n, m) = list(map(int, input().split()))
	belt = []
	for i in range(n):
		belt.append(list(input()))
	result = 0
	for i in range(n - 1):
		if belt[i][m - 1] != 'D':
			result += 1
	for i in range(m - 1):
		if belt[n - 1][i] != 'R':
			result += 1
	print(result)


for _ in range(int(input())):
	(n, m) = map(int, input().split(' '))
	grid = []
	for i in range(n):
		a = input()
		grid.append(a)
	i = n - 1
	ans = 0
	for j in range(m - 1):
		if grid[i][j] == 'D':
			ans += 1
	j = m - 1
	for i in range(n - 1):
		if grid[i][j] == 'R':
			ans += 1
	print(ans)


x = int(input())
for i in range(x):
	(n, m) = [int(a) for a in input().split()]
	matrix = []
	for j in range(n):
		t = input()
		ar = list(t)
		matrix.append(ar)
	s = 0
	for j in range(n):
		for k in range(m):
			if k == m - 1 and matrix[j][k] == 'R':
				s = s + 1
			elif j == n - 1 and matrix[j][k] == 'D':
				s = s + 1
	print(s)


for u in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input())
	c = 0
	for i in range(m):
		if l[n - 1][i] == 'D':
			c = c + 1
	for i in range(n):
		if l[i][m - 1] == 'R':
			c = c + 1
	print(c)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	data = []
	for i in range(n):
		data.append(list(str(input())))
	vis = [[False] * m for k in range(n)]
	vis[n - 1][m - 1] = True
	count = 0
	for i in range(n - 1, -1, -1):
		for j in range(m - 1, -1, -1):
			if i == n - 1 and j == m - 1:
				continue
			elif data[i][j] == 'R':
				if j + 1 < m:
					if not vis[i][j + 1]:
						vis[i][j] = True
						data[i][j] = 'D'
						count += 1
					else:
						vis[i][j] = True
				else:
					vis[i][j] = True
					data[i][j] = 'D'
					count += 1
			elif i + 1 < n:
				if not vis[i + 1][j]:
					vis[i][j] = True
					data[i][j] = 'R'
					count += 1
				else:
					vis[i][j] = True
			else:
				vis[i][j] = True
				data[i][j] = 'R'
				count += 1
	print(count)


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	(n, m) = input_split()
	grid = []
	for _ in range(n):
		grid.append(input())
	counter = 0
	for i in range(m - 1):
		if grid[n - 1][i] != 'R':
			counter += 1
	for i in range(n - 1):
		if grid[i][m - 1] != 'D':
			counter += 1
	ans = counter
	answers.append(ans)
print(*answers, sep='\n')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = [list(input()) for _ in range(n)]
	c = 0
	for i in range(n):
		if li[i][m - 1] == 'R' and i != n - 1:
			c += 1
		if i == n - 1:
			for j in range(m):
				if li[i][j] == 'D':
					c += 1
	print(c)


T = int(input())
for test in range(T):
	(n, m) = map(int, input().split())
	counter = 0
	for row in range(n):
		belt = input()
		if row != n - 1:
			if belt[m - 1] == 'R':
				counter += 1
		else:
			for column in range(m - 1):
				if belt[column] == 'D':
					counter += 1
	print(counter)


n = int(input())
for i in range(n):
	x = [int(i) for i in input().split()]
	e = []
	for i in range(x[0]):
		k = input()
		e.append(k)
	sum_ = 0
	sum_ += e[-1].count('D')
	for j in e:
		if j[-1] == 'R':
			sum_ += 1
	print(sum_)


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	(res, lt) = ([], [])
	c = 0
	for i in range(n):
		x = input()
		l = []
		l[:] = x
		res.append(x)
		lt.append(x[-1])
	c = lt.count('R') + res[-1].count('D')
	print(c)


T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	Grid = [list(input()) for i in range(N)]
	ans = 0
	for j in range(M):
		if Grid[N - 1][j] == 'D':
			ans += 1
	for i in range(N):
		if Grid[i][M - 1] == 'R':
			ans += 1
	print(ans)


for x in range(int(input())):
	(n, m) = map(int, input().split())
	ls = [list(input()) for i in range(n)]
	count = 0
	for i in range(n - 2, -1, -1):
		if ls[i][m - 1] == 'R':
			count += 1
	for i in range(m - 2, -1, -1):
		if ls[n - 1][i] == 'D':
			count += 1
	print(count)