#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    char arr[100 + 1][100 + 1];
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> arr[i][j];
      }
    }
    int chg = 0;
    for (int i = 1; i <= m - 1; i++) {
      if (arr[n][i] == 'D') {
        chg++;
      }
    }
    for (int i = 1; i <= n - 1; i++) {
      if (arr[i][m] == 'R') {
        chg++;
      }
    }
    cout << chg << "\n";
  }
  return 0;
}
