// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
const int N = (int) 1e5 + 5, mod = (int) 0;
int op[N], t, hi[N], f[N], lo[N], flo[N][2], fhi[N][2];
void update() {

    for (int i = t - 1; i >= 0; --i) {
        if (op[i]) {
            lo[i] = max(flo[i][0], flo[i][1]);
            hi[i] = max(fhi[i][0], fhi[i][1]);
        } else {
            lo[i] = min(flo[i][0], flo[i][1]);
            hi[i] = min(fhi[i][0], fhi[i][1]);
        }
        if (i) flo[i - 1][f[i - 1]] = lo[i];
        if (i) fhi[i - 1][f[i - 1]] = hi[i];
    }
}
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int q;
    cin >> q;
    while (q--) { t = 0;
        string x;
        cin >> x;
        int n = (int) x.size();
        if (x[0] == '0') {
            cout << 0 << ' ' << 1 << endl;
            continue;
        }
        if (n == 3) {
            cout << (x[0] - '0') * 10 + (x[1] - '0') << ' ' << 2 << '\n';
            continue;
        }
        if (n == 2) {
            cout << (x[0] - '0') << ' ' << 2 << endl;
            continue;
        }
        for (int i = 0; i < n - 1; ++i) {
//            cout << endl << i << " I IS STARTING " << endl << x << endl << endl;
            if (x[i] == '(') {
                f[t] = 0;
                op[t] = (x[i - 1] != '_');
                lo[t] = 0;
                hi[t] = 99;
                for (int i = 0; i < 2; ++i)
                    flo[t][i] = 0, fhi[t][i] = 99;
                t++;
                update();
            }
            if (x[i] == ')') {
                if ((x[i - 2] < '0' || x[i - 2] > '9') && (x[i - 1] >= '0' && x[i - 1] <= '9')) {
                    flo[t - 1][f[t - 1]] = x[i - 1] - '0';
                    fhi[t - 1][f[t - 1]] = x[i - 1] - '0';
                }
                update();
                t--;
            }
            if (x[i] == ',') {
                if ((x[i - 2] < '0' || x[i - 2] > '9') && (x[i - 1] >= '0' && x[i - 1] <= '9')) {
                    flo[t - 1][f[t - 1]] = x[i - 1] - '0';
                    fhi[t - 1][f[t - 1]] = x[i - 1] - '0';
                }
                update();
                f[t - 1] = 1;
            }
            if (x[i] >= '0' && x[i] <= '9') {
                int num = x[i] - '0';
                if ((x[i - 1] >= '0' && x[i - 1] <= '9') || x[i] == '0') {
                    if (x[i - 1] >= '0' && x[i - 1] <= '9') num += 10 * (x[i - 1] - '0');
                    flo[t - 1][f[t - 1]] = num;
                    fhi[t - 1][f[t - 1]] = num;
                } else {
                    flo[t - 1][f[t - 1]] = num;
                    fhi[t - 1][f[t - 1]] = num * 10 + 9;
                }
                update();
            }
            if ((t > 0 || i > 2) && hi[0] == lo[0]) {
                cout << lo[0] << ' ' << i + 1 << endl;
                break;
            }
      //      for (int j = 0; j < t; ++j) {
        //        cout << j << ' ' << f[j] << ' ' << flo[j][0] << ' ' << fhi[j][0] << ' ' << flo[j][1] << ' ' << fhi[j][1] << ' ' << lo[j] << ' ' << hi[j] << endl;
          //  }
            //cout << endl << endl << endl << " I IS ENDING " << endl;
        }
    }


}


Measured memory_bytes: 256