#include <bits/stdc++.h>

using namespace std;

vector <long long int> happy ( int N, int Q, vector<int> u, vector<int> v, vector<int> h,
vector<int> t, vector<int> l, vector<int> r )
{
    vector <long long int> ans;

    bool fv[300001];

    for ( int i = 0; i < 300001; i++ ) {
        fv[i] = 0;
    }
    long long sum = 0;
    for ( int ct = 0; ct < Q; ct++ ) {
        long long poz = l[ct]-1;
        t[ct] %= 2;
        if ( t[ct] != fv[poz] ) {
            fv[poz] = t[ct];
            long long auxi = 0;
            for ( int i = poz; fv[i] == 1 || poz == i; i-- ) {
                if ( i != poz ) {
                    auxi = ( h[poz]^h[i] );
                    if ( t[ct] == 0 ) {
                        sum -= auxi;
                    }
                    else {
                        sum += auxi;
                    }
                }
                else {
                    auxi = h[poz];
                }
                for ( int j = poz+1; fv[j] == 1; j++ ) {
                    auxi = ( auxi^h[j] );
                    if ( t[ct] == 0 ) {
                        sum -= auxi;
                    }
                    else {
                        sum += auxi;
                    }
                }
            }
        }

        ans.push_back ( sum );
    }

    /*for ( auto i: ans ) {
        cout << i << ' ';
    }*/

    return ans;
}