#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
const int N = 1e6 + 5;
const int M = 1e4;
const long long Mod = 998244353;
namespace FASTIO {
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
void print(int x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
}  // namespace FASTIO
using namespace FASTIO;
void FRE() {}
char s[105][105];
int main() {
  int ca;
  ca = read();
  while (ca--) {
    int n, m;
    n = read(), m = read();
    for (int i = 0; i < n; ++i) scanf("%s", s[i]);
    int cnt = 0;
    for (int i = 0; i < n; ++i)
      if (s[i][m - 1] == 'R') cnt++;
    for (int i = 0; i < m; ++i)
      if (s[n - 1][i] == 'D') cnt++;
    printf("%d\n", cnt);
  }
  return 0;
}
