#include <bits/stdc++.h>
using namespace std;
string s[105];
void Solve() {
  int n, m;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (i < n - 1) {
      if (s[i][m - 1] != 'D') {
        ans++;
      }
    } else {
      for (int j = 0; j < m - 1; ++j) {
        if (s[i][j] != 'R') {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    Solve();
  }
  return 0;
}
