public static void main (String args[]) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int round = Integer.parseInt(reader.readLine());

        for (int i = 0; i < round; i++) {
            StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
            int nodeCount = Integer.parseInt(tokenizer.nextToken());
            int operationCount = Integer.parseInt(tokenizer.nextToken());

            Tree tree = new Tree();
            int[][] input = new int[nodeCount][2];
            // BUG2: omit the situation the input value are not in order
            for (int j = 0; j < nodeCount; j++) {
                String line = reader.readLine();
                tokenizer = new StringTokenizer(line);
                int value = Integer.parseInt(tokenizer.nextToken());
                input[value][0] = Integer.parseInt(tokenizer.nextToken());
                input[value][1] = Integer.parseInt(tokenizer.nextToken());
            }
            for (int j = 0; j < nodeCount; j++) {
                tree.addNode(j, input[j][0], input[j][1]);
            }


            for (int j = 0; j < operationCount; j++) {
                String line = reader.readLine();
                tokenizer = new StringTokenizer(line);

                if ("1".equals(tokenizer.nextToken())) {
                    tree.switchNode(Integer.parseInt(tokenizer.nextToken()),
                            Integer.parseInt(tokenizer.nextToken()));
                } else {
                    // BUG1: "2".equals(tokenizer.nextToken()) retrieve an extra token
                    System.out.println(tree.getLeftValue(Integer.parseInt(tokenizer.nextToken())));
                }
            }
        }
    }