#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  char ch[n][m];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> ch[i][j];
    }
  }
  long long r = 0, d = 0;
  for (long long i = 0; i < n; i++) {
    if (ch[i][0] == 'R') {
      r++;
    }
  }
  for (long long i = 0; i < m; i++) {
    if (ch[0][i] == 'D') {
      d++;
    }
  }
  if (ch[0][m - 1] == 'C') {
    cout << d << endl;
  } else if (ch[n - 1][0] == 'C') {
    cout << r << endl;
  } else {
    long long r1 = 0, d1 = 0;
    for (long long i = 0; i < n; i++) {
      if (ch[i][m - 1] == 'R') {
        r1++;
      }
    }
    for (long long i = 0; i < m; i++) {
      if (ch[n - 1][i] == 'D') {
        d1++;
      }
    }
    cout << (r1 + d1) << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
