/*
  [BAPC'07] CONTEST
  by: Jan Kuipers
*/

using namespace std;

#include <iostream>
#include <vector>

int N,T,now,res;
vector<int> l;
vector<vector<int> > t;

void go (int n) {
  if (n==N) { if (now>res) res=now; return; }

  for (int i=0; i<4; i++) {
    if (i<3 && (t[i][n]==-1 || l[i]<t[i][n])) continue;
    if (i<3) l[i]-=t[i][n], now++;
    go(n+1);
    if (i<3) l[i]+=t[i][n], now--;
  }
}

int main () {

  int runs;
  cin>>runs;
  while (runs--) {

    cin>>N>>T;
    l=vector<int>(3,T);
    t=vector<vector<int> >(3,vector<int>(N));
    for (int i=0; i<3; i++)
      for (int j=0; j<N; j++) cin>>t[i][j];

    now=res=0;
    go(0);
    cout<<res<<endl;
  }

  return 0;
}
