fork(1) download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4. class Main{
  5. static final long MOD = (long)1e9+7;
  6. static FastReader in;
  7. public static void main(String[] args){
  8. in = new FastReader();
  9. int T = ni();
  10. while(T-->0){
  11. int N = ni(), M = ni();
  12. long sum1 = 0, sum2 = 0;
  13. for(int i = 0; i< N; i++){
  14. String s = n();
  15. for(int j = 0; j< M; j++){
  16. if(((i+j)&1) == 1){
  17. if(s.charAt(j) == 'R')sum1+=5;
  18. else sum2 += 3;
  19. }else{
  20. if(s.charAt(j) == 'R')sum2+=5;
  21. else sum1 += 3;
  22. }
  23. }
  24. }
  25. pn(Math.min(sum1, sum2));
  26. }
  27. }
  28.  
  29. static void p(Object o){
  30. System.out.print(o);
  31. }
  32.  
  33. static void pn(Object o){
  34. System.out.println(o);
  35. }
  36.  
  37. static String n(){
  38. return in.next();
  39. }
  40.  
  41. static String nln(){
  42. return in.nextLine();
  43. }
  44.  
  45. static int ni(){
  46. return Integer.parseInt(in.next());
  47. }
  48.  
  49. static int[] ia(int N){
  50. int[] a = new int[N];
  51. for(int i = 0; i<N; i++)a[i] = ni();
  52. return a;
  53. }
  54.  
  55. static long[] la(int N){
  56. long[] a = new long[N];
  57. for(int i = 0; i<N; i++)a[i] = nl();
  58. return a;
  59. }
  60.  
  61. static long nl(){
  62. return Long.parseLong(in.next());
  63. }
  64.  
  65. static double nd(){
  66. return Double.parseDouble(in.next());
  67. }
  68.  
  69. static class FastReader{
  70. public FastReader(){
  71. }
  72.  
  73. String next(){
  74. while (st == null || !st.hasMoreElements()){
  75. try{
  76. st = new StringTokenizer(br.readLine());
  77. }catch (IOException e){
  78. e.printStackTrace();
  79. }
  80. }
  81. return st.nextToken();
  82. }
  83.  
  84. String nextLine(){
  85. String str = "";
  86. try{
  87. str = br.readLine();
  88. }catch (IOException e){
  89. e.printStackTrace();
  90. }
  91. return str;
  92. }
  93. }
  94. }
Success #stdin #stdout 0.08s 28048KB
stdin
1
3 4
RRGG 
GRGR
RGRG
stdout
8