#include "happy.h"
#include <bits/stdc++.h>
using namespace std;

std::vector <long long int> happy (int N, int Q, std::vector <int> u, std::vector <int> v, std::vector <int> h, std::vector <int> t, std::vector <int> l, std::vector <int> r) {
    vector<bool> isOpen(N, false);
    vector<vector<int>> adj(N, vector<int>(2));
    for(int i = 0; i < N; i++) {
        adj[i][0] = v[i];
        adj[i][1] = h[i];
    }
    vector<long long int> ret(Q);
    for(int q = 0; q < Q; q++) {
        if(t[q] == 1) {
            isOpen[l[q]] = true;
        }
        else if(t[q] == 2) {
            isOpen[l[q]] = false;
        }
        long long routeHappines;
        for(int i = 0; i < N; i++) {
            if(isOpen[i]) {
                for(int j = 0; j < N; j++) {
                    if(j != i && isOpen[j]) {
                        routeHappines = adj[i][1];
                        int curr = i+1;
                        while(curr != j) {
                            routeHappines = routeHappines ^ adj[curr[1]]
                        }
                    }
                }
            }
        }
        ret[q] = routeHappines;
    }
    return ret;
}
