#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int n, m, t, vis[maxn][maxn], cnt;
char a[maxn][maxn];
void dfs(int x, int y) {
  if (x == n && y == m) return;
  vis[x][y] = 1;
  if (a[x][y] == 'D') {
    if (x + 1 > n) {
      cnt++;
      a[x][y] = 'R';
      dfs(x, y + 1);
    } else
      dfs(x + 1, y);
  }
  if (a[x][y] == 'R') {
    if (y + 1 > m) {
      cnt++;
      a[x][y] = 'D';
      dfs(x + 1, y);
    } else
      dfs(x, y + 1);
  }
}
int main() {
  cin >> t;
  while (t--) {
    cnt = 0;
    cin >> n >> m;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) cin >> a[i][j];
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (!vis[i][j]) dfs(i, j);
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
