Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fr for(int i=0; i<t; i++)
#define frj for(int j=0; j<n; j++)
#define int long long int
#define pb push_back
#define vii vector<pair<int,int>>
#define pii pair<int,int>
using ll = long long;
/*
⣿⣿⡿⣽⣿⣿⢽⢿⡾⢸⡀⡀⡀⡀⣾⣿⣿⠿⠁⡀⡴⡀⡀⡏⡀⡀⡀⠁⡀⣸⡀⡀⢼⡀⡀⢀⡀⡀⢣⡀⡀⡀⡀⡀⠳⡀⡀⡀⡀⡀⢰⡐⡀⡀⠲⡀⠈⠛⣿⣿⣷⣄⡀⡀⡀⡀⡀⠹⣿⠸⠸⠨⠅⡀⠢⠌⠙⡄⡀⡀
⣿⡿⣿⣿⣿⣿⢽⣰⠁⠇⡀⡀⢀⣿⣿⡿⠁⡀⢀⠊⡀⡠⣡⡀⡀⡀⡀⡀⡀⡀⡀⡀⢸⡀⡀⡀⡀⡀⠸⡀⠠⡀⡀⡀⡀⡀⠲⡀⡀⡀⣾⣿⣷⣕⡀⡀⠓⣄⡀⠈⢿⣿⣿⣄⡀⡀⡀⡀⠹⡇⡀⠄⠡⠠⠈⡀⠈⣷⡀⡀
⣿⢱⣿⣿⣿⡟⣴⠁⠎⡀⡀⡀⢿⣿⠟⡀⡀⡠⠁⡀⡀⣴⠃⡀⡀⡀⡀⡀⡀⡄⡀⡀⡀⡀⡀⡀⡀⡀⡀⡄⡀⠈⡀⡀⡀⡀⡀⠈⠄⢠⣿⣿⣿⣿⣿⣤⡀⡀⠙⢄⡀⠙⣿⣿⠇⡀⡀⡀⡀⠹⡆⠙⢤⠨⢨⡅⡀⣿⡀⡀
⣿⣺⣿⠝⣭⡿⢁⠋⡀⡀⣀⡀⡀⡀⡀⡀⠞⡀⢀⣢⣿⡿⡀⡀⡀⡀⢀⡀⡀⡇⡀⡀⡀⡇⡀⡀⡀⡀⡀⣇⡀⡀⡀⡄⡀⡀⡀⡀⡀⢋⠮⡻⣿⣿⣿⣧⣿⣦⡒⡀⠈⢦⡀⡀⡀⡀⣤⣄⡀⡀⢳⠘⠁⡇⠠⡀⠄⡿⡀⡀
⣿⣶⣾⡿⠁⡠⠁⡀⢀⣾⣿⡿⡀⡀⡀⠁⡀⠔⣾⣿⣿⠁⡀⡀⡀⡀⣼⡀⡀⡇⡀⡀⡀⣿⡀⡀⡀⡀⡀⢻⡀⡀⡀⠈⢦⡀⡀⡀⡸⠂⠡⡀⠓⢝⢿⣿⡎⣿⣿⣷⣑⢀⠈⢦⡀⡀⠈⢿⣿⣦⡀⣇⠠⢻⡀⡀⡀⡇⡀⡀
⠿⠋⡀⡤⠊⡄⡀⣴⣿⣿⠟⡀⡀⡔⡀⢀⣪⣿⣿⠟⡟⡀⡀⡀⡀⡀⠇⡀⡀⡇⡀⡀⡀⣿⡆⡀⡀⡀⡀⢸⡀⡀⡀⡀⡀⠙⢄⡀⠃⢌⢀⡂⡀⡀⢉⢿⠻⢹⣿⣿⣿⣿⣤⠄⡀⢀⡀⡀⠙⣿⣿⣌⡄⢸⡀⠐⡀⠃⡀⡀
⠴⠛⢁⡤⣻⠇⣾⣿⣿⠋⡀⢀⠋⡀⡠⣵⣿⣿⢋⡣⡇⡀⡀⡀⡀⣸⡀⡀⡀⡇⡀⡀⡀⣿⣿⡀⡀⢰⡀⠘⣿⡀⡀⡀⡀⡀⡀⡝⢌⠒⡀⠁⡀⡀⡀⡄⡆⣇⡻⣿⣿⣿⣿⣹⡬⠄⠙⢄⡀⡀⠻⣿⣿⡘⡂⠂⢸⡀⡀⡀
⡖⢻⣫⣎⣠⣿⣿⡿⠁⡀⡠⠁⡀⠎⣾⣿⢿⢰⡎⡇⡇⡀⡀⡀⡀⠇⡀⡀⡀⡀⡀⡀⡀⣿⣿⡆⡀⡀⡄⡀⣿⣿⡄⡀⡀⡀⢀⠠⡀⠉⢦⡁⠢⡀⡀⠈⢸⢸⡀⠓⡻⣿⣿⣇⣿⠹⣦⡀⠙⢄⡀⠙⣿⣿⢈⡀⡟⡀⡀⡀
⢇⣪⡎⣰⣿⣿⡟⡀⡀⡜⡀⢀⢠⣿⣿⠏⢸⡸⢳⡀⡂⡀⡀⡀⣸⡀⡀⡀⡀⡀⡀⡀⢰⣿⣿⣿⡀⡀⢘⡀⢿⣿⣿⣦⡀⡀⡞⡀⡀⡀⡀⡀⠓⢄⠈⠁⡀⣧⡀⡀⡀⠪⠻⣿⢻⣧⣿⣿⣄⡀⠑⡀⠈⣌⡄⢠⡀⡀⡀⡀
⠷⠛⠁⣿⣿⡏⡀⢀⠎⡀⡄⣰⣿⣿⠋⢪⢼⡱⡞⡀⡇⡀⡀⡀⠃⡀⡀⡀⢀⡀⡀⡀⣼⡇⢹⣿⣧⡀⡀⢁⠘⡆⠻⣿⣷⡀⡀⡀⠂⡀⡀⡀⢐⡀⠈⠑⠦⣹⡆⡀⡀⡀⠈⢌⢸⣿⠘⣿⣿⣷⡀⡀⢢⡀⠻⣧⡀⡀⡀⡀
⡯⢽⡧⠙⢋⠄⣠⠁⡀⠞⣾⣿⡿⠡⢕⢪⣿⢵⡀⡀⠂⡀⡀⡜⡀⡀⡀⡀⢸⡀⡀⡀⣿⡀⡀⢿⣿⡀⡀⢲⡀⣷⡀⠈⢿⢸⣷⡀⡀⡀⡀⡀⠐⠤⣀⡀⡀⡀⡇⡀⡀⡀⡀⡀⠱⡻⣇⣿⣿⣿⣿⣄⡄⠙⡀⠙⣿⣦⡀⡀
⢃⣴⡌⠕⠺⡴⡀⢀⢊⡟⣿⠟⢾⡪⠕⠘⣿⡏⡀⡀⡀⡀⢀⠁⡀⡀⡀⡀⣿⡀⡀⢠⡟⡀⡀⡀⣿⣿⡀⡀⡀⢹⡀⡀⢰⠙⢿⣿⣦⡀⡀⡀⡀⡀⡀⠈⠐⡀⢹⡀⡀⡀⡀⠈⡀⡌⣝⣿⣿⣿⣿⣾⣆⢄⡀⢆⡀⢿⣿⣄
⣿⣿⢃⠃⡞⡀⢀⢃⣿⣇⠏⢘⡗⡜⡑⢈⣷⡀⡀⡀⡀⡀⠏⡀⡀⡀⡀⣼⡇⡀⡀⣾⠁⡀⡀⡀⠈⣿⣇⡀⢳⡀⡆⡀⠇⡀⡀⠈⠻⣿⣷⣄⣀⠤⠖⠚⠉⢁⢸⡀⡀⡀⡀⡀⡀⡇⠈⣿⣿⣿⣿⣿⣯⣦⢦⡀⢦⡀⠈⢿
⣿⢁⢫⣎⢸⣠⢁⣿⣿⡇⠂⢱⡇⡕⢑⡂⡇⡀⡀⡀⡄⡼⡀⡀⡀⡀⢀⣿⠃⡀⡀⡟⡀⡀⡀⡀⡀⠘⣿⡀⡀⡄⢷⢸⡀⡀⢀⣠⠖⠊⠉⠻⢿⣷⣤⣀⡀⡀⡀⡀⡀⠅⡀⡀⡀⡇⡀⣿⣿⣿⣿⣿⣿⣿⣷⠣⡀⠳⡀⡀
⣧⢀⢣⠤⡰⢠⣿⣿⢹⡇⡀⢪⡇⡎⢌⣸⡇⡀⡀⢠⣷⡀⡀⡀⡀⡀⣾⢻⡀⡀⣼⡀⡀⡀⡀⡀⡀⡀⠘⣿⡀⠸⠘⢁⠖⠉⡀⡀⡀⡀⡀⡀⣠⠤⠉⠻⠿⣿⣦⡀⡀⡂⡀⡀⡀⡇⡀⣿⣿⣿⣿⣿⣿⣿⣿⣿⠱⡀⠱⡀
⢂⠋⠒⡜⣠⣿⣿⠃⣿⡇⠰⢸⡇⡃⠑⠇⡇⡀⡀⢸⢀⡀⡀⡀⡀⢰⡟⣾⣀⣀⡯⠤⠤⠤⠄⡀⡀⡀⡀⠘⣧⡀⣳⣇⡀⡀⡀⡀⣠⠖⠋⡀⡀⡀⣠⣴⣟⣿⢸⡀⡀⡀⡀⡀⢰⡀⡀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠱⡀⠙
⢋⠖⡞⣰⣿⣿⡏⢂⣿⡇⢐⢸⡇⠂⣸⡀⡇⡀⡀⣸⣨⠤⠖⠚⠉⡿⡀⡇⡀⣼⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠈⣆⠁⠞⡀⡀⢒⠏⡀⡀⣠⣴⣾⡿⣿⣿⠁⠇⠸⡀⢀⡀⡀⡀⢸⡀⡀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⢱⡀
⠌⡞⣰⣿⣿⣿⠨⣸⣿⡇⡀⢨⡃⡑⠃⡀⡇⡀⡀⢸⡀⡀⡀⡀⣾⡀⡀⡀⢀⠃⣀⣀⣀⢀⡀⡀⡀⡀⡀⡀⡀⡌⣦⡀⢷⡀⣀⣶⣿⡿⠛⠉⣿⢠⣿⣿⡜⡀⡀⡀⠨⡀⡀⡀⡟⡀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢨⡀
⡜⣰⣿⣿⢹⢹⣼⠟⠉⡧⠰⢸⡇⡼⡀⡀⡇⡀⡀⢸⡀⡀⠐⣼⠉⠉⣸⡀⡞⡀⡀⡀⠑⠤⠁⡀⡀⡀⡀⡀⢀⡀⡀⢦⡀⢧⠞⠉⡀⡀⡀⡀⢿⣿⠿⢓⠞⡀⡀⡇⠂⡀⡀⢠⢀⢀⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢃⠁⢀
⢠⣿⣿⣿⠸⢸⣿⡀⣦⡏⢪⢸⡇⠁⡀⡀⡇⡀⡀⣸⣀⣀⣼⣤⣤⣤⢣⣶⣶⣿⣿⣿⣿⣿⣭⣀⡀⡀⡀⡀⡎⡀⡀⡀⠙⡀⢦⡀⡀⠰⠶⠯⠖⠛⠉⡀⡀⡀⢰⠇⡀⡀⡀⣏⠁⣾⢻⣿⣷⣿⣿⣿⣿⣿⣿⣿⠃⠃⡀⠏
⣿⣿⣿⣿⡠⢸⢸⡀⡛⡇⠨⢘⡯⡀⡀⡀⡇⡀⡀⣿⠻⡛⠛⠛⠋⣹⢉⢻⠉⡙⢸⡀⣿⡀⡀⡀⡀⡀⡀⢠⡀⡀⡀⡀⡀⠈⢦⠙⣄⡀⡀⡀⡀⡀⡀⡀⡀⡀⣸⡀⡀⠠⣰⠁⣠⣿⢸⣿⣿⣿⣿⣿⣿⣿⣿⠋⠊⢀⠋⡀
⣿⣿⣿⣿⡇⣸⡜⡇⣇⣇⠰⣸⠁⡀⡀⡀⡇⡀⡀⣿⣼⠙⢦⡀⢀⠃⡞⡀⢷⢀⣉⡤⠿⡤⡀⡀⡀⡀⡀⡏⡀⡀⡀⡀⡀⡀⡀⠉⢦⠓⣄⡀⡀⡀⡀⡀⡀⡀⣿⡀⡀⡼⡀⢠⣿⣿⡤⠟⠛⠉⡀⡀⡀⣽⠃⡀⢀⠁⡀⡀
⣿⣿⣿⣿⡇⣿⡇⣿⡀⣟⠸⡏⡂⡀⡀⡀⣧⡀⡀⣿⠃⡀⡀⠒⠏⡼⠭⠭⠵⠖⠛⠉⡀⡀⡀⡀⡀⡀⢰⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠈⠦⡉⠦⣄⡀⡀⡀⡀⣥⣠⠋⡀⡴⠁⡿⠁⡀⡀⡀⡀⡀⡀⣴⢁⡀⢠⠁⡀⡀⣴
⣿⣿⣿⣿⡇⣿⣇⣿⣷⣿⢸⡀⠅⡀⡀⡀⢽⡀⡀⣿⠈⡀⡀⠏⣰⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠇⡀⡀⡀⡐⡀⡀⡀⡀⡀⡀⡀⡀⡀⠙⠦⣀⠉⠉⠉⠁⡀⣤⠋⠂⡂⡇⡀⡀⡀⡀⡀⡀⡼⡠⡀⣠⠁⡀⣠⣿⣿
⣿⣿⣿⣿⣷⢹⣿⣿⣿⣿⡎⡀⡅⡀⡀⡀⢸⡀⡀⡇⡀⢀⠋⣠⠁⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⣸⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡠⣄⡀⡀⠈⠙⣶⡞⠁⡀⡀⡀⠅⡇⡀⡀⡀⡀⢀⠞⠜⡀⡴⡀⡀⣴⣿⣿⠋
⣿⣿⣿⣿⣿⢸⣿⣿⣿⡿⡀⡀⡅⡀⡀⡀⠸⡀⡀⡅⡰⠁⡴⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠃⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠓⠏⡀⡀⢀⣿⣿⢰⡀⡀⡀⡀⠂⡯⡀⡀⡀⢀⢃⠃⡀⡜⡀⡀⣼⣿⣿⠁⡀
⣿⣿⣿⣿⣿⢸⣿⢸⣿⣱⡀⡀⡃⡀⡀⡀⡀⡀⢠⡋⡀⠜⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡸⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⣠⣿⣿⡏⣿⣀⡀⡀⡀⡀⣟⡀⡀⡴⡡⡀⢀⠊⡀⡀⣾⣿⡿⡀⡀⣠
⣿⣿⣿⣿⣿⣸⣿⢸⡟⣿⡀⡀⡇⡀⡀⡀⡀⡀⢸⣠⡁⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠁⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⢀⣾⠿⠋⠁⡀⡀⡀⠳⡀⡀⢸⣿⣠⡿⡔⡀⣠⠁⡀⡀⡀⡀⡀⡀⡀⣠⠁
⣿⣿⣿⣿⣿⢸⣿⣼⢰⣟⡀⡀⡯⡀⡀⡀⡀⡀⢸⣿⣿⣄⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡜⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⢀⣾⣿⠁⡀⡀⣆⡀⡀⡇⡀⠈⢤⢸⣿⠟⠜⡀⡴⡀⡀⣠⣿⡀⡀⢀⣤⣿⠇⡀
⣿⣿⣿⣿⣿⢸⣿⡏⣿⣿⡀⡀⢸⡀⡀⡀⡀⡀⢸⣿⣿⣿⣷⣤⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⢀⡀⡀⡀⡀⡀⢀⠤⠤⡀⡀⡀⡀⡀⣠⠞⢩⣿⣿⡀⡀⡀⡀⣦⠼⡀⡀⠄⡀⠙⢯⡊⡀⠎⡀⡀⣰⣿⠟⣠⠞⡀⡀⢠⡀⡀
⡀⠻⣿⣿⣿⢸⣿⣸⠟⣿⡀⡀⡀⡀⡀⡀⡀⡀⢸⣿⣿⣿⣿⣿⣿⣷⣤⣀⡀⡀⡀⡀⡀⡀⡞⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⢀⣴⠟⠁⡀⣸⣿⣿⣦⡀⢳⡀⡀⣧⠐⡀⡀⡀⡀⠋⡀⠈⠉⠛⠚⠿⠿⠿⠷⠤⠴⣶⣇⣀⣐
⠳⡀⠈⢿⣿⢸⠇⢃⣿⣟⡀⡀⡀⡀⡀⡀⡀⡀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⡦⣤⣤⣀⣀⣀⣀⡀⡀⣀⣤⣾⠟⡀⡀⡀⢠⣿⣿⣿⣿⣧⡏⡀⣼⡇⠳⢀⡀⡀⡀⡀⡀⡀⠈⠐⠄⡀⡰⡀⡀⡀⡀⡀⡀⡀⠹
⠙⣌⠢⡀⠙⣼⣼⣼⣿⣿⡀⡀⡀⡀⡀⡀⡀⡀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠽⣰⠿⣿⣿⣿⣿⣿⣿⣿⣿⠋⡀⡀⡀⡀⣀⠿⣛⣋⠉⠉⢛⠿⠿⣿⣇⣤⠁⡀⡀⡀⡀⡀⡀⡀⡀⡀⡴⡀⡀⡀⠈⡀⡀⠂⡀⡀
⡀⡀⠳⡈⠦⡰⠻⣿⣿⡯⡀⡀⡇⡀⡀⡀⡀⡀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⢰⡀⡀⠉⠁⠛⠻⠻⠟⠁⡀⡀⡀⡀⡀⢸⡀⡀⡀⢀⠈⠳⣸⡀⠈⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⢰⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀
⡀⡀⡀⠈⢦⡉⠦⡀⡿⠿⡀⡀⣧⡀⡀⡀⡀⡀⢸⣿⣿⣿⣿⣿⣿⣿⣿⠿⣿⣿⣦⡀⠇⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠨⣄⡀⡀⡀⡀⡀⢹⡀⡀⡀⡀⡆⡀⡀⡀⡀⡀⡀⡀⡀⢠⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀
⡀⡀⡀⡀⣰⣿⣤⠈⡇⡀⢠⡀⡿⡀⡀⡀⡀⡀⢸⣿⣿⣿⣿⣿⡿⠋⡀⠁⡀⡀⠉⠋⢷⣤⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⣀⠊⠉⠒⢄⡆⡀⣾⣷⣤⣀⡀⠁⡀⡀⡀⡀⡀⡀⡀⡀⠃⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀
⡀⡀⡀⢰⣿⣿⣿⣿⡀⡀⢸⡀⡗⡀⡀⡀⡀⡀⢸⣿⣿⣿⠟⠁⡀⢠⡀⡀⡀⡀⡀⠃⡀⠈⠉⠛⠓⠒⠒⠤⣤⣄⡀⡀⡀⢀⣿⠃⡀⡀⢀⣠⠤⠿⠿⠿⠿⠓⡛⠐⡀⡀⡀⡀⡀⡀⡀⡼⡀⡀⡀⡀⡀⣀⠴⠶⠶⡀⡀⡀
⡀⡀⢀⢣⣿⣿⣿⣿⡀⡀⢸⡀⡗⡄⡀⡀⡀⡀⢸⣿⣹⡀⡂⡀⡀⡀⡀⡀⡀⡀⡸⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠙⠿⠐⠊⡀⠁⡀⡀⡴⠁⢀⠈⡄⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⢀⠴⠉⡀⡀⡀⢀⡀⡀⡀
⡀⡀⠈⣏⢿⣿⣿⡇⡀⡀⣿⡀⡯⣇⡀⡀⡀⡀⢸⣧⢀⡦⡁⡀⠂⡀⢢⡀⡀⡀⠁⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⢀⠏⡀⠐⠂⡀⣧⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠞⡀⡀⡀⠞⠁⡀⡀⡀⢠⠊⡀⡀⡀⡀
⡀⡀⣳⣷⣝⣝⣿⢁⡀⡀⢹⡀⡯⣻⡀⡀⡀⡀⢸⣿⠋⡀⠈⢶⡁⠠⠠⠕⢄⡜⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡖⠁⡀⣥⡀⡀⡀⣤⣤⡤⣤⣭⣁⠇⡀⡀⡀⡀⠉⡀⡀⡀⡼⡀⠂⡀⠂⡔⡀⡀⡀⡀⡀⡀
⡀⢠⢻⣿⣿⣮⣾⡸⡀⡀⣸⡀⣇⡆⡀⡀⡀⡀⣀⠻⣄⡀⡀⢀⡋⠠⢘⡆⢃⢲⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡇⡀⢀⡀⠈⢤⣿⣿⠟⡠⡏⢢⣿⣹⠠⡀⡀⠈⠠⠠⠄⡀⡇⡀⠐⢐⢀⡀⡀⡀⡀⡀⡀⡀
⡀⠇⠈⣿⣿⣿⡿⡇⡀⡆⣿⠄⣿⡁⡇⡀⡀⡀⢠⠙⢄⠳⣀⠛⣿⣿⣶⡼⠳⣌⠩⢦⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⡀⠈⢤⡀⡀⡀⡀⣿⠏⠔⢀⢀⣿⡿⡁⠁⠂⠈⢄⢀⡀⡀⡀⣧⢀⡬⠴⢒⠒⠶⠤⡀⡀⡀⡀
⢰⡀⡀⣿⣿⣿⡇⡀⡀⢁⣿⡇⣟⣇⣺⡀⡀⢰⢸⣿⣤⠉⠦⡛⣄⠙⠋⢠⡀⡀⠻⣶⣦⣭⣂⡠⠄⡀⡀⡀⡀⡀⡀⡀⡀⡀⡠⠁⠳⡀⡀⢠⢃⠎⢀⡟⣿⠟⢠⡀⠐⠐⠕⡀⡄⡀⠠⣠⣛⢀⢠⡀⡀⡀⡀⡀⡀⡀⡀⡀
⠃⡀⡀⣿⣿⣿⢸⡀⢸⣼⣾⡇⣯⢜⢸⡀⡀⠐⠈⣿⣆⣿⣄⠈⠲⡙⢶⣊⡀⡀⣼⢿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣬⣬⣤⣤⣥⡼⠩⢉⠓⡶⣡⠁⢀⠟⠟⡿⡀⡀⡀⡓⣄⡀⣠⣷⣿⠋⡀⢐⢐⠁⡀⡀⡀⡀⡀⡀⡀⣠⣿
⡀⡀⡀⣿⣿⣿⣼⡀⡏⣿⣌⡇⡷⣻⡩⡇⡀⡀⡀⣿⣿⡘⣿⣷⣄⠢⢱⢌⠻⣤⠙⢿⣿⡏⠓⢦⣉⠉⠛⠛⠿⠿⣿⣿⣿⣿⡀⡀⢀⠞⡰⠄⣠⠏⠚⣸⡆⡀⡀⠚⠋⠉⠉⠛⠿⣤⡈⠃⢃⠋⡀⣀⣠⣤⣶⣶⣿⣿⣿⣿
⡀⣶⣶⣿⣿⣿⣿⢀⢁⣿⣿⡇⡟⢣⠅⣿⡀⡀⡆⣿⣿⣿⠹⣿⣿⡷⣉⠉⠙⢦⠉⠶⣄⡀⡀⡀⡀⣹⣿⣿⣶⣶⣦⣤⣤⣿⡀⣴⢋⠞⡀⡴⠁⣴⡄⣿⣿⡀⡀⡀⡀⡀⡀⠈⠓⡆⠈⣍⣉⣉⣉⣉⣉⣉⣉⣉⣉⣉⣉⣉
⡀⣿⢦⡙⣿⡇⣿⣸⢸⣿⡿⢸⣟⡺⢻⢺⡀⡀⡇⣿⣿⣿⣷⢻⣿⡇⠂⠙⢦⡈⠪⠲⣄⠙⢦⣀⡀⣿⣿⣿⣿⠋⡀⠉⠛⢁⡞⣠⡁⣠⠟⢀⣾⣿⠃⣿⣿⡏⣄⣀⣀⣀⣀⣀⣀⠹⡀⡿⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⡀⣏⢗⢏⠄⡇⡇⣿⣿⡟⣾⢸⢹⣷⣕⡲⣧⡀⣿⢹⣿⣿⣿⣧⢻⡜⠠⣷⣄⠈⠷⣈⠂⡙⢦⡀⠙⢦⡙⣿⡁⡀⡀⡀⣨⠋⡴⡀⡴⢁⢠⣿⡿⠁⢀⣿⣿⢰⣿⣿⣿⣿⣿⣿⣷⡈⣉⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
*/
// Sieve of Eratosthenes to find primes up to n
vector<bool> sieve(int n) {
    vector<bool> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i*i <= n; i++) {
        if(is_prime[i]) {
            for(int j = i*i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return is_prime;
}

// Function to calculate GCD (HCF)

bool canFormPalindrome(int n, int k, string s) {
    // Check if n-k is 1
    if (n - k == 1) {
        return true;
    }

    // Check if n-k is even
    if ((n - k) % 2 == 0) {
        map<char, int> charCount;
        for (char c : s) {
            charCount[c]++;
        }

        int oddCount = 0;
        for (auto& pair : charCount) {
            if (pair.second % 2 != 0) {
                oddCount++;
            }
        }

        return oddCount == k;
    } else {
        map<char, int> charCount;
        for (char c : s) {
            charCount[c]++;
        }

        int oddCount = 0;
        int evenCount = 0;
        for (auto& pair : charCount) {
            if (pair.second % 2 != 0) {
                oddCount++;
            } else {
                evenCount += pair.second / 2;
            }
        }

        return oddCount <= 1 && evenCount >= k - oddCount;
    }
}
const int MOD = 1e9 + 7;
const int MAX_N = 100000;
const int MAX = 1000000;
int powm(int x,int n){
    //to calculate 2 to the power
    x%=MOD;
    if(n==0){
        return 1;
    }
    else if(n==1){
        return x;
    }
    int p = powm(x*x,n/2);
    if(n%2){
        return p*x%MOD;
    }
    else{
        return p;
    }
}
int largest_power_of_2(int n) {
    int power = 1;
    // Loop to find the largest power of 2 less than or equal to n
    while (power <= n) {
        power *= 2;
    }
    // The last valid power of 2 will be half of the current power
    return power / 2;
}
int mx2(int k){
    int x = log2(k);
    return pow(2,x);

}
bool canAliceWin(int n, const string& s) {
    // Base case: If the string is empty or only contains one character,
    // return true if it's '1', false otherwise.
    if (s.length() <= 1) {
        return s == "1";
    }

    // Try all possible ways to split the string into two parts.
    for (size_t i = 1; i < s.length(); ++i) {
        string left = s.substr(0, i);
        string right = s.substr(i);

        // Recursively check if Alice can win with the left or right part.
        if (canAliceWin(n - 1, left) || canAliceWin(n - 1, right)) {
            return true;
        }

        // If Alice can't win with either part, check combining them with 'AND' or 'OR'.
        if ((left == "1" && right == "1") || 
            (left == "0" && right == "1") || 
            (left == "1" && right == "0")) {
            return true;
        }
    }

    // If none of the above conditions are met, Alice can't win.
    return false;
}
int count_good_subsegments(int n, int m, const vector<pair<int, int>>& bad_pairs) {
    // Store bad pairs in a set for quick lookup
    set<pair<int, int>> bad_pairs_set(bad_pairs.begin(), bad_pairs.end());
    
    int good_count = 0;
    int start = 1; // Start of the segment

    // Use two pointers to find valid subarrays
    for (int end = 1; end <= n; ++end) {
        // Check if the current end creates a bad pair with any previous friend
        while (start < end && (bad_pairs_set.count({start, end}) || bad_pairs_set.count({end, start}))) {
            start++; // Move the start pointer to the right
        }
        
        // Count all valid subarrays ending at `end`
        good_count += (end - start + 1);
    }

    return good_count;
}
int helper(vector<int>&a,int l,int r,int k){
    int sum =0;
    for(int i=l-1;i<r;i++){
        a[i]=k;
    }
    for(int i=0;i<a.size();i++){
        sum += a[i];
    }
    return sum;
}



bool check(vector<int>&a){
    int n = a.size();
    if(a[0]==a[n-1]){
        return true;
    }
    return false;
}

void solve() {
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    int cnt1=0,cnt0=0;
    for(int i=0;i<n;i++){
        if(s[i]=='0')cnt0++;
        else cnt1++;

    }
    for(int i=0;i<n-1;i++){
        if(cnt1==0||cnt0==0){
            cout<<"NO"<<endl;
            return;
        }
        if(t[i]=='0')cnt1--;
        else cnt0--;
    }
    cout<<"YES"<<endl;
        
}
bool check(int cnt0,int cnt1){
    if(cnt0==0||cnt1==0){
        return true;
    }
    return false;
}


bool ispos(vector<int>&a,int h,int x){
    int sum =0;
    int n = a.size();
    for(int i=0;i<n;i++){
        if(h>a[i]){
            sum +=h-a[i];
        }
    }
    if(sum<=x){
        return true;
    }
    else return false;
}
int gcd(int a, int b) {
    while (b != 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

void ssolve() {
        int n;
        cin>>n;
        vector<vector<int>>v(n,vector<int>(n));
        vector<int>arr;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin>>v[i][j];
            }
            arr.pb(0);
            while(v[i].size()&&v[i].back()==1){
                arr.back()++;
                v[i].pop_back();
            }
        }
        sort(arr.begin(),arr.end());
        int cnt =0;
        int i=0;
        while(i<n){
            i = lower_bound(arr.begin()+i,arr.end(),cnt+1)-arr.begin();
            if(i==n){
                cout<<min(n,cnt+1)<<endl;
                return;
            }
            cnt++;
            i++;
        }
        cout<<min(n,cnt+1)<<endl;
}   


//converting to bits
int msb(int n){
    for(int i=32;i>=0;i--){
        if(n&(1ll<<i)){
            return i;
        }
    }
    return 0;
}

int maxpow2(int n){
    int ans = 1;
    while(ans<=n){
        ans = ans*2;
    }
    return ans/2;
}
int binarys(int l,int h,vector<int>&a,int i){
    if(l<=h){
        int m = (l+h)/2;
        if(a[m]>=(i-m+1)){
            if(m==l){
                return m;
            }
            else{
                if(a[m-1]>=(i-(m-1)+1)){
                    return binarys(l,m-1,a,i);
                }
            }
        }
        else{
           return binarys(m+1,h,a,i);
        }
    }
    else{
        return -1;
    }
}

int32_t main() {
    int t;
    cin>>t;
    while(t--){
       int n;
       cin>>n;
       vector<int>a(n);
       for(int i=0;i<n;i++){
        cin>>a[i];
       }
       if(n==2){
        if(a[0]>a[1]){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
        }
       }
       else{
        bool flag = true;

       for(int i=0;i<n-2;i=i+2){
        if(a[i]>a[i+1]){
            flag = false;
            break;
        }
        else if(a[i]<=a[i+1]){
            if(a[i+1]-a[i]<=a[i+2]){
                continue;
            }
            else{
                flag = false;
                break;
            }
        }
       }
       if(flag){
        cout<<"YES"<<endl;
       }
       else{
        cout<<"NO"<<endl;
       }
       }
       
    }
    return 0;
}    
      
    






    
    

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;

#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define wh while(t--)
#define fr(n) for(int i=0; i<n; i++)
#define int long long
#define pb push_back
#define sort(v) sort(v.begin(), v.end())

int32_t main(){
   ios
   int t;
   cin>>t;
   while(t--){
    int n;
    cin>>n;
    vector<int>a(n);
    // vector<int>ans(n);
    fr(n){
        cin>>a[i];
    }int flg=1;
    for(int i=1;i<n;i++){
      int  mini= min(a[i-1],a[i]);
      a[i-1]=a[i-1]-mini;
      a[i]=a[i]-mini;
      if(a[i-1]>a[i]){
        cout<<"NO"<<endl;
       flg=0;
       break;
      }
    }
    if(flg){
        bool fl=true;
        for(int i=0;i<n-1;i++){
            if(a[i]>a[i+1]){
                
                fl=false;
                break;
            }
        }
        if(fl)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
   }
   return 0;
}