#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, CR = 0, CD = 0;
    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];
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (i == n - 1) {
          if (a[i][j] == 'D') CD++;
        }
        if (j == m - 1) {
          if (a[i][j] == 'R') CR++;
        }
      }
    }
    cout << CD + CR << endl;
  }
}
