#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <cassert>
#include <iostream>
#include <memory>
#include <unordered_map>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()


bool isdigit(char c){
	return '0' <= c and c <= '9';
}

struct V{
	int l,r;
	V(){ l = 0, r = 99; }
	V(int a,int b){ l = a, r = b; }
	bool unique(){ return l == r; }	
};

int p;
string e;

V EXPR();
V STATE();
V NUMBER();

V STATE(){
	V res = EXPR();
	return res;
}
V EXPR(){
	if ( e.size() <= p ){
		return V();
	}
	if( e[p] == '_' ){
		p++;
		p++;
		V a = EXPR();
		p++;
		V b = EXPR();
		p++;
		V res;
		//cout << "a: " << a.l << " " << a.r << endl;
		//cout << "b: " << b.l << " " << b.r << endl;
		
		res.l = min(a.l,b.l);
		res.r = min(a.r,b.r);

		return res;
	}else if( e[p] == '^'){
		p++;
		p++;
		V a = EXPR();
		p++;
		V b = EXPR();
		p++;
		V res;
		
		res.l = max(a.l,b.l);
		res.r = max(a.r,b.r);
		return res;
	}else{
		V a = NUMBER();
		//cout << a.l << " " << a.r << endl;
		return a;
	}
}

V NUMBER(){
	if( e.size() <= p ){
		return V();
	}
	string val;

	while( isdigit(e[p]) ){
		val += e[p];
		p++;
	}
	if( p == e.size() and val.size() == 1 and val[0] != '0'){
		int t = val[0] - '0';
		//cout << "><" << endl;
		return V(t,t*10+9);
	}
	assert(val.size()>0);
	if( val[0] == '0' ){
		return V(0,0);
	}else{
		if( val.size() >= 2){
			int t = (val[0]-'0') * 10 + (val[1]-'0');
			return V(t,t);
		}else{
			int t = val[0] - '0';
			return V(t,t);
		}
	}

}


V check(string s){

	e = s;
	p = 0;
	return STATE();


}

int DEBUG = 0;
void query(string s){
	if( DEBUG ){
		cout << s.substr(0,17) << endl;
		check(s.substr(0,17));
		exit(0);
	}
	if( isdigit(s[0]) ){
		assert(s.size() <= 3);

		if( s[0] == '0' ){
			cout << 0 << " " << 1 << endl;
		}else{
			cout << s.substr(0,s.size()-1) << " " << 2 << endl;
		}
		return;
	}
	int l = 0, r = s.size();

	while( l != r ){
		int m = (l+r) / 2;
		V v = check(s.substr(0,m));
		if( v.unique() ){
			r = m;
		}else{
			l = m + 1;
		}
	}
	cout << check(s.substr(0,l)).l << " " << l << endl;
}
int main(){
	int N;
	cin >> N;
	for(int i = 0 ; i < N ; i++){
		string s;
		cin >> s;
		query(s);
	}
}











Measured memory_bytes: 256