/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
using namespace std;

int T, cas;
int n, m;
int x, y, w;
LL add[100005 << 2], t[100005 << 2];

void up(int p){
	t[p] = t[p << 1] + t[p << 1 | 1];
}

void down(int p, int len){
	if(add[p]){
		add[p << 1] = add[p];
		add[p << 1 | 1] = add[p];
		t[p << 1] = add[p] * (len - (len >> 1));
		t[p << 1 | 1] = add[p] * (len >> 1);
		add[p] = 0;
	}
}

void build(int p, int l, int r){
	add[p] = 0;
	if(l == r){
		t[p] = 1;
		return ;
	}
	int mid = (l + r) >> 1;
	build(p << 1, l, mid);
	build(p << 1 | 1, mid + 1, r);
	up(p);
}

void modify(int p, int L, int R, int l, int r, int w){
	if(L <= l && r <= R){
		add[p] = w;
		t[p] = (LL)w * (r - l + 1);
		return ;
	}
	down(p, r - l + 1);
	int mid = (l + r) >> 1;
	if(L <= mid){
		modify(p << 1, L, R, l, mid, w);
	}
	if(mid < R){
		modify(p << 1 | 1, L, R, mid + 1, r, w);
	}
	up(p);
}

LL querry(int p, int L, int R, int l, int r){
	if(L <= l && r <= R){
		return t[p];
	}
	down(p, r - l + 1);
	int mid = (l + r) >> 1;
	LL ans = 0;
	if(L <= mid) ans += querry(p << 1, L, R, l, mid);
	if(mid < R) ans += querry(p << 1 | 1, L, R, mid + 1, r);
	return ans;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);

	scanf("%d", &T);
	while(T--){
		scanf("%d %d", &n, &m);
		build(1, 1, n);
		for (int i = 1; i <= m; i++){
			scanf("%d %d %d", &x, &y, &w);
			modify(1, x, y, 1, n, w);
		}
		printf("Case %d: The total value of the hook is %lld.\n", ++cas, querry(1, 1, n, 1, n));
	}

	return 0;
}
/**/