#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<string> mat(n);
    for (int i = 0; i < (n); ++i) cin >> mat[i];
    int ans = 0;
    for (int i = 0; i < (n - 1); ++i) ans += mat[i][m - 1] == 'R';
    for (int j = 0; j < (m - 1); ++j) ans += mat[n - 1][j] == 'D';
    cout << ans << '\n';
  }
  return 0;
}
