Gorillas in Kyoto University are good at math. They are currently trying to solve problems to find the value of an expression that contains two functions, `_` , `^`. Each of these functions takes two input values. `_` function returns the smaller of the two input values and `^` function returns the larger. Gorillas know that integers in the expression are non-negative and less than or equal to 99, but can not find out the length of the expression until they read a terminal symbol `?` that represents the end of the expression. The number of characters included in each expression is less than or equal to 1000, but they do not even know this fact. Ai, a smart gorilla, noticed that she may be able to know the value of the expression even if they don't read the whole expression.

For example,

Assume you read the following sentence from the left.


^(41,3)?

When you read the sixth character, that is, when you read the following expression,


^(41,3

you can tell the second input value of the funcion is whether 3 or an integer between 30 and 39, and the value turns out 41.

Since Ai wants to solve problems earlier than other gorillas, she decided to solve the problems such that she reads as fewer characters as possible from the left. For each expression, Find the value of the expression and the minimum number of characters Ai needs to read to know the value.

Constraints

* 1 \leq Q \leq 200
* The number of characters each expression contains is less than or equal to 1000.

Input

The input consists of multiple test cases and is given from Standard Input in the following format:


Q
statement_1
...
statement_Q

Input

The input consists of multiple test cases and is given from Standard Input in the following format:


Q
statement_1
...
statement_Q

Output

Output consists of Q lines. On line i (1 \leq i \leq Q), print the value of the expression and the number of character Ai needs to read for the test case i separated by space.

Examples

Input

4
_(4,51)?
^(99,_(3,67))?
_(0,87)?
3?


Output

4 5
99 4
0 3
3 2


Input

7
_(23,^(_(22,40),4))?
_(0,99)?
^(99,_(^(19,2),5))?
_(^(43,20),^(30,29))?
^(_(20,3),_(50,41))?
^(_(20,3),_(3,41))?
^(_(20,3),_(4,41))?


Output

22 18
0 3
99 4
30 17
41 17
3 14
4 15
#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;
}