from collections import deque

class Node:
    def __init__(self, value, parent):
        self.value = value
        self.parent = parent
        self.links = []
        self.anc_locked = 0
        self.dec_locked = 0
        self.uid = 0
        self.isLocked = False

    def add_links(self, children, parent):
        for child in children:
            self.links.append(Node(child, parent))

def print_tree(root):
    print(f"Parent: {root.value}")
    print("Child: ")
    for child in root.links:
        print(f"{child.value} anc_locked: {child.anc_locked} dec_locked: {child.dec_locked} isLocked: {child.isLocked} uid: {child.uid}")
    print("\n")
    for child in root.links:
        print_tree(child)

def build_tree(root, m, values):
    q = deque([root])
    idx = 1
    while q:
        current = q.popleft()
        if idx >= len(values):
            continue
        temp = []
        for i in range(idx, idx + m):
            if i < len(values):
                temp.append(values[i])
        current.add_links(temp, current)
        idx += m
        for child in current.links:
            q.append(child)    
    return root

class Tree:
    def __init__(self, root):
        self.root = root
        self.vton = {}

    def get_root(self):
        return self.root

    def fill_vton(self, node):
        if not node:
            return
        self.vton[node.value] = node
        for child in node.links:
            self.fill_vton(child)

    def inform_descendants(self, node, val):
        for child in node.links:
            child.anc_locked += val
            self.inform_descendants(child, val)

    def verify_descendants(self, node, uid, locked_nodes):
        if node.isLocked:
            if node.uid != uid:
                return False
            locked_nodes.append(node)
        if node.dec_locked == 0:
            return True
        for child in node.links:
            if not self.verify_descendants(child, uid, locked_nodes):
                return False
        return True

    def lock(self, value, uid):
        node = self.vton.get(value)
        if not node or node.isLocked or node.anc_locked != 0 or node.dec_locked != 0:
            return False
        cur = node.parent
        while cur:
            cur.dec_locked += 1
            cur = cur.parent
        self.inform_descendants(node, 1)
        node.isLocked = True
        node.uid = uid
        return True

    def unlock(self, value, uid):
        node = self.vton.get(value)
        if not node or not node.isLocked or node.uid != uid:
            return False
        cur = node.parent
        while cur:
            cur.dec_locked -= 1
            cur = cur.parent
        self.inform_descendants(node, -1)
        node.isLocked = False
        return True

    def upgrade(self, value, uid):
        node = self.vton.get(value)
        if not node or node.isLocked or node.anc_locked != 0 or node.dec_locked == 0:
            return False
        locked_nodes = []
        if self.verify_descendants(node, uid, locked_nodes):
            for locked_node in locked_nodes:
                self.unlock(locked_node.value, uid)
            self.lock(value, uid)
            return True
        return False

def main():
    n = int(input())
    m = int(input())
    q = int(input())
    
    values = [input().strip() for _ in range(n)]
    root = Node(values[0], None)
    root = build_tree(root, m, values)
    
    t = Tree(root)
    t.fill_vton(t.get_root())
    
    for _ in range(q):
        op, sq, uid = input().split()
        op = int(op)
        uid = int(uid)
        
        if op == 1:
            if t.lock(sq, uid):
                print("true")
            else:
                print("false")
        elif op == 2:
            if t.unlock(sq, uid):
                print("true")
            else:
                print("false")
        elif op == 3:
            if t.upgrade(sq, uid):
                print("true")
            else:
                print("false")

if __name__ == "__main__":
    main()   .