Another Tree Queries Problem

QOJ - 1163