#include <bits/stdc++.h>

using namespace std;

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define ALL(v) (v).begin(), (v).end()

int main() {
    bitset<64> a(0);
    vector<bitset<64>> m;
    int n; cin >> n;
    rep(i, n) {
        bitset<64> t(0);
		int k; cin >> k;
		while (k--) {
			int tt; cin >> tt;
			t.set(tt);
		}
        m.push_back(t);
    }
    int Q; cin >> Q;
    while (Q--) {
        int q; cin >> q;
        if (q == 0) {
            int i; cin >> i;
            cout << a.test(i) << endl;
        } else if (q == 1) {
            int i; cin >> i;
            a |= m[i];
        } else if (q == 2) {
            int i; cin >> i;
            a &= ~m[i];
        } else if (q == 3) {
            int i; cin >> i;
            a ^= m[i];
        } else if (q == 4) {
            int i; cin >> i;
            cout << ((a & m[i]) == m[i]) << endl;
        } else if (q == 5) {
            int i; cin >> i;
            cout << (a & m[i]).any() << endl;
        } else if (q == 6) {
            int i; cin >> i;
            cout << (a & m[i]).none() << endl;
        } else if (q == 7) {
            int i; cin >> i;
            cout << (a & m[i]).count() << endl;
        } else if (q == 8) {
            int i; cin >> i;
            cout << (a & m[i]).to_ulong() << endl;
        }
    }
    
}
