#include <map>
#include <vector>
#include <iostream>

#define IS(c,v) ((c).find(v)!=(c).end())

using namespace std;

typedef map<int,int>::iterator MI;
typedef vector<int>::iterator VI;

int N,M;

vector<int> val;                //kapacity
vector<int> price;              //

vector<int> top;                //tok
vector<map<int,int> > down;     //
vector<map<int,int> > up;       //
vector<int> bottom;             //

int augment()
{
  map<int,int> upflow;
  map<int,int> upedge;
  map<int,int> downflow;
  map<int,int> downedge;

  for(int i=0;i<M;i++)if(val[i]>top[i])         //zhora do gastracov
  {
    upflow[i]=val[i]-top[i];
    upedge[i]=-1;
  }

  for(;;)
  {
    int found=0;
    for(int i=0;i<N;i++)if(!IS(downflow,i))    //z gastracov do veci (priamy smer)
    {
      int f=0, e=-1;
      for(MI j=up[i].begin(); j!=up[i].end(); ++j)if(IS(upflow,j->first))
      {
        int ff=upflow[j->first];
        if(ff>f) {f=ff; e=j->first; }
      }
      if(f>0)
      {
        if(bottom[i]<price[i])                  // z veci dole
        {
          f=min(f,price[i]-bottom[i]);
          cerr << "#" << f << ": " << i << ".." << e;     //DEBUG
          bottom[i]+=f;
          up[i][e]+=f;
          down[e][i]+=f;
          int v=e;
          while(upedge[v]!=-1)          //pozijeme najdenu cestu
          {
            int w=upedge[v], x=downedge[w];
            cerr << " " << w << ".." << x;      //DEBUG
            down[v][w]-=f; up[w][v]-=f;
            up[w][x]+=f; down[x][w]+=f;
            v=x;
          }
          top[v]+=f;
          cerr<<endl;           //DEBUG
          return 1;
        }
        else
        {
          found=1;
          downflow[i]=f;
          downedge[i]=e;
        }
      }
    }
    if(!found) return 0;        //nenasla sa zlepsujuca cesta

    found=0;
    for(int i=0;i<M;i++)if(!IS(upflow,i))          //z veci do gastracov (spatny smer)
    {
      int f=0, e=-1;
      for(MI j=down[i].begin(); j!=down[i].end(); ++j)if(IS(downflow,j->first))
      {
        int ff=min(downflow[j->first],j->second);
        if(ff>f) {f=ff; e=j->first; }
      }
      if(f>0)
      {
        found=1;
        upflow[i]=f;
        upedge[i]=e;
      }
    }
    if(!found) return 0;        //nenasla sa zlepsujuca cesta
  }

  return 0;     //should not happen
}

void one_case()
{
  cin >> N >> M;
  
  val=vector<int>(M);
  price=vector<int>(N);
  top=vector<int>(M);
  bottom=vector<int>(N);
  up=vector<map<int,int> >(N);
  down=vector<map<int,int> >(M);

  for(int i=0;i<N;i++)
  {
    int a; cin >> a; price[i]=a; bottom[i]=0;
  }
  for(int i=0;i<M;i++)
  {
    int a; cin >> a; val[i]=a; top[i]=0;
  }
  for(int i=0;i<M;i++)
  {
    int c; cin >> c;
    for(int j=0;j<c;j++)
    {
      int k; cin >> k; k--; down[i][k]=0; up[k][i]=0;
    }
  }
  int augc=0, flow=0;  //DEBUG
  while(augment())augc++;
  int sum=0;
  for(int i=0;i<N;i++)
  {
    sum+=price[i]-bottom[i];
    flow+=bottom[i];            //DEBUG
  }
  cout<<sum<<endl;
  cerr<<"* "<<augc<<" "<<flow<<" "<<sum<<endl;  //DEBUG
  cerr<<"** flow found:"<<endl;
  for(int i=0;i<N;i++)
  {
    cerr<<i<<":";
    for(MI j=up[i].begin(); j!=up[i].end(); ++j) cerr<<" "<<j->second<<"["<<j->first<<"]";
    cerr<<endl;
  }
  cerr<<"** reverse flow:"<<endl;
  for(int i=0;i<M;i++)
  {
    cerr<<i<<":";
    for(MI j=down[i].begin(); j!=down[i].end(); ++j) cerr<<" "<<j->second<<"["<<j->first<<"]";
    cerr<<endl;
  }
}

int main()
{
  int T; cin >> T;
  while(T--)one_case();
  return 0;
}
