#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1e9 + 7;
const ll MAXN = 1e7 + 10;
int spf[MAXN];
void solve() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<string> vs(n);
  for (int i = 0; i < n; i++) {
    cin >> vs[i];
  }
  if (n == 1) {
    ans = count(vs[0].begin(), vs[0].end(), 'D');
    cout << ans << "\n";
    return;
  }
  int flagr = 0, flagd = 0, f1 = 0, f2 = 0;
  for (int i = 0; i < n; i++) {
    if (vs[i][m - 1] == 'R') {
      flagr++;
    }
  }
  for (int i = 0; i < m; i++) {
    if (vs[n - 1][i] == 'D') {
      flagd++;
    }
  }
  int ok = flagd + flagr;
  cout << ok << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
