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