#include<bits/stdc++.h>
using namespace std;
struct network_flow{
int max_v,e,s,t,head,tail;
int *cap,*to,*next,*last,*dist,*q,*now;
network_flow(){}
network_flow(int v, int max_e){
max_v = v; e = 0;
cap = new int[2*max_e], to = new int[2*max_e], next = new int[2*max_e];
last = new int[max_v], q = new int[max_v], dist = new int[max_v], now = new int[max_v];
fill(last,last+max_v,-1);
}
void clear(){
fill(last,last+max_v,-1);
e = 0;
}
void add_edge(int u, int v, int uv, int vu = 0){
to[e] = v, cap[e] = uv, next[e] = last[u]; last[u] = e++;
to[e] = u, cap[e] = vu, next[e] = last[v]; last[v] = e++;
}
bool bfs(){
fill(dist,dist+max_v,-1);
head = tail = 0;
q[tail] = t; ++tail;
dist[t] = 0;
while(head<tail){
int v = q[head]; ++head;
for(int er = last[v];er!=-1;er = next[er]){
if(cap[er^1]>0 && dist[to[er]]==-1){
q[tail] = to[er]; ++tail;
dist[to[er]] = dist[v]+1;
}
}
}
return dist[s]!=-1;
}
int dfs(int v, int f){
if(v==t) return f;
for(int &er = now[v];er!=-1;er = next[er]){
if(cap[er]>0 && dist[to[er]]==dist[v]-1){
int ret = dfs(to[er],min(f,cap[er]));
if(ret>0){
cap[er] -= ret;
cap[er^1] += ret;
return ret;
}
}
}
return 0;
}
long max_flow(int source, int sink){
s = source; t = sink;
long int f = 0,x;
while(bfs()){
for(int i = 0;i<max_v;++i) now[i] = last[i];
while(true){
x = dfs(s,INT_MAX);
if(x==0) break;
f += x;
}
}
return f;
}
}graph(402,200*200+400+2);
int main() {
int t, v,n,x,l,m;
scanf("%d",&t);
while(t--) {
scanf("%d %d %d",&l,&m,&n);
graph.clear();
for(int i=1;i<=m;i++) {
scanf("%d",&x);
graph.add_edge(0,i,x);
}
for(int i=1;i<=n;i++) {
scanf("%d",&x);
graph.add_edge(m+i,m+n+1,x);
}
for(int i=1;i<=m;i++) {
for(int j=1;j<=n;j++) {
scanf("%d",&x);
graph.add_edge(i,j+m,x);
}
}
printf("%ld\n",graph.max_flow(0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