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