#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  long long int c = 0;
  if (n == 1) {
    string s;
    cin >> s;
    for (long long int i = 0; i < m; i++) {
      if (s[i] == 'D') {
        c++;
      }
    }
    cout << c << endl;
    return;
  }
  if (m == 1) {
    for (long long int i = 0; i < n; i++) {
      string s;
      cin >> s;
      if (s[0] == 'R') {
        c++;
      }
    }
    cout << c << endl;
    return;
  }
  for (long long int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s[m - 1] == 'R') {
      c++;
    }
    if (i == n - 1) {
      for (long long int i = 0; i < m; i++) {
        if (s[i] == 'D') {
          c++;
        }
      }
    }
  }
  cout << c << endl;
  return;
}
int32_t main() {
  c_p_c();
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
