#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<vector<char> > a(n, vector<char>(m, 0));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i][m - 1] == 'R') ans++;
  }
  for (long long j = 0; j < m; j++) {
    if (a[n - 1][j] == 'D') ans++;
  }
  cout << ans << endl;
}
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    solve();
  }
}
