#include <bits/stdc++.h>
using namespace std;
#define Samurai ios_base::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL);
int main(){ Samurai
int _t = 1;
cin >> _t;
for (int i = 1; i <= _t; i++){
int n; cin >> n;
int arr[n];
long long avg = 0;
for(int i=0; i<n; i++){
cin >> arr[i];
avg += arr[i];
}
if(avg%n != 0){
cout << "NO\n";
}
else{
avg/=n;
for(int i=1; i<n-1; i++){
if(arr[i-1] < avg){
arr[i+1] -= (avg - arr[i-1]);
arr[i-1] = avg;
}
else if(arr[i-1] > avg){
arr[i+1] += (arr[i-1] - avg);
arr[i-1] = avg;
}
}
bool ok = true;
for(int i=0; i<n-1; i++){
if(arr[i] != arr[i+1]){
ok = false;
cout << "NO\n";
break;
}
}
if(ok) cout << "YES\n";
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgU2FtdXJhaSBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKSwgY291dC50aWUoTlVMTCksIGNpbi50aWUoTlVMTCk7CgppbnQgbWFpbigpeyBTYW11cmFpCiAgICBpbnQgX3QgPSAxOwogICAgY2luID4+IF90OwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gX3Q7IGkrKyl7CiAgICAgICAgaW50IG47IGNpbiA+PiBuOwogICAgICAgIGludCBhcnJbbl07CiAgICAgICAgbG9uZyBsb25nIGF2ZyA9IDA7CiAgICAgICAgZm9yKGludCBpPTA7IGk8bjsgaSsrKXsKICAgICAgICAgICAgY2luID4+IGFycltpXTsKICAgICAgICAgICAgYXZnICs9IGFycltpXTsKICAgICAgICB9CiAgICAgICAgaWYoYXZnJW4gIT0gMCl7CiAgICAgICAgICAgIGNvdXQgPDwgIk5PXG4iOwogICAgICAgIH0KICAgICAgICBlbHNlewogICAgICAgICAgICBhdmcvPW47CiAgICAgICAgICAgIGZvcihpbnQgaT0xOyBpPG4tMTsgaSsrKXsKICAgICAgICAgICAgICAgIGlmKGFycltpLTFdIDwgYXZnKXsKICAgICAgICAgICAgICAgICAgICBhcnJbaSsxXSAtPSAoYXZnIC0gYXJyW2ktMV0pOwogICAgICAgICAgICAgICAgICAgIGFycltpLTFdID0gYXZnOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZWxzZSBpZihhcnJbaS0xXSA+IGF2Zyl7CiAgICAgICAgICAgICAgICAgICAgYXJyW2krMV0gKz0gKGFycltpLTFdIC0gYXZnKTsKICAgICAgICAgICAgICAgICAgICBhcnJbaS0xXSA9IGF2ZzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBib29sIG9rID0gdHJ1ZTsKICAgICAgICAgICAgZm9yKGludCBpPTA7IGk8bi0xOyBpKyspewogICAgICAgICAgICAgICAgaWYoYXJyW2ldICE9IGFycltpKzFdKXsKICAgICAgICAgICAgICAgICAgICBvayA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgIGNvdXQgPDwgIk5PXG4iOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKG9rKSBjb3V0IDw8ICJZRVNcbiI7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0KCg==