/*************************************************************************
> File Name: C.cpp
> Author:chudongfang
> Mail:1149669942@qq.com
> Created Time: 2016年08月04日 星期四 08时17分23秒
************************************************************************/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
#define M 111111
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
ll sum[M<<2];
ll add[M<<2];
void pushplus(int rt)
{
sum[rt] = sum[rt<<1] + sum [rt<<1|1];
}
void pushdown(int rt,int m)
{
if(add[rt]){
add[rt<<1] = add[rt];
add[rt<<1|1] = add[rt];
sum[rt<<1] = add[rt] * (m - (m >> 1));
sum[rt<<1|1] = add[rt] * (m >> 1);
add[rt] = 0;
}
}
void build(int l,int r,int rt)
{
if(l == r){
sum[rt] = 1;
add[rt] = 0;
return;
}
int m = (l+r)>>1;
build(lson);
build(rson);
pushplus(rt);
}
void update(int L,int R,int c,int l,int r ,int rt)
{
if(L <= l && r<=R)
{
add[rt] = c;
sum[rt] = (ll)c * (r-l+1);
return ;
}
pushdown(rt , r-l+1);
int m = (l+r)>>1;
if(L<=m)
update(L,R,c,lson);
if(R>m)
update(L,R,c,rson);
pushplus(rt);
}
int main(int argc,char *argv[])
{
int q,a,b,c,n,T;
scanf("%d",&T);
for(int k=1;k<=T;k++)
{
memset(sum,0,sizeof(sum));
memset(add,0,sizeof(add));
scanf("%d %d",&n,&q);
build(1,n,1);
for(int i=1;i<=q;i++)
{
scanf("%d %d %d",&a,&b,&c);
update(a,b,c,1,n,1);
}
printf("Case %d: The total value of the hook is %lld.\n", k,sum[1]);
}
return 0;
}