#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>
using namespace std;

int main()
{

    int n;
    cin>>n;
    vector<int> s[n];
    bitset<64> b(0);
    for(int i=0;i<n;i++){
        int temp,temp1;
        cin>>temp;
        while(temp--){
            cin>>temp1;
            s[i].push_back(temp1);
        }
    }
    int q;cin>>q;
    int tp1,i,ok;
    while(q--){
        cin>>tp1;
        switch(tp1){
        case 0:
            cin>>i;
            cout<<b.test(i)<<"\n";
            break;
        case 1:
            cin>>i;
            for(int j=0;j<s[i].size();j++)
            b.set(s[i][j],1);
            break;
        case 2:
            cin>>i;
            for(int j=0;j<s[i].size();j++)
            b.set(s[i][j],0);
            break;
        case 3:
            cin>>i;
            for(int j=0;j<s[i].size();j++)
            b.flip(s[i][j]);
            break;
        case 4:
            cin>>i;
             ok=1;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])==0){
                ok=0;break;
            }
            if(ok)cout<<"1\n";
            else cout<<"0\n";
            break;
        case 5:
            cin>>i;
             ok=0;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])){
                cout<<"1\n";
                ok=1;
                break;
            }
            if(ok==0)cout<<"0\n";
            break;
        case 6:
            cin>>i;
             ok=1;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])){
                ok=0;break;
            }
            if(ok)cout<<"1\n";
            else cout<<"0\n";
            break;
        case 7:
            cin>>i;
             ok=0;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])){
                ok++;
            }
            cout<<ok<<"\n";
            break;
        case 8:
            bitset<64> c(0);
            cin>>i;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])){
                c.set(s[i][j]);
            }
            cout<<c.to_ulong()<<"\n";
            break;
         }
    }
}



