#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int m, n;
    scanf("%d %d", &n, &m);
    char s[n][m];
    for (int i = 0; i < n; i++) {
      scanf("%s", s[i]);
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
      if (s[i][m - 1] == 'R') ans++;
    for (int i = 0; i < m; i++)
      if (s[n - 1][i] == 'D') ans++;
    printf("%d\n", ans);
  }
  return 0;
}
