How would you design a permission system using a tree data structure?
Implement permission_queries(parent, permissions, operations). parent maps each node to its parent, with the root mapped to None. permissions[node][principal][action] is either "allow" or "deny". Operations are ['grant', node, principal, action], ['revoke', node, principal, action], or ['check', node, principal, action]. A permission is inherited from ancestors, and the closest explicit rule wins. Return booleans for check operations in order.
Constraints: the structure is a valid rooted tree, node depth is at most 5,000, and there are at most 5,000 operations. Actions and principals are non-empty strings.
def permission_queries(parent, permissions, operations):