#include <bits/stdc++.h>
using namespace std;
char grid[101][101];
int change(int i, int j, int n, int m) {
  int res = 0;
  while (i != (n - 1) || j != (m - 1)) {
    if (grid[i][j] == 'R') {
      if (j == m - 1 && i != n - 1) {
        grid[i][j] = 'D';
        i++;
        res++;
      } else {
        j++;
      }
    } else {
      if (j != m - 1 && i == n - 1) {
        grid[i][j] = 'R';
        j++;
        res++;
      } else
        i++;
    }
  }
  return res;
}
int main() {
  int tc, n, m, i, j, ans;
  scanf("%d", &tc);
  while (tc--) {
    ans = 0;
    scanf("%d %d", &n, &m);
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        cin >> grid[i][j];
      }
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        ans += change(i, j, n, m);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
