#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t != 0) {
    int n, m;
    cin >> n >> m;
    char c;
    int i, j, cnt = 0;
    char down[m];
    char ri[n];
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        cin >> c;
        if (i == n) down[j] = c;
        if (j == m) ri[i] = c;
      }
    }
    for (i = 1; i <= m; i++) {
      if (down[i] == 'D') cnt++;
    }
    for (j = 1; j <= n; j++) {
      if (ri[j] == 'R') cnt++;
    }
    cout << cnt << endl;
    t--;
  }
  return 0;
}
