#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Lson root<<1,L,tree[root].Mid()
#define Rson root<<1|1,tree[root].Mid()+1,R
const int maxn = 100005;
struct Hook{int l, r, z;}hook[maxn];
struct Tree{
int L, R;
int isCover;//等于1的时候被覆盖,等于2的时候区间下面有被覆盖的
int Mid(){return (L+R)/2;}
int Len(){return (R-L+1);}
}tree[maxn*4];
void Build(int root, int L, int R)
{
tree[root].L = L, tree[root].R = R;
tree[root].isCover = false;
if(L == R)return ;
Build(Lson);
Build(Rson);
}
void Up(int root)
{
if(tree[root].L != tree[root].R)
if(tree[root<<1].isCover == 1 && tree[root<<1|1].isCover == 1)
tree[root].isCover = 1;
}
int Insert(int root, int L, int R)
{
if(tree[root].isCover == 1)return 0;
if(tree[root].L == L && tree[root].R == R && !tree[root].isCover)
{
tree[root].isCover = 1;
return tree[root].Len();
}
tree[root].isCover = 2;
int ans = 0;
if(R <= tree[root].Mid())
ans = Insert(root<<1, L, R);
else if(L > tree[root].Mid())
ans = Insert(root<<1|1, L, R);
else
ans = Insert(Lson)+Insert(Rson);
Up(root);
return ans;
}
int main()
{
int i, T, t=1;
scanf("%d", &T);
while(T--)
{
int N, M;
scanf("%d%d", &N, &M);
Build(1, 1, N);
for(i=1; i<=M; i++)
scanf("%d%d%d", &hook[i].l, &hook[i].r, &hook[i].z);
int ans = N;
for(i=M; i>0; i--)
{
int len = Insert(1, hook[i].l, hook[i].r);
ans = ans - len + len * hook[i].z;
}
printf("Case %d: The total value of the hook is %d.\n", t++, ans);
}
return 0;
}