#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<char>> v(n, vector<char>(m));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) cin >> v[i][j];
    }
    int count = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (v[i][j] == 'R') {
          if (j + 2 > m) count++;
        } else {
          if (i + 2 > n) count++;
        }
      }
    }
    cout << count - 1 << endl;
  }
  return 0;
}
