#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 105;
const double eps = 1e-8;
int n, m;
string s[N];
int main() {
  int i, j;
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    int ans = 0;
    for (i = 1; i <= n; i++) {
      cin >> s[i];
    }
    i = n;
    for (j = 0; j < m; j++) {
      if (s[i][j] == 'D') {
        ans++;
      }
    }
    j = m - 1;
    for (i = 1; i <= n; i++) {
      if (s[i][j] == 'R') ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
