#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100;
int dp[1 + N][1 + N];
string grid[1 + N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int ans = 0;
    for (int i = 1; i <= n; i++) cin >> grid[i], grid[i] = " " + grid[i];
    for (int i = 1; i < n; i++) ans += grid[i][m] == 'R';
    for (int j = 1; j < m; j++) ans += grid[n][j] == 'D';
    cout << ans << "\n";
  }
  return 0;
}
