#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m;
  cin >> n >> m;
  char a[n][m];
  ;
  for (long long i = 0; i < n; ++i) {
    ;
    for (long long j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  int count = 0;
  ;
  for (long long i = 0; i < n; ++i) {
    ;
    for (long long j = 0; j < m; ++j) {
      if (a[i][j] == 'R') {
        if (j + 1 >= m) {
          count++;
        }
      }
      if (a[i][j] == 'D') {
        if (i + 1 >= n) {
          count++;
        }
      }
    }
  }
  cout << count;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int test;
  cin >> test;
  while (test--) {
    solve();
    cout << "\n";
  }
}
