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