#include<bits/stdc++.h>
#include<math.h>
#define ll long long int
#define ull unsigned long long int
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree< ll, null_type, less<ll >, rb_tree_tag, tree_order_statistics_node_update> order_set;
#define fbo find_by_order
#define ook order_of_key
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define print(res) cout<<#res<<" = ";for(auto x:res) cout<<x<<" "; cout<<endl
#define see(res) cout<<#res<<" = "<<res<<endl
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pf push_front
#define pb push_back
#define NL printf("\n")
#define YES printf("YES\n")
#define NO printf("NO\n")
#define Yes printf("Yes\n")
#define No printf("No\n")
#define tc int tc;scanf("%d",&tc);for(int cs=1;cs<=tc;cs++)
const ll mxn=2e6+6;
const ll mod=1e9+7;
const ll N=2e5+10;
int main( )
{
tc
{
ll n ;
cin>>n ;
map<ll,ll>m1;
map<ll,ll>m2;
ll a[n+10] ;
for(ll i=1 ; i<=n ; i++)
{
cin>>a[i];
m1[a[i]]++ ;
}
ll ans = 0;
ll extra = 0 ;
ll cnt = 1;
for(ll i=n ; i>=1 ; i--)
{
if(m2[a[i]]) ++extra;
--m1[a[i]];
++m2[a[i]];
if(m1[a[i]]==0) ans+=(cnt-extra);
++cnt;
}
cout<<ans<<endl;
cout<<endl;
}
return 0;
}
//printf("Case %d: ",cs);
479C - Exams | 1030A - In Search of an Easy Problem |
158A - Next Round | 71A - Way Too Long Words |
160A - Twins | 1A - Theatre Square |
1614B - Divan and a New Project | 791A - Bear and Big Brother |
1452A - Robot Program | 344A - Magnets |
96A - Football | 702B - Powers of Two |
1036A - Function Height | 443A - Anton and Letters |
1478B - Nezzar and Lucky Number | 228A - Is your horseshoe on the other hoof |
122A - Lucky Division | 1611C - Polycarp Recovers the Permutation |
432A - Choosing Teams | 758A - Holiday Of Equality |
1650C - Weight of the System of Nested Segments | 1097A - Gennady and a Card Game |
248A - Cupboards | 1641A - Great Sequence |
1537A - Arithmetic Array | 1370A - Maximum GCD |
149A - Business trip | 34A - Reconnaissance 2 |
59A - Word | 462B - Appleman and Card Game |