Language: C++

import std.string;
import std.algorithm;
import std.math;
import std.array;
import std.format;
import std.range;
import std.stdio;
import std.conv;

struct Node
{
    size_t value;
    Node*[] childs;

    static
    Node* parse(string str)
    {
        Node* dst = new Node;
        size_t cnt;
        foreach(e; str) if(e == '[') ++cnt; else break;
        if(cnt == 1){
            dst.value = str[1 .. $-1].to!uint;
            return dst;
        }else{
            size_t s, c;
            foreach(i, e; str){
                if(c == 1) s = i;
                if(e == '[') {++c; if(c == 1) s = i;};
                if(e == ']') {--c; if(c == 1) dst.childs ~= parse(str[s .. i+1]); };
            }
        }

        return dst;
    }

    string toString()
    {
        if(childs.length == 0) return '[' ~ value.to!string ~ ']';
        else{
            auto app = appender!string();
            app.put('[');
            foreach(e; childs)
                app.put(e.toString());
            app.put(']');
            return app.data;
        }
    }

    size_t query()
    {
        if(childs.length == 0) return (value + 1)/2;
        else{
            int[] vs;
            foreach(e; childs) vs ~= e.query;
            vs.sort();
            vs = vs[0 .. ($+1)/2];
            return vs.sum;
        }
    }
}


void main()
{
    foreach(i; 0 .. readln().chomp().to!size_t){
        writeln(Node.parse(readln().chomp()).query);
    }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import std.string;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import std.algorithm;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import std.math;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import std.array;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import std.format;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import std.range;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import std.stdio;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import std.conv;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:12:5: error: 'size_t' does not name a type
   12 |     size_t value;
      |     ^~~~~~
a.cc:1:1: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
  +++ |+#include <cstddef>
    1 | import std.string;
a.cc:13:10: error: expected unqualified-id before '[' token
   13 |     Node*[] childs;
      |          ^
a.cc:16:17: error: 'string' has not been declared
   16 |     Node* parse(string str)
      |                 ^~~~~~
a.cc:36:5: error: 'string' does not name a type
   36 |     string toString()
      |     ^~~~~~
a.cc:49:5: error: 'size_t' does not name a type
   49 |     size_t query()
      |     ^~~~~~
a.cc:49:5: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
a.cc:60:2: error: expected ';' after struct definition
   60 | }
      |  ^
      |  ;
a.cc: In static member function 'static Node* Node::parse(int)':
a.cc:19:9: error: 'size_t' was not declared in this scope
   19 |         size_t cnt;
      |         ^~~~~~
a.cc:19:9: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
a.cc:20:17: error: 'e' was not declared in this scope
   20 |         foreach(e; str) if(e == '[') ++cnt; else break;
      |                 ^
a.cc:20:23: error: expected ';' before ')' token
   20 |         foreach(e; str) if(e == '[') ++cnt; else break;
      |                       ^
a.cc:20:45: error: 'else' without a previous 'if'
   20 |         foreach(e; str) if(e == '[') ++cnt; else break;
      |                                             ^~~~
a.cc:20:50: error: break statement not within loop or switch
   20 |         foreach(e; str) if(e == '[') ++cnt; else break;
      |                                                  ^~~~~
a.cc:21:12: error: 'cnt' was not declared in this scope; did you mean 'int'?
   21 |         if(cnt == 1){
      |            ^~~
      |            int
a.cc:22:17: error: request for member 'value' in 'dst', which is of pointer type 'Node*' (maybe you meant to use '->' ?)
   22 |             dst.value = str[1 .. $-1].to!uint;
      |                 ^~~~~
a.cc:22:32: error: expected unqualified-id before '.' token
   22 |             dst.value = str[1 .. $-1].to!uint;
      |                                ^
a.cc:25:20: error: expected ';' before 's'
   25 |             size_t s, c;
      |                    ^
a.cc:26:21: error: 'i' was not declared in this scope
   26 |             foreach(i, e; str){
      |                     ^
a.cc:26:25: error: expected ')' before ';' token
   26 |             foreach(i, e; str){
      |                         ^
a.cc:26:20: note: to match this '('
   26 |             foreach(i, e; str){
      |                    ^
a.cc:26:30: error: expected ';' before ')' token
   26 |             foreach(i, e; str){
      |                              ^
a.cc: At global scope:
a.cc:63:1: error: '::main' must return 'int'
   63 | void main()
      | ^~~~
a.cc: In function 'int main()':
a.cc:65:13: error: 'i' was not declared in this scope
   65 |     foreach(i; 0 .. readln().chomp().to!size_t){
      |             ^
a.cc:65:19: error: expected unqualified-id before '.' token
   65 |     foreach(i; 0 .. readln().chomp().to!size_t){
      |                   ^