#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int t, n, m, a;
  string matrix[100];
  cin >> t;
  for (int k = 0; k < t; ++k) {
    a = 0;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
      cin >> matrix[i];
      if (matrix[i][m - 1] == 'R' && i != n - 1) a++;
    }
    for (int i = 0; i < m - 1; ++i) {
      if (matrix[n - 1][i] == 'D') a++;
    }
    cout << a << endl;
  }
  return 0;
}
