#include <bits/stdc++.h>
using namespace std;
void systemIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  char arr[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      if (arr[i][j] == 'C') break;
      if (i == n - 1 && arr[i][j] != 'R')
        ans++;
      else if (j == m - 1 && arr[i][j] != 'D')
        ans++;
    }
  }
  cout << ans << endl;
}
int main() {
  systemIO();
  int test;
  cin >> test;
  while (test--) solve();
  return 0;
}
