#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PB push_back #define ALL(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define REP(i, n) for(int i=0; i=0; --i) #define FOR(i, b, e) for(typeof(e) i=b; i!=e; ++i) using namespace std; typedef long long LL; typedef vector VI; typedef vector VVI; typedef vector VS; typedef istringstream ISS; map cnt; string s; int pos; int next() { if(pos==SZ(s)) { printf("Invalid input: tried to read beyond end of line\n"); exit(1); } if(s[pos]=='[') {pos++; return -2;} if(s[pos]==']') {pos++; return -3;} if(s[pos]==',') {pos++; return -4;} if(isdigit(s[pos])) { int res; int delta; sscanf(s.c_str()+pos, "%d%n", &res, &delta); pos+=delta; return res; } printf("Invalid input: don't recognize token %c\n", s[pos]); exit(1); } int parse(LL mult) { int n=next(); if(n>0) { cnt[n*mult]++; return 1; } else if(n==-2) { int res=parse(2*mult); if(next()!=-4) { printf("Invalid input: expected ','\n"); exit(1); } res+=parse(2*mult); if(next()!=-3) { printf("Invalid input: expected ']'\n"); exit(1); } return res; } else { printf("Invalid input: expected number of '[' got %d\n", n); exit(1); } } void go() { cnt.clear(); cin >> s; pos=0; int N=parse(1); int most=0; FOR(it, cnt.begin(), cnt.end()) most>?=it->second; cout << N-most << endl; } int main() { int nruns; cin >> nruns; while(nruns--) go(); return 0; }