#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef double db; const db pi=acos(-1); void gn(int &x){ int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c=='-')sg=-1,x=0;else x=c-'0'; while((c=getchar())>='0'&&c<='9')x=x*10+c-'0'; x*=sg; } void gn(ll &x){ int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c=='-')sg=-1,x=0;else x=c-'0'; while((c=getchar())>='0'&&c<='9')x=x*10+c-'0'; x*=sg; } const int mo=1000000007; int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;} int tes; int n,m; int a[111111],b[111111]; int check(int k){ for (int i=1;i<=k;i++)if(b[i]>a[n-k+i])return 0; return 1; } ll ax[111111],bx[111111]; int main() { scanf("%d",&tes); while(tes--){ scanf("%d%d",&n,&m); int lef=0,rig=min(n,m); for (int i=1;i<=n;i++)scanf("%d",&a[i]); for (int i=1;i<=m;i++)scanf("%d",&b[i]); sort(a+1,a+1+n); sort(b+1,b+1+m); while(lef<=rig){ int mid=lef+rig; if(check(mid))lef=mid+1; else rig=mid-1; } ax[0]=bx[0]=0; for (int i=1;i<=m;i++)bx[i]=bx[i-1]+b[i]; for (int i=1;i<=n;i++)ax[i]=ax[i-1]+a[n-i+1]; ll su=0; for (int i=1;i<=rig;i++)su=max(su,ax[i]-bx[i]); cout<