#include <iostream>
#include <vector>
#include <limits>
#include <string>

using namespace std;

/* For debug only: assertion macro for verifying input data */
#define ASSERT(e) { if(!(e)) throw #e; }

/* A graph edge points to another graph node and has an associated cost */
class edge;
class node {
public:
    node() : num(-1), visited(false) {}

    int num;            /* Room number */
    bool visited;       /* True if visited during depth first search */
    vector<edge> edges; /* List of outgoing doors from this room */
};

/* A graph node has a flow capacity and a list of outgoing edges */
class edge {
public:
    edge(bool cp, node *r) : panel(cp), locked(false), room(r) {}

    bool panel;   /* True if this side of the door has a control panel */
    bool locked;  /* True if this door has been locked */
    node *room;   /* Pointer to room on the other side of this door */
};

/* The current data set encoded into graph form */
vector<node> house;

/* Panic room number */
int panic_num;

/*
 * Parse one input data set into graph format and store in global "house"
 * variable. Each door is represented in the graph as a pair of directed edges
 * between two rooms, with one edge marked as having the control panel.
 * 
 * This function also adds a special "master intruder" room which has doors
 * with control panels leading from it to all other rooms in which an intruder
 * starts. Consolidating the individual intruders like this makes the
 * underlaying maximum network flow problem easier.
 *
 * The panic room number is stored in the global "panic_num".
 */
void parse_input(void)
{
    vector<node *> intruders; 
    int room_num;

    /* Clear out any previous data set */
    house.clear();

    /* Get the total room count and the panic room number */
    cin >> room_num >> panic_num;
    ASSERT(room_num >= 1 && room_num <= 20);
    ASSERT(panic_num >= 0 && panic_num < room_num);
    
    /* Preallocate all graph nodes; the +1 is for the intruder node */
    house.resize(room_num + 1);
    
    /* Iterate over all rooms in data set */
    for(int room = 0; room < room_num; room++) {
        int door_num;
    
        /* Assign room number to graph node */
        house[room].num = room;

        /* Keep track of rooms with intruders in them */
        string s;
        cin >> s;
        ASSERT(s == "I" || s == "NI");
        if(s == "I") {
            intruders.push_back(&house[room]);
        }
        
        /* Read in the door count */
        cin >> door_num;
        ASSERT(door_num >= 0 && door_num <= 20);
        
        /* Create directed edges between rooms connected by a door */
        for(int door_idx = 0; door_idx < door_num; door_idx++) {
            int num;
            
            cin >> num;
            ASSERT(num >= 0 && num < room_num);
            house[room].edges.push_back( edge(true, &house[num]) );
            house[num].edges.push_back( edge(false, &house[room]) );
        }
    }
    
    /* Add a "master intruder" node that points to all other intruders */
    house[room_num].num = -1;
    for(int i = 0; i < intruders.size(); i++) {
        house[room_num].edges.push_back( edge(-1, intruders[i]) );
    }
}

/*
 * Recursively perform a depth first search starting at "room" and trying to
 * reach the panic room.
 *
 * Returns -1 if the panic room can be reached by moving only through
 * unlockable doors (i.e. the control panels are always on the intruders side).
 *
 * Returns 1 if the path to the panic room passed through at least one lockable
 * door. In that case, all the locable doors on this path are permanently
 * locked so this path cannot be considered again.
 *
 * Returns 0 if the panic room cannot be reached at all because all the doors
 * on the path are locked (and the control panel is on the other side) or
 * there are no doors at all between "room" and the panic room.
 */
