#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long m, n;
    cin >> m >> n;
    char a[m][n];
    for (long long i = 0; i < m; i++) {
      for (long long j = 0; j < n; j++) cin >> a[i][j];
    }
    long long ans = 0;
    for (long long i = 0; i < n - 1; i++) {
      if (a[m - 1][i] != 'R') ans++;
    }
    for (long long i = 0; i < m - 1; i++) {
      if (a[i][n - 1] != 'D') ans++;
    }
    cout << ans << endl;
  }
}
