#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
    int n, k, a, q, com, m, i;
    cin >> n;
    vector<bitset<64> > bit(n);
    bitset<64> b;
    bitset<64> c;
    rep(j, n)
    {
        cin >> k;
        rep(l, k)
        {
            cin >> a;
            bit[j].set(a, 1);
        }
    }
    
    cin >> q;
    rep(j, q)
    {
        cin >> com;
        switch(com)
        {
            case 0:
                cin >> i;
                if (b.test(i)) cout << 1 << endl;
                else cout << 0 << endl;
                break;
            case 1:
                cin >> m;
                b |= bit[m];
                break;
            case 2:
                cin >> m;
                b &= ~bit[m];
                break;
            case 3:
                cin >> m;
                b ^= bit[m];
                break;
            case 4:
                cin >> m;
                c = b & bit[m];
                if (c == bit[m]) cout << 1 << endl;
                else cout << 0 << endl;
                break;
            case 5:
                cin >> m;
                c = b & bit[m];
                if (c.any()) cout << 1 << endl;
                else cout << 0 << endl;
                break;
            case 6:
                cin >> m;
                c = b & bit[m];
                if (c.none()) cout << 1 << endl;
                else cout << 0 << endl;
                break;
            case 7:
                cin >> m;
                c = b & bit[m];
                cout << c.count() << endl;
                break;
            case 8:
                cin >> m;
                c = b & bit[m];
                cout << c.to_ulong() << endl;
                break;
        }
    }
}

