#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, m, n;
  cin >> t;
  while (t--) {
    int changes = 0;
    cin >> m >> n;
    vector<vector<char> > paths;
    for (int i = 0; i < m; i++) {
      char temp;
      vector<char> row;
      for (int j = 0; j < n; j++) {
        cin >> temp;
        row.push_back(temp);
      }
      paths.push_back(row);
    }
    for (int j = 0; j < n; j++) {
      if (paths[m - 1][j] == 'D') changes++;
    }
    for (int i = 0; i < m; i++) {
      if (paths[i][n - 1] == 'R') changes++;
    }
    cout << changes << "\n";
  }
  return 0;
}
