#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
const int maxn = (int)2e9;
const int mod = (int)1e9 + 7;
const long long inf = 1ll * 2e18;
int n, m;
char a[111][111];
int b[111][111];
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      b[i][j] = 0;
    }
  }
  b[n][m] = 1;
  int ans = 0;
  for (int i = n; i >= 1; --i) {
    for (int j = m; j >= 1; --j) {
      if (i == n && j == m) continue;
      if (j == m) {
        b[i][j] = 1;
        if (a[i][j] == 'R') {
          ans++;
        }
      }
      if (i == n) {
        b[i][j] = 1;
        if (a[i][j] == 'D') {
          ans++;
        }
      }
      if (i < n && j < m) {
        if (a[i][j] == 'D') {
          b[i][j] = 1;
          if (b[i + 1][j]) {
            continue;
          }
          if (b[i][j + 1]) {
            ans++;
            continue;
          }
          ans++;
          continue;
        }
        b[i][j] = 1;
        if (b[i][j + 1]) {
          continue;
        }
        if (b[i + 1][j]) {
          ans++;
          continue;
        }
        ans++;
      }
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int q = 1;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
