#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod  1000000007
#define write freopen("output.txt","w",stdout)
#define read freopen("test (1).txt","r",stdin)
#define FIO std::ios_base::sync_with_stdio(false);
using namespace std;
int a[100005],timer;
ll square[4*100005];
int suming[4*100005];
int lazy1[4*100005],lazy2[4*100005];
int t1[4*100005],t2[4*100005];

void init()
{
    memset(square,0,sizeof(square));
    memset(suming,0,sizeof(suming));
    memset(lazy1,0,sizeof(lazy1));
    memset(lazy2,0,sizeof(lazy2));
    memset(t1,0,sizeof(t1));
    memset(t2,0,sizeof(t2));
}
void shift(int node,int L,int R)
{
    if(t1[node] > t2[node])
    {
        if(lazy1[node])
        {
            int val = lazy1[node];
            int len = R-L+1;
            square[node] = (square[node] + 2LL * val * suming[node] + len * val * val);
            suming[node] += (1LL * len * val);

            if(t1[2*node] > t2[2*node])
            {
                lazy1[2*node] += lazy1[node];
                lazy1[2*node] += lazy1[node];
                t1[2*node] = t1[node];
            }
            else
            {
                lazy2[2*node] += lazy1[node];
                lazy2[2*node] += lazy1[node];
                t2[2*node] = t1[node];
            }
            if(t1[2*node+1] > t2[2*node+1]) 
            {
                lazy1[2*node+1] += lazy1[node];
                lazy1[2*node+1] += lazy1[node];
                t1[2*node+1] = t1[node];
            }
            else
            {
                lazy2[2*node+1] += lazy1[node];
                lazy2[2*node+1] += lazy1[node];
                t2[2*node+1] = t1[node];
            }
        }
        lazy1[node] = 0;
    }
    else
    {
        if(lazy2[node])
        {
            int val = lazy2[node];
            int len = R-L+1;
            square[node] = 1LL * len * val * val;
            suming[node] = (1LL * len * val);
            if(t1[2*node] > t2[2*node]) /// time increment
            {
                lazy1[2*node] += lazy2[node];
                lazy1[2*node] += lazy2[node];
                t1[2*node] = t2[node];
            }
            else
            {
                lazy2[2*node] += lazy2[node];
                lazy2[2*node] += lazy2[node];
                t2[2*node] = t2[node];
            }


            if(t1[2*node+1] > t2[2*node+1]) /// time increment
            {
                lazy1[2*node+1] += lazy2[node];
                lazy1[2*node+1] += lazy2[node];
                t1[2*node+1] = t2[node];
            }
            else
            {
                lazy2[2*node+1] += lazy2[node];
                lazy2[2*node+1] += lazy2[node];
                t2[2*node+1] = t2[node];
            }
        }
        lazy2[node] = 0;
    }
    t1[node] = t2[node] = 0;
}
void update1(int node,int L,int R,int l,int r,int val) /// add val to all number [l,r]
{
    shift(node,L,R);
    if(L > R || L > r || R < l)
        return ;
    if(L >= l && R <= r)
    {
        lazy1[node] = val;
        t1[node] = timer;
        shift(node,L,R);
        return ;
    }

    int mid = (L+R)/2;
    update1(2*node,L,mid,l,r,val);
    update1(2*node+1,mid+1,R,l,r,val);

    square[node] = square[2*node] + square[2*node+1];
    suming[node] = suming[2*node] + suming[2*node+1];

}
void update2(int node,int L,int R,int l,int r,int x) /// set x to all number [l,r]
{
    shift(node,L,R);
    if(L > R || L > r || R < l)
        return ;
    if(L >= l && R <= r)
    {
        lazy2[node] = x;
        t2[node] = timer;
        square[node] = 0;
        suming[node] = 0;
        shift(node,L,R);
        return ;
    }

    int mid = (L+R)/2;
    update2(2*node,L,mid,l,r,x);
    update2(2*node+1,mid+1,R,l,r,x);

    square[node] = square[2*node] + square[2*node+1];
    suming[node] = suming[2*node] + suming[2*node+1];

}
void build(int node,int L,int R)
{
    if(L == R)
    {
        square[node] = 1LL * a[L] * a[L];
        suming[node] = a[L];
        return ;
    }
    int mid = (L+R)/2;
    build(2*node,L,mid);
    build(2*node+1,mid+1,R);

    square[node] = square[2*node] + square[2*node+1];
    suming[node] = suming[2*node] + suming[2*node+1];
}
ll query(int node,int L,int R,int l,int r)
{
    if(L > R || L > r || R < l)
        return 0;

    shift(node,L,R);

    if(L >= l && R <= r)
        return square[node];

    int mid = (L + R) / 2;
    ll sum1 = query(node*2, L, mid, l, r);
    ll sum2 = query(node*2 + 1, mid + 1, R, l, r);
    return (sum1 + sum2);
}

int main()
{
    int t,num = 1;
    cin >> t;
    while(t--)
    {
        printf("Case %d:\n",num++);
        init();
        timer = 0;
        int n,q;
        cin >> n >> q;
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        build(1,0,n-1);
        while(q--)
        {
            timer++;
            int c,x,y,z;
            scanf("%d",&c);
            if(c == 2)
            {
                scanf("%d%d",&x,&y);
                ll ans = query(1,0,n-1,x-1,y-1);
                printf("%I64d\n",ans);
            }
            else
            {
                scanf("%d%d%d",&x,&y,&z);
                if(c == 1)
                    update1(1,0,n-1,x-1,y-1,z);
                else
                    update2(1,0,n-1,x-1,y-1,z);

            }
        }
    }



    return 0;
}
