#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 5;
char str[maxn][maxn];
int main() {
  int T;
  for (cin >> T; T; --T) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
      cin >> str[i];
    }
    int ans = 0;
    for (int i = 0; i < m; ++i) {
      if (str[n - 1][i] == 'D') ++ans;
    }
    for (int i = 0; i < n; ++i) {
      if (str[i][m - 1] == 'R') ++ans;
    }
    cout << ans << endl;
  }
  return 0;
}
