#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

typedef pair<int, int> cand;

cand maximize(cand c1, cand c2)
{
	return make_pair(max(c1.first, c2.first), max(c1.second, c2.second));
}
cand minimize(cand c1, cand c2)
{
	return make_pair(min(c1.first, c2.first), min(c1.second, c2.second));
}

int Q;
char in_[1010];
int p;
string in;

char val(int p)
{
	if (p >= in.size()) return 'w';
	return in[p];
}
cand parse()
{
	if (val(p) == '^' || val(p) == '_') {
		bool ismax = (val(p) == '^');
		++p;
		++p;
		cand a = parse();
		++p;
		cand b = parse();
		++p;
		return (ismax ? maximize(a, b) : minimize(a, b));
	}
	if (val(p) >= '0' && val(p) <= '9') {
		++p;
		if (val(p - 1) == '0') {
			return{ 0, 0 };
		}
		if (val(p) >= '0' && val(p) <= '9') {
			++p;
			int a = (val(p - 2) - '0') * 10 + (val(p - 1) - '0');
			return{ a, a };
		}
		if (val(p) == 'w') {
			++p;
			int a = (val(p - 2) - '0');
			return{ a, 10 * a + 9 };
		}
		int a = (val(p - 1) - '0');
		return{ a, a };
	}
	return{ 0, 99 };
}

bool check(int L)
{
	in.clear();
	for (int i = 0; i < L; ++i) in.push_back(in_[i]);
	p = 0;
	cand a = parse();
	return a.first == a.second;
}

int main()
{
	scanf("%d", &Q);
	for (; Q--;) {
		scanf("%s", in_);
		int L = strlen(in_);
		int left = 0, right = L;
		while (left < right) {
			int mid = (left + right) / 2;
			if (check(mid)) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		in = in_;
		p = 0;
		cand a = parse();
		printf("%d %d\n", a.first, left);
	}
	return 0;
}
