#include <stdio.h>

int compare(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}

int next(void) {
	int i;
	char ch;
	int ret;

	ch = getchar();
	ungetc(ch, stdin);

	if (ch == '[') {
		int ary[10000], cnt;

		cnt = 0;
		while(getchar() == '[')
			ary[cnt++] = next();

		qsort(ary, cnt, sizeof(int), &compare);

		ret = 0;
		for (i = 0; i < cnt + 1 >> 1; i++)
			ret += ary[i];
	} else {
		scanf("%d]", &ret);
		ret = ret + 1 >> 1;
	}

	return ret;
}

int main(void) {
	int n;

	scanf("%d ", &n);

	while (n--) {
		getchar();
		printf("%d\n", next());
		getchar();
	}

	return 0;
}