#include<algorithm> #include<iostream> #include<cstring> #define ll long long constint N = 200005; int a[N], c[N];
usingnamespace std;
intmain() { int T; cin >> T; while (T--) { ll sum = 0; memset(c,0,sizeof(c)); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum+=a[i]; }
int mx = 0; for(int i = 1; i <= n; i ++) { if (++c[a[i]]>=2) mx=max(mx,a[i]); a[i]=mx; sum+=a[i]; } memset(c,0,sizeof(c)); mx = 0; for(int i = 1; i <= n; i ++) { if (++c[a[i]]>=2) mx=max(mx,a[i]); a[i]=mx; sum += 1LL * a[i] * (n-i + 1); //累加 } cout << sum << endl; } }