#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
bool smin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool smax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
void test_case() {
  int n, m;
  cin >> n >> m;
  vector<string> grid(n);
  for (int i = 0; i < n; i++) cin >> grid[i];
  int ans = 0;
  for (int i = 0; i < n - 1; i++) ans += (grid[i][m - 1] != 'D');
  for (int i = 0; i < m - 1; i++) ans += (grid[n - 1][i] != 'R');
  cout << ans << '\n';
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) test_case();
  return 0;
}
