#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
int solve() {
  int n, m;
  cin >> n >> m;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (i < n - 1) {
      if (v[i][m - 1] != 'D') {
        cnt++;
      }
    } else {
      for (int j = 0; j < m - 1; j++) {
        if (v[i][j] != 'R') cnt++;
      }
    }
  }
  cout << cnt;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cerr << fixed << setprecision(10);
  auto start = chrono::high_resolution_clock::now();
  int t = 1;
  cin >> t;
  while (t--) solve(), cout << "\n";
  auto stop = chrono::high_resolution_clock::now();
  auto duration = chrono::duration_cast<chrono::nanoseconds>(stop - start);
  cerr << "Time taken : "
       << ((long double)duration.count()) / ((long double)1e9) << "s \n";
  return 0;
}
