#include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  int n;
  cin >> n;
  vector< bitset<64> > mask(n, bitset<64>(0));
  rep(i,n) {
    int k; cin >> k;
    rep(j,k) {
      int b; cin >> b;
      mask[i].set(b);
    }
  }

  int q;
  cin >> q;
  bitset<64> a(0);

  vector<ull> ans;
  rep(i,q) {
    int command;
    cin >> command;
    if (command == 0) {
      int x; cin >> x;
      ans.push_back(a[x]);
    } else if (command == 1) {
      int m; cin >> m;
      a |= mask[m];
    } else if (command == 2) {
      int m; cin >> m;
      a &= ~mask[m];
    } else if (command == 3) {
      int m; cin >> m;
      a ^= mask[m];
    } else if (command == 4) {
      int m; cin >> m;
      ans.push_back((a|~mask[m]).all());
    } else if (command == 5) {
      int m; cin >> m;
      ans.push_back((a&mask[m]).any());
    } else if (command == 6) {
      int m; cin >> m;
      ans.push_back((a&mask[m]).none());
    } else if (command == 7) {
      int m; cin >> m;
      ans.push_back((a&mask[m]).count());
    } else if (command == 8) {
      int m; cin >> m;
      ans.push_back((a&mask[m]).to_ullong());
    }
  }
  for (auto a : ans) cout << a << endl;

  return 0;
}

