#include <iostream>
#include <cstdio>
using namespace std;
const int MAX = 100100;
struct Tree
{
int l,r,mark;
}tree[MAX * 4];
void BuildTree(int root,int l,int r)
{
tree[root].l = l;
tree[root].r = r;
tree[root].mark = 1;
if(tree[root].l == tree[root].r)
return ;
int mid = (tree[root].l + tree[root].r) / 2;
BuildTree(root << 1,l,mid);
BuildTree(root << 1|1,mid + 1,r);
}
void Update(int root,int l,int r,int val)
{
if(l <= tree[root].l && r >= tree[root].r)
{
tree[root].mark = val;
return ;
}
if(tree[root].mark != -1)
{
tree[root << 1].mark = tree[root << 1|1].mark = tree[root].mark;
tree[root].mark = -1;
}
int mid = (tree[root].l + tree[root].r) / 2;
if(l <= mid) Update(root << 1,l,r,val);
if(r > mid) Update(root << 1|1,l,r,val);
}
int Query(int root,int l,int r)
{
if(tree[root].l == l && tree[root].r == r)
{
if(tree[root].mark != -1)
{
return (r - l + 1) *tree[root].mark;
}
else
{
int mid = (tree[root].l + tree[root].r) / 2;
return Query(root << 1,l,mid) + Query(root << 1|1,mid + 1,r);
}
}
int mid = (tree[root].l + tree[root].r) / 2;
if(r <= mid) return Query(root << 1,l,mid);
else if(l > mid) return Query(root << 1|1,mid + 1,r);
else
{
return Query(root << 1,l,mid) + Query(root << 1|1,mid + 1,r);
}
}
int main()
{
int T,cas = 1;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d",&n);
BuildTree(1,1,n);
scanf("%d",&m);
while(m--)
{
int L,R,change;
scanf("%d%d%d",&L,&R,&change);
Update(1,L,R,change);
}
printf("Case %d: The total value of the hook is %d.\n",cas,Query(1,1,n));
cas ++;
}
return 0;
}