#include <bits/stdc++.h>
#include "happy"
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(q, 0);
    for(long long i = 0; i < q; i++)ans[0] += h[i];
    vector<bool> v(n, true);
    for(long long i = 0; i < q; i++)
    {
        bool t = v[q];
        if(t[q] - 1)v[q] = true;
        else v[q] = false;
        if(v[q] != t)
        {
            if(v[q])
            {
                ans[i] = ans[i - 1];
                if(i < q - 1) ans[i] += h[i];
                if(i > 0)ans[i] += h[i - 1];
            }
            else
            {
                ans[i] = ans[i - 1];
                if(i < q - 1) ans[i] -= h[i];
                if(i > 0)ans[i] -= h[i - 1];
            }
        }
    }
    return ans;
}