Language: C++

#include <iostream>

bool is_complete(int*);

int solve(int *, int);
void rot(int*, int);

int min(int, int, int, int);
void swap(int&, int&);

int main(){
	int N;
	int **p;
	std::cin >> N;
	p = new int*[N];
	for(int i=0; i<N; i++){
		p[i] = new int[30];
		for(int j=0; j<30; j++)
			std::cin >> p[i][j];
	}
	for(int i=0; i<N; i++)
		std::cout << solve(p[i]) << std::endl;
}

bool is_complete(int* p){
	int cmp=p[0];
	for(int i=0; i<30; i++){
		if(i == 9)
			cmp = p[9];
		else if(i == 12)
			cmp = p[12];
		else if(i == 15)
			cmp = p[15];
		else if(i == 18)
			cmp = p[18];
		else if(i == 21)
			cmp = p[21];
		else if(cmp != p[i])
			return false;
	}
	return true;
}

int solve(int *p, int cnt){
	if(cnt == 9 || is_complete(p))
		return cnt;
	int **pp = new int*[4];
	for(int i=0; i<4; i++){
		pp[i] = new int[30];
		for(int j=0; j<30; j++)
			pp[i][j] = p[j];
	}
	delete[] p;
	for(int dir=1; dir<=4; dir++){
		rot(pp[dir-1], dir);
		if(is_complete(pp))
			return cnt;
	}
	return min(sovle(pp[0]), solve(pp[1]), solve(pp[2]), solve(pp[3]));
}

void rot(int* p, int dir){
	if(dir == 1){
		swap(p[6], p[21]);
		swap(p[7], p[22]);
		swap(p[8], p[23]);
		swap(p[9], p[11]);
		swap(p[12], p[17]);
	}else if(dir == 2){
		swap(p[0], p[27]);
		swap(p[1], p[28]);
		swap(p[2], p[29]);
		swap(p[18], p[20]);
		swap(p[14], p[15]);
	}else if(dir == 3){
		swap(p[0], p[23]);
		swap(p[3], p[26]);
		swap(p[6], p[29]);
		swap(p[15], p[17]);
		swap(p[9], p[20]);
	}else{
		swap(p[2], p[21]);
		swap(p[5], p[24]);
		swap(p[8], p[27]);
		swap(p[12], p[14]);
		swap(p[11], p[18]);
	}
}

int min(int a, int b, int c, int d){
	int ans = a;
	if(ans > b)
		ans = b;
	if(ans > c)
		ans = c;
	if(ans > d)
		ans = d;
	return ans;
}

void swap(int& a, int& b){
	int tmp = a;
	a = b;
	b = tmp;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:35: error: too few arguments to function 'int solve(int*, int)'
   22 |                 std::cout << solve(p[i]) << std::endl;
      |                              ~~~~~^~~~~~
a.cc:5:5: note: declared here
    5 | int solve(int *, int);
      |     ^~~~~
a.cc: In function 'int solve(int*, int)':
a.cc:56:32: error: cannot convert 'int**' to 'int*'
   56 |                 if(is_complete(pp))
      |                                ^~
      |                                |
      |                                int**
a.cc:25:23: note:   initializing argument 1 of 'bool is_complete(int*)'
   25 | bool is_complete(int* p){
      |                  ~~~~~^
a.cc:59:20: error: 'sovle' was not declared in this scope; did you mean 'solve'?
   59 |         return min(sovle(pp[0]), solve(pp[1]), solve(pp[2]), solve(pp[3]));
      |                    ^~~~~
      |                    solve
a.cc:59:39: error: too few arguments to function 'int solve(int*, int)'
   59 |         return min(sovle(pp[0]), solve(pp[1]), solve(pp[2]), solve(pp[3]));
      |                                  ~~~~~^~~~~~~
a.cc:44:5: note: declared here
   44 | int solve(int *p, int cnt){
      |     ^~~~~
a.cc:59:53: error: too few arguments to function 'int solve(int*, int)'
   59 |         return min(sovle(pp[0]), solve(pp[1]), solve(pp[2]), solve(pp[3]));
      |                                                ~~~~~^~~~~~~
a.cc:44:5: note: declared here
   44 | int solve(int *p, int cnt){
      |     ^~~~~
a.cc:59:67: error: too few arguments to function 'int solve(int*, int)'
   59 |         return min(sovle(pp[0]), solve(pp[1]), solve(pp[2]), solve(pp[3]));
      |                                                              ~~~~~^~~~~~~
a.cc:44:5: note: declared here
   44 | int solve(int *p, int cnt){
      |     ^~~~~