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