#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];
        t[ct] %= 2;
        if ( t[ct] != fv[poz] ) {
            fv[poz] = t[ct];
            long long auxi = -1, auxi2;
            for ( int i = poz;  ( i == poz || fv[i] == 1 ) && i >= 0; i-- ) {
                if ( i == 0 && poz != 0 ) {
                    break;
                }
                if ( i != poz ) {
                    if ( auxi == -1 ) {
                        auxi = h[i];
                    }
                    else {
                        auxi = ( auxi ^ h[i] );
                    }
                    if ( t[ct] == 0 ) {
                        sum -= auxi;
                    }
                    else {
                        sum += auxi;
                    }
                    auxi2 = auxi;
                }
                else {
                    auxi2 = -1;
                }
                for ( int j = poz+1; fv[j] == 1 && j < N; j++ ) {
                    if ( auxi2 == -1 ) {
                        auxi2 = h[j-1];
                    }
                    else {
                        auxi2 = ( auxi2^h[j-1] );
                    }
                    if ( t[ct] == 0 ) {
                        sum -= auxi2;
                    }
                    else {
                        sum += auxi2;
                    }
                }
            }
        }

        ans.push_back ( sum );
    }

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

    return ans;
}