#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    char a[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
      }
    }
    int qt = 0, i2 = n - 1, j1 = m - 1;
    for (int i1 = 0; i1 <= (n - 1); i1++) {
      if (a[i1][j1] == 'R') qt++;
    }
    for (int j2 = 0; j2 <= (m - 1); j2++) {
      if (a[i2][j2] == 'D') qt++;
    }
    int i = 0, j = 0, ct = 0;
    while (a[i][j] != 'C') {
      if (a[i][j] == 'R') {
        if ((j + 1) <= (m - 1))
          j = j + 1;
        else {
          a[i][j] = 'D';
          i = i + 1;
          ct++;
        }
      } else if (a[i][j] == 'D') {
        if ((i + 1) <= (n - 1))
          i = i + 1;
        else {
          a[i][j] = 'R';
          j = j + 1;
          ct++;
        }
      }
    }
    if (ct > qt)
      cout << ct << endl;
    else
      cout << qt << endl;
  }
  return 0;
}
