
#include<stdio.h>
#include<ctype.h>

void sort(int *array, int size);
int parse();
int term();
int number();

char expression[10000+1];
int index;

void sort(int *array, int size) {
    int i, j;
    for(i = 0; i < size; i++) {
        for(j = 0; j < size - i - 1; j++) {
            if(array[j] < array[j + 1]) continue;
            array[j] ^= array[j + 1];
            array[j + 1] ^= array[j];
            array[j] ^= array[j + 1];
        }
    }
    return;
}

int parse() {
    int res = 0;
    int number[10000];
    int size = 0;
    int i;
    while(expression[index] == '[') {
        index++;
        number[size++] = term();
        index++;
    }
    sort(number, size);
    for(i = 0; i <= size / 2; i++) {
        res += number[i];
    }
    return res;
}

int term() {
    int res = 0;
    if(isdigit(expression[index])) {
        res = number();
    } else {
        res = parse();
    }
    return res;
}

int number() {
    int res = 0;
    while(isdigit(expression[index])) {
        res *= 10;
        res += expression[index] - '0';
        index++;
    }
    return (res + 1) / 2;
}

int main(void) {
    int n;
    scanf("%d\n", &n);
    while(n-- > 0) {
        gets(expression);
        index = 0;
        printf("%d\n", parse());
    }
    return 0;
}