#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int n) {
  long long int result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = result * x;
    x = x * x;
    n = n / 2;
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, ans = 0;
  cin >> a;
  while (a--) {
    cin >> b >> c;
    char A[b + 1][c + 1];
    ans = 0;
    for (d = 0; d < b; d++) {
      for (e = 0; e < c; e++) {
        cin >> A[d][e];
        if (e == c - 1 && A[d][e] == 'R') {
          ans++;
        }
        if (d == b - 1 && A[d][e] == 'D') {
          ans++;
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
