#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4 * atan(1);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    char c[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cin >> c[i][j];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int ro = i, co = j;
        while (c[ro][co] != 'C') {
          if (c[ro][co] == 'D') {
            if (ro == n - 1) {
              c[ro][co] = 'R';
              cnt++;
            } else
              ro++;
          } else if (c[ro][co] == 'R') {
            if (co == m - 1) {
              c[ro][co] = 'D';
              cnt++;
            } else
              co++;
          }
        }
      }
    }
    cout << cnt;
    cout << "\n";
    ;
  }
  return 0;
}
