#include <bits/stdc++.h>
using namespace std;
void solve() {
  int x, y;
  cin >> x >> y;
  char c;
  int ans = 0;
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      cin >> c;
      if (i == x - 1 and c == 'D') ans++;
      if (j == y - 1 and c == 'R') ans++;
    }
  }
  cout << ans << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
