#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    int m;
    cin >> n >> m;
    int count = 0;
    for (int j = 0; j < n - 1; j++) {
      string s;
      cin >> s;
      if (s[m - 1] == 'R') {
        count++;
      }
    }
    string s;
    cin >> s;
    for (int i = 0; i < m - 1; i++) {
      if (s[i] != 'R') {
        count++;
      }
    }
    cout << count << "\n";
  }
}
