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