#include "stdio.h"
const int maxn = 100050;
int n,x,y,z;
struct Node
{
int val;
}tree[maxn*4];
void pushup( int t )
{
tree[t].val = tree[t*2].val + tree[t*2+1].val;
}
void pushdown( int t )
{
tree[t*2].val = tree[t*2+1].val = tree[t].val;
}
void buildtree( int ld,int rd,int t )
{
tree[t].val = 1;
if( ld == rd )
{
return;
}
int mid = ( ld+rd )/2;
buildtree( ld,mid,t*2 );
buildtree( mid+1,rd,t*2+1 );
}
void updata( int ld,int rd,int t )
{
if( x<=ld && rd<=y )
{
tree[t].val = z;
return;
}
if( tree[t].val )
{
pushdown( t );
tree[t].val = 0;
}
int mid = ( ld + rd )/2;
if( x<=mid ) updata( ld,mid,t*2 );
if( y>mid ) updata( mid+1,rd,t*2+1);
}
int sum( int ld,int rd ,int t )
{
if( tree[t].val )
return ( rd - ld + 1 )*tree[t].val;
int mid = ( ld + rd )/2;
return sum( ld,mid,t*2 ) + sum( mid+1,rd,t*2+1 );
}
int main()
{
int i,j,t,cas=1,q;
scanf("%d",&t);
while( t-- )
{
scanf("%d%d",&n,&q);
buildtree( 1,n,1 );
for( i=1; i<=q; i++ )
{
scanf("%d%d%d",&x,&y,&z);
updata( 1,n,1 );
}
printf( "Case %d: The total value of the hook is %d.\n",cas++,sum( 1,n ,1) );
}
return 0;
}