#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int	n;
	cin >> n;
	bitset<64>	bs;
	vector<bitset<64>>	bsm(n);
	rep(i, n)
	{
		int	x;
		cin >> x;
		rep(j, x)
		{
			int	y;
			cin >> y;
			bsm.at(i).set(y);
		}
	}
	cin >> n;
	rep(i, n)
	{
		int	a, b;
		cin >> a >> b;
		if (a == 0) // test
			cout << bs.test(b) << endl;
		else if (a == 1) // set
			bs |= bsm.at(b);
		else if (a == 2) // clear
			bs &= ~bsm.at(b);
		else if (a == 3) // flip
			bs ^= bsm.at(b);
		else if (a == 4) // all
			cout << (bsm.at(b) == (bs & bsm.at(b))) << endl;
		else if (a == 5) // any
			cout << (bs & bsm.at(b)).any() << endl;
		else if (a == 6) // none
			cout << (bs & bsm.at(b)).none() << endl;
		else if (a == 7)// count
			cout << (bs & bsm.at(b)).count() << endl;
		else // val
			cout << (bs & bsm.at(b)).to_ullong() << endl;
	}
}

