#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

int INF = INT_MAX / 100;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int f(string s, int& i) {
	char c = s[i++];
	if (('0' <= c && c <= '9') || (c == 'Z')) {
		int x = c - '0';
		if (c == 'Z') x = 0;
		if (('0' <= s[i] && s[i] <= '9') || (s[i] == 'Z')) {
			if (s[i] != 'Z') x = x * 10 + (s[i] - '0');
			i++;
		}
		return x;
	}
	else {
		i++;
		int x = f(s, i);
		i++;
		int y = f(s, i);
		i++;
		if (c == '_') return min(x, y);
		if (c == '^') return max(x, y);
		return min(x, y);
	}
}

void solve() {
	string s; cin >> s;
	int N = s.length();
	int lb = -1, ub = N;
	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		int mi, ma;
		{
			string t = s;
			for (int i = mid; i < N; i++) {
				char& c = t[i];
				if (c == '^') c = '_';
				if ('0' <= c && c <= '9') c = 'Z';
			}
			int i = 0;
			mi = f(t, i);
		}
		{
			string t = "###";
			int unko = 0;
			rep(i, N) {
				char c = s[i];
				if (i < mid) t.pb(c);
				else {
					if ('0' <= c && c <= '9') t.pb('9');
					else {
						char c1 = t.back(), c2 = t[t.length() - 2];
						if (('1' <= c1 && c1 <= '9') && !('0' <= c2 && c2 <= '9'))
							t.pb('9'), i--;
						else if (c == '_') t.pb('^');
						else t.pb(c);
					}
				}
			}
			t.erase(t.begin(), t.begin() + 3);
			int i = 0;
			ma = f(t, i);
		}
		if (mi == ma) ub = mid;
		else lb = mid;
	}
	int i = 0;
	cout << f(s, i) << ' ' << ub << endl;
}

int main() {
	int T; cin >> T;
	while (T--) solve();
}
