//teja349 #include #include #include #include #include #include #include #include #include #include #include #include #include #include //setbase - cout << setbase (16); cout << 100 << endl; Prints 64 //setfill - cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77 //setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx //cout.precision(x) cout<=b;i--) #define pb push_back #define mp make_pair #define vi vector< int > #define vl vector< ll > #define ss second #define ff first #define ll long long #define pii pair< int,int > #define pll pair< ll,ll > #define sz(a) a.size() #define inf (1000*1000*1000+5) #define all(a) a.begin(),a.end() #define tri pair #define vii vector #define vll vector #define viii vector #define mod (1000*1000*1000+7) #define pqueue priority_queue< int > #define pdqueue priority_queue< int,vi ,greater< int > > #define flush fflush(stdout) #define primeDEN 727999983 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int a[1234567],b[1234567]; int visit[1234567]; int main(){ //std::ios::sync_with_stdio(false); cin.tie(NULL); int t; cin>>t; while(t--){ int n; int i,j; int ans=0; scanf("%d",&n); rep(i,n){ scanf("%d",&a[i]); b[a[i]]++; visit[a[i]]=0; } rep(i,n){ if(visit[a[i]]) continue; visit[a[i]]=1; f(j,1,min(a[i],b[a[i]])+1){ if(b[j]>=a[i]){ ans++; if(j!=a[i]){ ans++; } } } } rep(i,n){ b[a[i]]=0; } printf("%d\n",ans); } return 0; }