#include <bits/stdc++.h>
 
#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl "\n"
const int MAX = 3e5+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

int q;
string s;

int nx(int id){
	int cnt = 0;
	while(1){
		if(s[id]==','&&!cnt)break;
		if(s[id]=='(')++cnt;
		else if(s[id]==')')--cnt;
		++id;
	}
	return id+1;
}

//a = batasan untuk operasi max, b = batasan untuk operasi min

pii det(int id,int a,int b);

pii mx(int id,int a,int b){
	pii res = det(id,a,b);
	int fis,sec;
	if(res.fi==-1){
		if(b<=9){if(s[id]-'0'>=b)return {b,id};}
		if(s[id+1]>='0'&&s[id+1]<='9')fis = (s[id]-'0')*10+s[id+1]-'0';
		else fis = s[id]-'0';
		res = {fis,id+1};
	}
	else fis = res.fi;
	if(fis>=b)return res;
	a = max(a,fis);
	id = nx(id);
	res = det(id,a,b);
	if(res.fi==-1){
		if(a>=19){
			if(a%10==9){if(s[id]-'0'<=a/10)return {a,id};}
			else if(s[id]-'0'<a/10)return {a,id};
		}
		if(b<=9){if(s[id]-'0'>=b)return {b,id};}
		if(s[id+1]>='0'&&s[id+1]<='9')sec = (s[id]-'0')*10+s[id+1]-'0';
		else sec = s[id]-'0';
		res.se = id+1;
	}
	else sec = res.fi;
	return {max(fis,sec),res.se};
}

pii mn(int id,int a,int b){
	pii res = det(id,a,b);
	int fis,sec;
	if(res.fi==-1){
		if(a>=19){
			if(a%10==9){if(s[id]-'0'<=a/10)return {a,id};}
			else if(s[id]-'0'<a/10)return {a,id};
		}
		if(s[id+1]>='0'&&s[id+1]<='9')fis = (s[id]-'0')*10+s[id+1]-'0';
		else fis = s[id]-'0';
		res = {fis,id+1};
	}
	else fis = res.fi;
	if(fis<=a)return res;
	b = min(b,fis);
	id = nx(id);
	res = det(id,a,b);
	if(res.fi==-1){
		if(a>=19){
			if(a%10==9){if(s[id]-'0'<=a/10)return {a,id};}
			else if(s[id]-'0'<a/10)return {a,id};
		}
		if(b<=9){if(s[id]-'0'>=b)return {b,id};}
		if(s[id+1]>='0'&&s[id+1]<='9')sec = (s[id]-'0')*10+s[id+1]-'0';
		else sec = s[id]-'0';
		res.se = id+1;
	}
	else sec = res.fi;
	return {min(fis,sec),res.se};
}

pii det(int id,int a,int b){
	if(s[id]=='^')return mx(id+2,a,b);
	if(s[id]=='_')return mn(id+2,a,b);
	if(s[id]=='0')return {0,id};
	return {-1,-1};
}
 
int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>q;
    pii res;
    while(q--){
    	cin>>s;
    	res = det(0,0,99);
    	if(res.fi==-1){
			if(s[1]>='0'&&s[1]<='9')res.fi = (s[0]-'0')*10+s[1]-'0';
			else res.fi = s[0]-'0';
			res.se = 1;
		}
		cout<<res.fi<<' '<<res.se+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256