#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  while (test--) {
    int n, m;
    cin >> n >> m;
    char arr[n][m];
    int d = 0;
    int r = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> arr[i][j];
        if (arr[i][j] == 'R' && j == m - 1)
          r++;
        else if (arr[i][j] == 'D' && i == n - 1)
          d++;
      }
    }
    if (n == 1) {
      cout << d << endl;
    } else if (m == 1)
      cout << r << endl;
    else if (n == 1 && m == 1)
      cout << "1" << endl;
    else {
      cout << r + d << endl;
    }
  }
}
