#include <bitset>
#include <iostream>
#include <vector>

using Bitset = std::bitset<64>;

int main(void) {
    std::bitset<64> bitset{};

    int n;
    std::cin >> n;

    std::vector<Bitset> bitsets{};
    bitsets.resize(n);
    for (int i = 0; i < n; ++i) {
        int k;
        std::cin >> k;
        for (int j = 0; j < k; ++j) {
            int b;
            std::cin >> b;
            bitsets[i].set(b);
        }
    }

    int q;
    std::cin >> q;

    for (int i = 0; i < q; ++i) {
        int kind, m;
        std::cin >> kind >> m;

        switch (kind) {
            case 0:
                std::cout << bitset.test(m) << std::endl;
                break;
            case 1:
                bitset |= bitsets.at(m);
                break;
            case 2:
                bitset &= ~bitsets.at(m);
                break;
            case 3:
                bitset ^= bitsets.at(m);
                break;
            case 4:
                std::cout << (bitset | ~bitsets.at(m)).all() << std::endl;
                break;
            case 5:
                std::cout << (bitset & bitsets.at(m)).any() << std::endl;
                break;
            case 6:
                std::cout << (bitset & bitsets.at(m)).none() << std::endl;
                break;
            case 7:
                std::cout << (bitset & bitsets.at(m)).count() << std::endl;
                break;
            case 8:
                std::cout << (bitset & bitsets.at(m)).to_ullong() << std::endl;
        }
    }
}