int search(node *room)
{
    vector<edge>::iterator door;

    /* Finish the current path if the panic room is reached */
    if(room->num == panic_num) {
        return -1;
    }
    
    /* Mark this room as visited to avoid cycles in the depth first search */
    room->visited = true;

    /* Explore all edges (i.e. doors) leading out of this room */
    for(door = room->edges.begin(); door < room->edges.end(); ++door) {

        /*
         * Only explore rooms not already visited on the current path and
         * only go through doors with a CP or doors not yet locked.
         */
        if(!door->room->visited && (door->panel || !door->locked)) {
        
            /* Recursively explore the next room in depth first order */
            int rc = search(door->room);
            
            /* If this door lead to the panic room, back out of current path */
            if(rc) {
            
                /*
                 * If this door has no CP, lock it and return 1 since at least
                 * one door on this path would have to be locked to keep the
                 * intruder out.
                 */
                if(!door->panel) {
                    door->locked = true;
                    rc = 1;
                }
                
                /* Return cost of reaching panic room on this path */
                return rc;
            }
        }
    }
    
    /* Ignore this path since it never reached the panic room */
    return 0;
}

/*
 * Compute the maximum network flow between the "master intruder" node and the
 * panic room. Each door the intruder must pass through which has a control
 * panel on the other side is treated as an edge with flow capacity of 1. Any
 * doors where the intruder has access to the control panel are treated as
 * edges with infinite flow capacity.
 *
 * The total number of doors to be locked exactly equals the max network flow
 * between the "master intruder" node and the panic room. In other words, this
 * is the minimum cut necessary in the graph to disconnect the panic room
 * from the intruder.
 *
 * This uses the Ford-Fulkerson algorithm which repeatetly searches for a
 * flow augmenting path between the two nodes. When no more such paths can be
 * found, then the maximum network flow has been computed.
 */
int maxflow(void)
{
    int rc, count = 0;

    /* The "master intruder" is always the last room added by parse_input() */
    node *master = &house[house.size() - 1];
    
    /*
     * Keep exploring paths to panic room until either all the doors have
     * been locked or the panic room can be reached by doors that cannot be
     * locked (i.e. the control panels are always facing the intruders)
     */
    do {
        /* Reset visited flags for depth first search */
        for(int i = 0; i < house.size(); i++) {
            house[i].visited = false;
        }
    
        rc = search(master);
        
        if(rc == -1) {
            count = -1;
        }
        else {
            count += rc;
        }
        
    } while(rc > 0);
    
    /* Return max network flow or -1 if there is a panic room breach */
    return count;
}

#ifdef DEBUG
/*
 * Print out the graph stored in "house" using the Graphiviz language. This
 * data can be fed into the "dot" program to produce a visual graph layout.
 */
void print_graph(void)
{
    vector<node>::iterator room;
    vector<edge>::iterator door;

    cerr << "digraph G {" << endl;

    /* Loop over every room (node) in the graph */
    for(room = house.begin(); room < house.end(); ++room) {    
        cerr << room->num;
        cerr << (panic_num == room->num ? " [shape=box];" : ";") << endl;
        
        /* Loop over every door (edge) in this room */ 
        for(door = room->edges.begin(); door < room->edges.end(); ++door) {
            cerr << room->num << " -> " << door->room->num;
            cerr << (door->panel ? " [style=bold];" : ";") << endl;
        }
    }
    
    cerr << "}" << endl;
}
#endif

/* Main body of program */
void process(void)
{
    int data_num, data_idx;
    
    /* Read how many data sets are to be processed */
    cin >> data_num;

    /* Process each puzzle separately */
    for(data_idx = 0; data_idx < data_num; data_idx++) {
    
        /* Create a graph from the input data set */
        parse_input();
#ifdef DEBUG
        print_graph();
#endif
        
        /* Compute maximum network flow in graph */
        int cost = maxflow();

        /* Total flow reaching the panic room is the number of doors to lock */
        if(cost == -1) {
            cout << "PANIC ROOM BREACH" << endl;
        }
        else {
            cout << cost << endl;
        }
    }
}    

/* Run program and print out any exceptions that occur */
int main(void)
{
    /* Throw exceptions on EOF or failed data extraction in >> operator */
    cin.exceptions(ios::eofbit | ios::failbit);

    /* Run main body of code */
    try {
        process();
    }
    
    /* Catch any internally generated exceptions */
    catch(char const *e) {
        cerr << "Exception: " << e << endl;
    }
    
    /* Catch unexpected EOF or bad input data */
    catch(ios::failure const &e) {
        cerr << "Unexpected EOF or data type mismatch on input" << endl;
    }

    return 0;
}