#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;

vector<ll> happy(int N, int Q,
	vector<int> u, vector<int> v, vector<int> h,
	vector<int> t, vector<int> l, vector<int> r) {
	map<int, vector<pair<int, int>>> mp;
	vector<ll> ans(Q, 0);
	/*for (int i = 0; i < N - 1; i++) {
		mp[u[i]].push_back({ v[i],h[i] });
		mp[v[i]].push_back({ u[i],h[i] });
	}
	vector<int> opened(N, 0);
	for (int x = 0; x < Q; x++) {
		vector<int> change;
		if (l[x] == r[x]) change.push_back(l[x]);
		else {
			vector<int> vis(N + 1, 0);
			queue < pair<int, vector<int>>> q;
			q.push({ l[x], {l[x]} });
			bool flag = false;
			while (!q.empty()) {
				auto v = q.front();
				q.pop();
				for (auto j : mp[v.first]) {
					if (vis[j.first] == 0) {
						vis[j.first] = 1;
						vector<int> cur = v.second;
						cur.push_back(j.first);
						if (j.first == r[x]) {
							flag = true;
							change = cur;
							break;
						}
						q.push({ j.first, cur });
					}
				}
				if (flag) break;
			}
		}
		//cout << "\n";
		if (t[x] == 1) {
			for (int i : change) {
				opened[i] = 1;
			}
		}
		else {
			for (int i : change) {
				opened[i] = 0;
			}
		}
		//for (int i : change) cout << i << " ";
		//cout << "\n";
		ll sum = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				if (opened[i] == 1 && opened[j] == 1) {
					//cout << "\n\n" << i << " " << j << "\n\n";
					ll XOR = 0;
					vector<int> vis2(N + 1, 0);
					queue<pair<int, int>> q2;
					q2.push({ i, -1 });
					bool flag = false;
					while (!q2.empty()) {
						auto v = q2.front();
						q2.pop();
						for (auto g : mp[v.first]) {
							//cout << g.first << " " << v.second << "\n";
							if (vis2[g.first] == 0) {
								vis2[g.first] = 1;
								if (g.first == j) {
									flag = true;
									if (v.second == -1) XOR = g.second;
									else XOR = (v.second ^ g.second);
									break;
								}
								if (v.second == -1) q2.push({ g.first, g.second });
								else q2.push({ g.first, (v.second ^ g.second) });
							}
						}
						if (flag) break;
					}
					sum += XOR;
				}
			}
		}
		ans.push_back(sum);
	}*/
	return ans;
}