#include <bits/stdc++.h>
using namespace std;
int n, t, a, m, cou, l, r;
char c[1001][1001];
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    cou = 0;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) cin >> c[i][j];
    for (int i = 1; i <= n; ++i)
      if (c[i][m] == 'R') ++cou;
    for (int i = 1; i <= m; ++i)
      if (c[n][i] == 'D') ++cou;
    cout << cou << '\n';
  }
  return 0;
}
