#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
const double PI = acos(-1);
const long long MOD = 1000000007;
long long dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
long long dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
long long powmod(long long a, long long b) {
  long long p = MOD;
  a %= p;
  if (!a) return 0;
  long long pr = 1;
  while (b > 0) {
    if (b & 1) {
      pr *= a;
      pr %= p;
      --b;
    }
    a *= a;
    a %= p;
    b /= 2;
  }
  return pr;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 or n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i += 6) {
    if (n % i == 0 or n % (i + 2) == 0) return false;
  }
  return true;
}
void seive(bool a[]) {
  long long mx = sqrt(N), ii, jj;
  for (ii = 3; ii <= mx; ii += 2)
    if (!a[ii])
      for (jj = ii * ii; jj <= N; jj += 2 * ii) a[jj] = true;
}
void numofdiv(long long a[]) {
  long long mx = sqrt(N), ii, jj;
  for (ii = 1; ii <= mx; ii++) {
    for (jj = ii * ii; jj <= N; jj += ii) {
      if (jj == ii * ii)
        a[jj]++;
      else
        a[jj] += 2;
    }
  }
}
void sumofdiv(long long a[]) {
  long long mx = sqrt(N), ii, jj;
  for (ii = 1; ii <= mx; ii++) {
    for (jj = ii * ii; jj <= N; jj += ii) {
      if (jj == ii * ii)
        a[jj] += ii;
      else
        a[jj] += ii + jj / ii;
    }
  }
}
void _case() {
  long long n, m, i, ans = 0;
  cin >> n >> m;
  string a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++)
    if (a[i][m - 1] == 'R') ans++;
  for (i = 0; i < m; i++)
    if (a[n - 1][i] == 'D') ans++;
  cout << ans << '\n';
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) _case();
}
