// Enjoy your stay. #include #define long long long #define LOOPVAR_TYPE long #define all(x) (x).begin(), (x).end() #define max(x, y) ((x) > (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y)) #define sz(x) ((LOOPVAR_TYPE)(x).size()) #define foreach(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++) #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define _rep(i, n) _rep2(i, 0, n) #define _rep2(i, a, b) for(LOOPVAR_TYPE i = (LOOPVAR_TYPE)(a); i < (LOOPVAR_TYPE)(b); i++) #define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__) #define fir first #define sec second #define mp make_pair #define mt make_tuple #define pb push_back const double EPS = 1e-9; const double PI = acos(-1.0); const long INF = 1070000000LL; const long MOD = 1000000007LL; using namespace std; typedef istringstream iss; typedef stringstream sst; typedef pair pi; typedef vector vi; const int MN = 100010; struct dinic{ struct edge{ int to;long cap;int rev; edge(int to,long cap,int rev): to(to),cap(cap),rev(rev){} }; vector G[MN]; long level[MN]; int iter[MN]; void init(int N){ rep(i,N)G[i].clear(); } void add_edge(int from,int to,long cap){ G[from].pb(edge(to,cap,sz(G[to]))); G[to].pb(edge(from,0,sz(G[from])-1)); } void bfs(int s){ memset(level,-1,sizeof(level)); queue que; level[s]=0; que.push(s); while(!que.empty()){ int v=que.front(); que.pop(); rep(i,sz(G[v])){ edge &e = G[v][i]; if(e.cap>0 && level[e.to]<0){ level[e.to] = level[v]+1; que.push(e.to); } } } } long dfs(int v,int t,long f){ if(v==t)return f; for(int &i=iter[v]; i0 && level[v] < level[e.to]){ long d=dfs(e.to,t,min(f,e.cap)); if(d>0){ e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0; } int max_flow(int s,int t){ long flow=0; for(;;){ bfs(s); if(level[t]<0)return flow; memset(iter,0,sizeof(iter)); int f; while((f=dfs(s,t,INF*INF))>0){ flow+=f; } } } }; int main(){ cin.tie(0); ios_base::sync_with_stdio(0); int W; int N, M; cin>>W>>N; int J[55], C[55]; int Q[55], X[55][55]; rep(i,N)cin>>J[i]; cin>>M; rep(i,M)cin>>C[i]; rep(i,M){ cin>>Q[i]; rep(j,Q[i])cin>>X[i][j],X[i][j]--; } dinic dnc; dnc.init(N+M+2); int s = N+M; int t = s+1; rep(i,N){ dnc.add_edge(s, i, J[i]); } rep(i,M){ dnc.add_edge(N+i, t, C[i]); } int ok[55][55]; rep(i,N)rep(j,M)ok[i][j] = 1; rep(i,M){ rep(j,Q[i]){ ok[i][X[i][j]] = 0; } } rep(i,N)rep(j,M){ if(ok[i][j]){ dnc.add_edge(i,N+j,INF); } } cout<<(dnc.max_flow(s,t) >= W ? "SHIROBAKO" : "BANSAKUTSUKITA")<