Language: C++

#include<stdio.h>
#include<algorithm>
using namespace std;
char s[1111];

int top;
char oper[1111];int op1[1111],op2[1111],res[1111];
int _top;
int _op1[1111], _op2[1111], _res[1111];
void calc(){
	if(res[top] == -1)return;
	while(top > 0){
		--top;
		if(op1[top] == -1){
			op1[top] = res[top+1];
			top++;
			oper[top] = '@';
			res[top] = -1;
			break;
		}else{
			op2[top] = res[top+1];
			if(oper[top] == '^')
				res[top] = max(op1[top], op2[top]);
			else
				res[top] = min(op1[top], op2[top]);
			oper[top] = '#';
		}
	}
	if(top==0){
		oper[top] = '#';
	}
}
int calc_min(){
	_top = top;
	memcpy(_op1, op1, sizeof(int)*(_top+1));
	memcpy(_op2, op2, sizeof(int)*(_top+1));
	memcpy(_res, res, sizeof(int)*(_top+1));
	while(_top > 0){
		if(_res[_top] == -1)
			_res[_top] = 0;

		--_top;
		if(_op1[_top] == -1){
			_op1[_top] = _res[_top+1];
			_op2[_top] = 0;
		}else{
			_op2[_top] = _res[_top+1];
		}
		if(oper[_top] == '^')
			_res[_top] = max(_op1[_top], _op2[_top]);
		else
			_res[_top] = min(_op1[_top], _op2[_top]);
	}
	if(oper[0] == '@'){
		if(_res[0] == -1)
			_res[0] = 0;
	}
	return _res[0];
}

int calc_max(){
	_top = top;
	memcpy(_op1, op1, sizeof(int)*(_top+1));
	memcpy(_op2, op2, sizeof(int)*(_top+1));
	memcpy(_res, res, sizeof(int)*(_top+1));
	while(_top > 0){
		if(_res[_top] == -1)
			_res[_top] = 99;
		else
		if(oper[_top] == '@' && _res[_top] >= 1 && _res[_top] <= 9)
			_res[_top] = _res[_top] * 10 + 9;

		--_top;
		if(_op1[_top] == -1){
			_op1[_top] = _res[_top+1];
			_op2[_top] = 99;
		}else{
			_op2[_top] = _res[_top+1];
		}
		if(oper[_top] == '^')
			_res[_top] = max(_op1[_top], _op2[_top]);
		else
			_res[_top] = min(_op1[_top], _op2[_top]);
	}
	if(oper[0] == '@'){
		if(_res[_top] == -1)
			_res[_top] = 99;
		else
		if(_res[_top] >= 1 && _res[_top] <= 9)
			_res[_top] = _res[_top] * 10 + 9;
	}
	return _res[0];
}

void process(){
	top = 0;
	res[0] = -1;
	oper[0] = '@';
	for(int it = 0; s[it]; ){
		if(s[it] == '^' || s[it] == '_'){
			oper[top] = s[it];
			op1[top] = -1;
			op2[top] = -1;
			top++;
			res[top] = -1;
			oper[top] = '@';
			it+=2;
		}else{
			if(s[it] >= '0' && s[it] <= '9'){
				if(res[top] == -1){
					res[top] = s[it] - '0';
					if(res[top] == 0)
						calc();
				}
				else{
					res[top] = res[top] * 10 + (s[it] - '0');
					calc();
				}
			}else
				calc();
			int S = calc_min();
			int E = calc_max();
			if(S==E){
				printf("%d %d\n",S, it+1);
				return;
			}
			it++;
		}
	}
}
int main(){
	int _;
	for(scanf("%d",&_); _--;){
		scanf("%s",s);
		process();
	}
	return 0;
}

Compiler output:
a.cc: In function 'int calc_min()':
a.cc:35:9: error: 'memcpy' was not declared in this scope
   35 |         memcpy(_op1, op1, sizeof(int)*(_top+1));
      |         ^~~~~~
a.cc:3:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<algorithm>
  +++ |+#include <cstring>
    3 | using namespace std;
a.cc: In function 'int calc_max()':
a.cc:63:9: error: 'memcpy' was not declared in this scope
   63 |         memcpy(_op1, op1, sizeof(int)*(_top+1));
      |         ^~~~~~
a.cc:63:9: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'