/***********Template Starts Here***********/
#include <bits/stdc++.h>
#define pb push_back
#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
using namespace std;
typedef long long vlong;
/***********Template Ends Here***********/
vlong arr[100010];
vlong serve[10100];
struct node {
int id;
vlong cur;
node ( int a, vlong b ) {
id = a;
cur = b;
}
};
class compare {
public:
bool operator () ( const node &a, node &b ) {
if ( a.cur < b.cur ) return false;
else if ( a.cur == b.cur && serve[a.id] < serve[b.id] ) return false;
else return true;
}
};
int main () {
int kase;
scanf ( "%d", &kase );
int cnt = 0;
while ( kase-- ) {
int n, m;
scanf ( "%d %d", &n, &m );
FOR(i,0,n-1) {
scanf ( "%lld", &arr[i] );
}
sort ( arr, arr + n, greater<vlong>() ); ///Sort in reverse order
priority_queue<node,vector<node>,compare> pq;
FOR(i,0,m-1){
scanf ( "%d", &serve[i] );
pq.push ( node(i,0) );
}
vlong res = 0;
FOR(i,0,n-1){
node temp = pq.top(); pq.pop();
vlong need = arr[i] + temp.cur;
res = MAX(res,need);
pq.push ( node ( temp.id, temp.cur + ser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IiwgJmFycltpXSApOwogICAgICAgIH0KCiAgICAgICAgc29ydCAoIGFyciwgYXJyICsgbiwgZ3JlYXRlcjx2bG9uZz4oKSApOyAvLy9Tb3J0IGluIHJldmVyc2Ugb3JkZXIKCiAgICAgICAgcHJpb3JpdHlfcXVldWU8bm9kZSx2ZWN0b3I8bm9kZT4sY29tcGFyZT4gcHE7CiAgICAgICAgRk9SKGksMCxtLTEpewogICAgICAgICAgICBzY2FuZiAoICIlZCIsICZzZXJ2ZVtpXSApOwogICAgICAgICAgICBwcS5wdXNoICggbm9kZShpLDApICk7CiAgICAgICAgfQoKICAgICAgICB2bG9uZyByZXMgPSAwOwogICAgICAgIEZPUihpLDAsbi0xKXsKICAgICAgICAgICAgbm9kZSB0ZW1wID0gcHEudG9wKCk7IHBxLnBvcCgpOwoKICAgICAgICAgICAgdmxvbmcgbmVlZCA9IGFycltpXSArIHRlbXAuY3VyOwogICAgICAgICAgICByZXMgPSBNQVgocmVzLG5lZWQpOwoKICAgICAgICAgICAgcHEucHVzaCAoIG5vZGUgKCB0ZW1wLmlkLCB0ZW1wLmN1ciArIHNlcnZlW3RlbXAuaWRdICkgKTsKICAgICAgICB9CgogICAgICAgIHByaW50ZiAoICJDYXNlICVkOiAlbGxkXG4iLCArK2NudCwgcmVzICk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K