#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  for (cin >> t; t--;) {
    long long n, m, c = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        char ch;
        cin >> ch;
        if (i == n - 1 && ch == 'D')
          c++;
        else if (j == m - 1 && ch == 'R')
          c++;
      }
    cout << c << '\n';
  }
}
