#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % 1000000007;
    }
    b >>= 1;
    a = (a * a) % 1000000007;
  }
  return ans % 1000000007;
}
void frooty() {
  long long n, m;
  cin >> n >> m;
  char c[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> c[i][j];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    if (c[i][m - 1] == 'R') ans++;
  }
  for (long long i = 0; i < m - 1; i++) {
    if (c[n - 1][i] == 'D') ans++;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q = 1;
  cin >> q;
  for (int i = 0; i < q; i++) {
    frooty();
  }
}
