#include<bits/stdc++.h>

using namespace std;

vector<int> vec[300005];
bool open[300005];
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;
    long long int curr=0;
    for(int i=0;i<n;i++) {
        vec[u[i]].push_back(v[i]);
        vec[v[i]].push_back(u[i]);
    }
    for(int i=0;i<q;i++) {
        int a=l[i];
        if(t[i]==1) {
            if(open[a]!=true); {
                open[a]=true;
                for(auto edge:vec[a]) {
                    if(open[edge]==true)curr++;
                }
            }
        } else {
            if(open[a]!=false){
                open[a]=false;
                for(auto edge:vec[a]) {
                    if(open[edge]==true)curr--;
                }
            }
        }
        ans.push_back(curr);
    }
    return ans;
}
