#include<bits/stdc++.h>
using namespace std;
bitset<64> b;
int main()
{
	int n;
	cin >> n;
	vector<bitset<64> > v(n);
	int k = 0;
	while(n--)
	{
		int m;
		cin >> m;
		while(m--)
		{
			int x;
			cin >> x;
			v[k].set(x);
		}
		k++;
	}
	int t;
	cin >> t;
	while(t--)
	{
		int ch;
		cin >> ch;
		if(ch == 0)
		{
			int x;
			cin >> x;
			printf("%d\n",b.test(x));
		}
		else if(ch == 1)
		{
			int x;
			cin >> x;
			b |= v[x];
		}
		else if(ch == 2)
		{
			int x;
			cin >> x;
			b &= ~(v[x]);
		}
		else if(ch == 3)
		{
			int x;
			cin >> x;
			b ^= v[x];
		}
		else if(ch == 4)
		{
			int x;
			cin >> x;
			cout << (b | ~v[x]).all() << endl;
		}
		else if(ch == 5)
		{
			int x;
			cin >> x;
			cout << (b & v[x]).any() << endl;
		}
		else if(ch == 6)
		{
			int x;
			cin >> x;
			cout << (b & v[x]).none() << endl;
		}
		else if(ch == 7)
		{
			int x;
			cin >> x;
			cout << (b & v[x]).count() << endl;
		}
		else if(ch == 8)
		{
			int x;
			cin >> x;
			cout << (b & v[x]).to_ulong() << endl;
		}
	}
	return 0;
} 
