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