#define LL long long
#define eps 1e-8
#define maxn 101000
#define mod 100000007
#define inf 0x3f3f3f3f
#define mid(a,b) ((a+b)>>1)
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n;
LL num[maxn];
struct Tree
{
int left,right;
LL lazy,sum,equl;
}tree[maxn<<2];
void build(int i,int left,int right)
{
tree[i].left=left;
tree[i].right=right;
tree[i].lazy=0;
if(left==right){
tree[i].sum = num[left];
tree[i].equl = num[left];
return ;
}
int mid=mid(left,right);
build(i<<1,left,mid);
build(i<<1|1,mid+1,right);
tree[i].sum = tree[i<<1].sum + tree[i<<1|1].sum;
tree[i].equl = tree[i<<1].equl==tree[i<<1|1].equl ? tree[i<<1].equl : -1;
}
void pushdown(int i)
{
if(tree[i].equl != -1) {
tree[i<<1].equl = tree[i].equl;
tree[i<<1|1].equl = tree[i].equl;
tree[i<<1].sum = (tree[i<<1].right-tree[i<<1].left+1)tree[i].equl;
tree[i<<1|1].sum = (tree[i<<1|1].right-tree[i<<1|1].left+1)tree[i].equl;
tree[i].lazy = 0;
tree[i<<1].lazy = 0;
tree[i<<1|1].lazy = 0;
}
if(tree[i].lazy) {
tree[i<<1].lazy += tree[i].lazy;
tree[i<<1|1].lazy += tree[i].lazy;
tree[i<<1].sum += (tree[i<<1].right-tree[i<<1].left+1)tree[i].lazy;
tree[i<<1|1].sum += (tree[i<<1|1].right-tree[i<<1|1].left+1)tree[i].lazy;
if(tree[i<<1].equl != -1) {
tree[i<<1].equl += tree[i].lazy;
tree[i<<1].lazy = 0;
}
if(tree[i<<1|1].equl != -1) {
tree[i<<1|1].equl += tree[i].lazy;
tree[i<<1|1].lazy = 0;
}
tree[i].lazy = 0;
}
}
void update(int i,int left,int right,LL d)
{
if(tree[i].leftleft&&tree[i].rightright)
{
tree[i].sum += (right-left+1)*d;
if(tree[i].equl == -1) tree[i].lazy += d;
else tree[i].equl += d;
return ;
}
pushdown(i);
int mid=mid(tree[i].left,tree[i].right);
if(right<=mid) update(i<<1,left,right,d);
else if(left>mid) update(i<<1|1,left,right,d);
else {
update(i<<1,left,mid,d);
update(i<<1|1,mid+1,right,d);
}
tree[i].sum = tree[i<<1].sum + tree[i<<1|1].sum;
tree[i].equl = tree[i<<1].equl==tree[i<<1|1].equl ? tree[i<<1].equl : -1;
}
void update_sqrt(int i,int left,int right)
{
if(tree[i].leftleft&&tree[i].rightright && tree[i].equl!=-1)
{
tree[i].equl = (LL)sqrt(tree[i].equl);
tree[i].sum = tree[i].equl * (tree[i].right-tree[i].left+1);
tree[i].lazy = 0;
return ;
}
pushdown(i);
int mid=mid(tree[i].left,tree[i].right);
if(right<=mid) update_sqrt(i<<1,left,right);
else if(left>mid) update_sqrt(i<<1|1,left,right);
else {
update_sqrt(i<<1,left,mid);
update_sqrt(i<<1|1,mid+1,right);
}
tree[i].sum = tree[i<<1].sum + tree[i<<1|1].sum;
tree[i].equl = tree[i<<1].equl==tree[i<<1|1].equl ? tree[i<<1].equl : -1;
}
LL query(int i,int left,int right)
{
if(tree[i].leftleft&&tree[i].rightright)
return tree[i].sum;
pushdown(i);
int mid=mid(tree[i].left,tree[i].right);
if(right<=mid) return query(i<<1,left,right);
else if(left>mid) return query(i<<1|1,left,right);
else return query(i<<1,left,mid)+query(i<<1|1,mid+1,right);
}
int main(int argc, char const *argv[])
{
//IN;
int t; cin >> t;
while(t--)
{
int m;
scanf("%d %d", &n,&m);
for(int i=1; i<=n; i++)
scanf("%lld", &num[i]);
build(1, 1, n);
while(m--) {
int op, l, r;
scanf("%d %d %d", &op,&l,&r);
if(op == 1) {
LL x; scanf("%lld", &x);
update(1, l, r, x);
}
else if(op == 2) {
update_sqrt(1, l, r);
}
else if(op == 3) {
printf("%lld\n", query(1, l, r));
}
}
}
return 0;
}