#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int numofbits(unsigned long long bits) {
    bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
    bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
    bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
    bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
    bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
    return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    unsigned long long flag = 0;
    int n, k, a, q, Q;
    cin >> n;
    vector<unsigned long long> mask(n, 0);
    rep(i, n) {
        cin >> k;
        rep(j, k) {
            cin >> a;
            mask[i] |= (1ull << a);
        }
    }
    cin >> Q;
    rep(i, Q) {
        cin >> q >> a;
        if(q == 0) { // test
            cout << (flag & (1ull << a) ? 1 : 0) << endl;
        } else if(q == 1) { // set
            flag |= mask[a];
        } else if(q == 2) { // clear
            flag &= ~mask[a];
        } else if(q == 3) { // flip
            flag ^= mask[a];
        } else if(q == 4) { // all
            cout << ((flag & mask[a]) == mask[a]) << endl;
        } else if(q == 5) { // any
            cout << ((flag & mask[a]) > 0) << endl;
        } else if(q == 6) { // none
            cout << ((flag & mask[a]) == 0) << endl;
        } else if(q == 7) { // count
            cout << numofbits(flag & mask[a]) << endl;
        } else if(q == 8) { // val
            cout << (flag & mask[a]) << endl;
        }
    }
}

