#include "happy.h"
#include <bits/stdc++.h>
using namespace std;
int parc(int node,bool deschis[], vector<int> h){
    int sum=0, nod=node;
    while(deschis[nod]==true){
        sum=sum^h[nod];
    }
    return parc;
}
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<long long> res;
    bool deschis[300005]={0};
    int suma=0;
    for(int i=0;i<(int)t.size();i++){
        if(t[i]==1)
            deschis[l[i]]=true;
        else
            deschis[l[i]]=false;
        suma=0;
        for(int j=0;j<N;j++)
            suma+=parc(i, deschis, h);
        res.push_back(suma);
    }
    return res;
}
