#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, n, t, j = 0, p, x, a = 0, b, l = 0, r = 0, y, k, c, sum = 0,
                         m, d, z;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    l = 0;
    char s[n][m];
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        cin >> s[i][j];
      }
    }
    i = n - 1;
    for (j = 0; j < m; j++) {
      if (s[i][j] == 'D') {
        l++;
      }
    }
    j = m - 1;
    for (i = 0; i < n; i++) {
      if (s[i][j] == 'R') {
        l++;
      }
    }
    cout << l << endl;
  }
  return EXIT_SUCCESS;
}
