#include <iostream>
#include <stdio.h>
#include <vector>

#define MAX 64

typedef unsigned long long ull;
using namespace std;

int main()
{
    int state[MAX] = {0};
    ull krr[MAX] = {0}, res;

    int n, k, b;
    scanf("%d", &n);
    vector<vector<int> > mask(n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &k);
        mask[i].push_back(k);
        for (int j = 0; j < k; j++)
        {
            scanf("%d", &b);
            mask[i].push_back(b);
        }
    }

    int query, commond, index, count;
    int loop, specified, j;
    scanf("%d", &query);
    for (int i = 0; i < query; i++)
    {
        scanf("%d", &commond);
        switch (commond) {
        case 0:
            scanf("%d", &index);
            printf("%d\n", state[index]);
            break;
        case 1:
            scanf("%d", &index);
            for (loop = 1; loop <= mask[index][0]; loop++)
            {
                specified = mask[index][loop];
                state[specified] = 1;
            }
            break;
        case 2:
            scanf("%d", &index);
            for (loop = 1; loop <= mask[index][0]; loop++)
            {
                specified = mask[index][loop];
                state[specified] = 0;
            }
            break;
        case 3:
            scanf("%d", &index);
            for (loop = 1; loop <= mask[index][0]; loop++)
            {
                specified = mask[index][loop];
                if (0 == state[specified])
                {
                    state[specified] = 1;
                }
                else
                {
                    state[specified] = 0;
                }
            }
            break;
        case 4:
            scanf("%d", &index);
            for (loop = 1; loop <= mask[index][0]; )
            {
                specified = mask[index][loop];
                if (1 == state[specified])
                {
                    loop++;
                }
                else
                {
                    printf("%d\n", 0);
                    break;
                }
            }

            if (loop == mask[index][0] + 1)
            {
                printf("%d\n", 1);
            }
            break;
        case 5:
            scanf("%d", &index);
            for (loop = 1; loop <= mask[index][0];)
            {
                specified = mask[index][loop];
                if (0 == state[specified])
                {
                    loop++;
                }
                else
                {
                    printf("%d\n", 1);
                    break;
                }
            }

            if (loop == mask[index][0] + 1)
            {
                printf("%d\n", 0);
            }
            break;
        case 6:
            scanf("%d", &index);
            for (loop = 1; loop <= mask[index][0];)
            {
                specified = mask[index][loop];
                if (0 == state[specified])
                {
                    loop++;
                }
                else
                {
                    printf("%d\n", 0);
                    break;
                }
            }

            if (loop == mask[index][0] + 1)
            {
                printf("%d\n", 1);
            }
            break;
        case 7:
            scanf("%d", &index);
            count = 0;
            for (loop = 1; loop <= mask[index][0]; loop++)
            {
                specified = mask[index][loop];
                if (1 == state[specified])
                {
                    count++;
                }
            }
            printf("%d\n", count);
            break;
        case 8:
            scanf("%d", &index);
            for (loop = 1; loop <= mask[index][0]; loop++)
            {
                specified = mask[index][loop];
                krr[specified] = state[specified];
            }

            for (loop = 1; loop <= mask[index][0]; loop++)
            {
                specified = mask[index][loop];
                for (j = 0; j < specified; j++)
                {
                    krr[specified] = 2 * krr[specified];
                }
            }

            res = 0;
            for (loop = 1; loop <= mask[index][0]; loop++)
            {
                specified = mask[index][loop];
                res += krr[specified];
            }
            //printf("%d\n", res);
            cout << res << endl;

            break;
        default:
            break;
        }

    }

    return 0;
}


Measured memory_bytes: 3280