#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

string s;
int n;

pair<vector<int>,vector<int> > calc(int p){
    vector<int> low;
    vector<int> high;
    if(isdigit(s[p])){
        int a = s[p]-'0';
        low.push_back(a);
        if(a!=0){
            high.push_back(a*10+9);
        }else{
            high.push_back(0);
        }
        if(isdigit(s[p+1])){
            int b = s[p+1]-'0';
            low.push_back(a*10+b);
            high.push_back(a*10+b);
            low.push_back(a*10+b);
            high.push_back(a*10+b);
        }else{
            low.push_back(a);
            high.push_back(a);
        }
    }else{
        auto fir = calc(p+2);
        int dep = 0;
        int sind=-1;
        for(int i=p+2;i<n;i++){
            if(s[i]==','&&dep==0){
                sind = i+1; 
                break;
            }
            if(s[i]=='('){
                dep++;
            }
            if(s[i]==')'){
                dep--;
            }
        }
        auto sec = calc(sind);
        if(s[p]=='_'){
            low.push_back(0);
            high.push_back(99);
            low.push_back(0);
            high.push_back(99);
            int m = 1;
            auto flow = fir.first;
            auto fhigh = fir.second; 
            for(int i=0;i<flow.size();i++){
                int r = min(high[m],fhigh[i]);
                high.push_back(r);
                m++;
                low.push_back(low[m-1]);
            }
            auto slow = sec.first;
            auto shigh = sec.second;
            for(int i=0;i<slow.size();i++){
                if(high[m]<=slow[i]){
                    high.push_back(high[m]);
                    low.push_back(high[m]);
                }else{
                    low.push_back(slow[i]);
                    high.push_back(min(high[m],shigh[i]));
                }
                m++;
            }
            low.push_back(high[m]);
            high.push_back(high[m]);
        }else{
            low.push_back(0);
            high.push_back(99);
            low.push_back(0);
            high.push_back(99);
            int m = 1;
            auto flow = fir.first;
            auto fhigh = fir.second; 
            for(int i=0;i<flow.size();i++){
                int r = max(low[m],flow[i]);
                low.push_back(r);
                m++;
                high.push_back(high[m-1]);
            }
            auto slow = sec.first;
            auto shigh = sec.second;
            for(int i=0;i<slow.size();i++){
                if(low[m]>=shigh[i]){
                    low.push_back(low[m]);
                    high.push_back(low[m]);
                }else{
                    high.push_back(shigh[i]);
                    low.push_back(max(low[m],slow[i]));
                }
                m++;
            }
            low.push_back(low[m]);
            high.push_back(low[m]);


        }
    }
    return MP(low,high);
}

int main(){
    int q;
    cin >> q;
    
    rep(tt,q){
        cin >> s;
        n = s.size();
        auto ans = calc(0);
        vector<int> low = ans.first;
        vector<int> high = ans.second;
        for(int i=0;i<n;i++){
            if(low[i]==high[i]){
                cout << low[i] << " " << i+1 << endl;
                break;
            }
        }
    }
    return 0;
}