// Arup Guha
// 4/25/2017
// Solution to COP 3502 Final Exam Questions 3 - 7

#include <stdio.h>

#define MAXVENDORS 20

void readVendors(int set[],int cost[], int n);
int sumCost(int cost[], int n, int bitmask);
int setBought(int set[], int n, int bitmask);
int bitCount(int n);
int bitCountAlt(int n);
int solve(int set[], int cost[], int n, int budget);

int main() {

    int loop, numCases;

    scanf("%d", &numCases);

    // Process each case.
    for (loop=0; loop<numCases; loop++) {

        int n, budget;
        int set[MAXVENDORS];
        int cost[MAXVENDORS];

        // Just get the # of vendors and your budget.
        scanf("%d%d", &n, &budget);

        // Read in the information about each vendor.
        readVendors(set, cost, n);

        printf("%d\n", solve(set, cost, n, budget));
    }
}

void readVendors(int set[],int cost[], int n) {

    int i;

    // Go through each vendor.
    for (i=0; i<n; i++) {

        int numF, bit, j;

        // Initialize our set to contain nothing.
        set[i] = 0;

        scanf("%d", &numF);
        for (j=0; j<numF; j++) {
            scanf("%d", &bit);
            set[i] |= (1<<bit);
        }

        // The cost is last.
        scanf("%d", &cost[i]);
    }
}

int sumCost(int cost[], int n, int bitmask) {
    int res = 0, i;

    // Try each bit in the bitmask
    for (i=0; i<n; i++)

        // Add the cost in only if bit i is on in the mask.
        if ((bitmask &(1<<i)) != 0)
            res += cost[i];
    return res;
}

int setBought(int set[], int n, int bitmask) {
    int res = 0, i;

    // Try each bit in the bitmask
    for (i=0; i<n; i++)

        // Add the cost in only if bit i is on in the mask.
        if ((bitmask &(1<<i)) != 0)
            res |= set[i];
    return res;
}

int bitCount(int n) {
    int i, res = 0;
    while (n > 0) {
        res += (n&1);
        n >>= 1;
    }
    return res;
}

int bitCountAlt(int n) {
    int i, res = 0;
    for (i=0; i<32; i++)
        if ((n &(1<<i)) != 0)
        res++;
    return res;
}

int solve(int set[], int cost[], int n, int budget) {

    int best = 0, i;
    for (i=1; i<(1<<n); i++) {
        int mycost = sumCost(cost, n, i);
        if (mycost <= budget) {
            int numFigurines = bitCount(setBought(set,n,i));
            if (numFigurines > best)
                best = numFigurines;
        }
    }
    return best;
}
