#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<string> directions(n);
    int cnt = 0;
    for (int i = 0; i < n; i++) cin >> directions[i];
    for (int i = 0; i < n - 1; i++)
      if (directions[i][m - 1] != 'D') cnt++;
    for (int i = 0; i < m - 1; i++)
      if (directions[n - 1][i] != 'R') cnt++;
    cout << cnt << "\n";
  }
  return 0;
}
