#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    bitset<64> mask[n];
    for(int i = 0; i < n; i++)
    {
        int k; cin >> k;
        for(int j = 0; j < k; j++)
        {
            ull x;
            cin >> x;
            mask[i].set(x);
        }
    }
    int q;
    cin >> q;
    bitset<64> bs;
    for(int i = 0; i < q; i++)
    {
        ull x, m;
        cin >> x >> m;
        if(x == 0) cout << bs.test(m) << endl;
        if(x == 1) bs |= mask[m];
        if(x == 2) bs &= ~mask[m];
        if(x == 3) bs ^= mask[m];
        if(x == 4) cout << ((bs & mask[m]) == mask[m]) << endl;
        if(x == 5) cout << (bs & mask[m]).any() << endl;
        if(x == 6) cout << (bs & mask[m]).none() << endl;
        if(x == 7) cout << (bs & mask[m]).count() << endl;
        if(x == 8) cout << (bs & mask[m]).to_ullong() << endl;
    }
    return 0;
}


