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