//
// Strategy:
//   Every problem can be skipped or assigned to one of the 3 teammates.
//   There are 4^10 (~1mil) posible assignments: we try them all
//

#include <stdio.h>
#include <stdlib.h>

int team[11][4];	// Time needed for the problems for eact teammate
int times[3];		// Puzzeling time left for individual teammates

int best(int n, int problems)
{
	int mx = 0;

	if(n==problems)
		return 0;
	
	for(int i=0; i<4; i++)
	{
		int t = 0;

		if(i==3)							// Skip problem n
			t = 0 + best(n+1, problems);
		else if((team[n][i]>=0) && (team[n][i]<=times[i]))	
										// Teammate i can solve this problem in 
										// the remaining time
		{
			times[i] -= team[n][i];
		
			t = 1 + best(n+1, problems);
			
			times[i] += team[n][i];
		}

		if(t > mx)
			mx = t;	
	}
	
	return mx;
}

void run()
{
	int probs, time;
	scanf("%d %d", &probs, &time);
	
	for(int i=0; i<3; i++)
		for(int j=0; j<probs; j++)
			scanf("%d", &team[j][i]);
			
	times[0] = times[1] = times[2] = time;
	
	printf("%d\n", best(0, probs));
}

int main()
{
	int runs;
	scanf("%d", &runs);
	
	while(runs--)
		run();
		
	system("pause");
}
