#include<iostream>
using namespace std;
int T,N;
int main()
{
int time[1001],score[1001],punish;
cin>>T;
while(T--)
{
cin>>N;
int sign[300]= {0};
punish=0;
//输入时间顺序
for(int i=1; i<=N; i++)
cin>>time[i];
//输入相应的分数
for(int i=1; i<=N; i++)
cin>>score[i];
//按照分数降序排列,且对应的时间随分数变化
for(int i=0; i<N-1; i++)
{
for(int j=1; j<N-i; j++)
{
int tempt,temps;
if(score[j]<score[j+1])
{
temps=score[j];
score[j]=score[j+1];
score[j+1]=temps;
tempt=time[j];
time[j]=time[j+1];
time[j+1]=tempt;
}
}
}
//进行选择
for(int i=1; i<=N; i++)
{
punish+=score[i];//choice the big score
for(int j=time[i]; j>0; j--)
{
if(sign[j]==0)//从截止日期开始往前推,直到有空余的时间.
{
sign[j]=1;
punish-=score[i];
break;
}
}
}
cout<<punish<<endl;
}
return 0;
}
using namespace std;
int T,N;
int main()
{
int time[1001],score[1001],punish;
cin>>T;
while(T--)
{
cin>>N;
int sign[300]= {0};
punish=0;
//输入时间顺序
for(int i=1; i<=N; i++)
cin>>time[i];
//输入相应的分数
for(int i=1; i<=N; i++)
cin>>score[i];
//按照分数降序排列,且对应的时间随分数变化
for(int i=0; i<N-1; i++)
{
for(int j=1; j<N-i; j++)
{
int tempt,temps;
if(score[j]<score[j+1])
{
temps=score[j];
score[j]=score[j+1];
score[j+1]=temps;
tempt=time[j];
time[j]=time[j+1];
time[j+1]=tempt;
}
}
}
//进行选择
for(int i=1; i<=N; i++)
{
punish+=score[i];//choice the big score
for(int j=time[i]; j>0; j--)
{
if(sign[j]==0)//从截止日期开始往前推,直到有空余的时间.
{
sign[j]=1;
punish-=score[i];
break;
}
}
}
cout<<punish<<endl;
}
return 0;
}