#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

//#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n;
	cin >> n;

	bitset<64> bs(0);
	vector<bitset<64>> b(n);

	for (ll i = 0; i < n; i++)
	{
		ll m;
		cin >> m;

		for (ll j = 0; j < m; j++)
		{
			ll x;
			cin >> x;

			b[i].set(x);
		}
	}

	ll a;
	cin >> a;

	for (ll i = 0; i < a; i++)
	{
		ll q, p, x;
		cin >> q >> p;

		switch (q)
		{
			case 0:
				println(bs.test(p));
				break;

			case 1:
				bs |= b[p];
				break;

			case 2:
				bs &= ~b[p];
				break;

			case 3:
				bs ^= b[p];
				break;

			case 4:
				println(((bs & b[p]) == b[p]));
				break;

			case 5:
				println(((bs & b[p]).to_ullong() != 0 ? 1 : 0));
				break;

			case 6:
				println(((bs & b[p]).to_ullong() == 0 ? 1 : 0));
				break;

			case 7:
				println((bs & b[p]).count());
				break;

			case 8:
				println((bs & b[p]).to_ullong());
				break;
		}

	}
}

