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