// CodeChef: Practical coding for everyone
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((int)(a).size())
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define eps 1e-12
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos(0))
#define linf (1ll << 60)
#define maxn 400005
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
void solve(int a[] , int n){
map<int,int> m; int count=0;
set<int> s1,s2;
for(int i=0;i<n;i++){
if(i == 0) continue;
if(a[i] == a[i-1]){
count++;
continue;
}
else{
m.insert({a[i-1],(count+1)});
count=0;
if(s1.find(a[i-1]) != s1.end()){
cout << "NO" << "\n";
return;
}
else{
s1.insert(a[i-1]);
}
}
}
m.insert({a[n-1],count+1});
if(s1.find(a[n-1]) != s1.end()){
cout << "NO" << "\n";
return;
}
else{
s1.insert(a[n-1]);
}
bool c[n] = {false};
for(auto pos = m.begin() ; pos!=m.end();++pos){
if(!c[pos -> second]){
c[pos -> second ] = true;
}
else{
cout << "NO" << "\n";
return;
}
}
cout << "YES" << "\n";
return;
}
int main(){
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int x; cin >> x;
while(x--){
int n; cin >> n;
int a[n];
Rep(i,n) cin >> a[i];
solve(a,n);
}
}