static int s_GetTreeHeight(const CQueryParseTree::TNode& node)
{
    if (node.IsLeaf()) return 0;

    CQueryParseTree::TNode::TNodeList_CI iter = node.SubNodeBegin();
    vector<int> heights;
    for ( ; iter != node.SubNodeEnd(); ++iter) {
        CQueryParseTree::TNode& sub_node = **iter;
        heights.push_back(s_GetTreeHeight(sub_node));
    }

    auto it = max_element(begin(heights), end(heights));
    return *it + 1;
}
static int s_CountNodesOfGivenType(const CQueryParseTree::TNode& node, CQueryParseNode::EType type)
{
    if (node.IsLeaf()) {
        return (node->GetType() == type) ? 1 : 0;
    }

    CQueryParseTree::TNode::TNodeList_CI iter = node.SubNodeBegin();
    int count = 0;
    for (; iter != node.SubNodeEnd(); ++iter) {
        CQueryParseTree::TNode& sub_node = **iter;
        count += s_CountNodesOfGivenType(sub_node, type);
    }

    return (node->GetType() == type) ? count +1 : count;
}