#include <bits/stdc++.h>
using namespace std;
void solve() {
  int x, y, cnt = 0;
  cin >> x >> y;
  string s[x];
  for (int i = 0; i < x; ++i) cin >> s[i];
  for (int i = 0; i < x - 1; ++i)
    if (s[i][y - 1] != 'D') ++cnt;
  for (int i = 0; i < y - 1; ++i)
    if (s[x - 1][i] != 'R') ++cnt;
  cout << cnt << endl;
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
