#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
pair<long long, long long> p;
map<long long, long long> mp;
set<long long> st;
deque<long long> dq;
priority_queue<long long> pq;
long long mn = INT_MAX, mx = INT_MIN;
long long n, m, tc, i, j, tmp, sum, cn, ans, res, pos, flag, l, x, k, dif;
string s[105], str;
long long a[2000007], b[2000007];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> tc;
  while (tc--) {
    ans = 0;
    cin >> n >> m;
    for (i = 0; i < n; i++) {
      cin >> s[i];
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (s[i][j] == 'D' && i == n - 1)
          ans++;
        else if (s[i][j] == 'R' && j == m - 1)
          ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
