#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int fx[] = {+1, -1, +0, +0};
const int fy[] = {+0, +0, +1, -1};
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
const long long N = 110, M = 1e5 + 10;
char box[N][N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    for (long long i = 0; i < n; i++) {
      string s;
      cin >> s;
      for (long long j = 0; j < m; j++) {
        box[i][j] = s[j];
      }
    }
    long long cnt = 0;
    for (long long i = 0; i < m; i++) {
      if (box[n - 1][i] == 'D') cnt++;
    }
    for (long long i = 0; i < n; i++) {
      if (box[i][m - 1] == 'R') cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
