#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(n) (n).begin(), (n).end()


int main()
{
    int n, q;
    cin >> n;
    vector<bitset<64>> mask(n);
    bitset<64> bit;

    rep(i, n)
    {
        int k;
        int flag;
        cin >> k;
        rep(j, k)
        {
            cin >> flag;
            mask[i] |=  (1LL << flag);
        }
    }
    cin >> q;
    rep(n, q)
    {
        ll que, i, m;
        cin >> que;
        if (que == 0)
            cin >> i;
        else
            cin >> m;

        switch (que) {
        case 0://test
            //(bit & (1LL << i))
            cout << bit.test(i) << endl;
            break;
        case 1://set
            bit |= mask[m];
            break;
        case 2://clear
            bit &= ~(mask[m]);
            break;
        case 3:
            //XOR_ 0 0 = 0, 0 1 = 1, 1 1=0,
            bit ^= mask[m];
            break;
        case 4:
            cout << ((bit & mask[m]) == mask[m]) << endl;
            break;
        case 5:
            cout << (bit & mask[m]).any() << endl;
            break;
        case 6:
            cout << (bit & mask[m]).none() << endl;
            break;
        case 7:
            cout << (bit & mask[m]).count() << endl;
            break;
        case 8:
            cout << (bit & mask[m]).to_ulong() << endl;
            break;
        }

    }

}
