import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; public class Main { public static void main(String[] args) { int W = nextInt(); int N = nextInt(); int[] J = new int[N]; for (int i = 0; i < J.length; i++) { J[i] = nextInt(); } int M = nextInt(); int[] C = new int[M]; for (int i = 0; i < C.length; i++) { C[i] = nextInt(); } /* * 原画マンiを頂点i、作画監督jを頂点N+j、始点をN+M、終点をN+M+1とした最大フロー問題に帰着する */ MaximumFlow maximumFlow = new MaximumFlow(M + N + 2, N + M, N + M + 1); for (int i = 0; i < N; i++) { maximumFlow.addEdge(N + M, i, J[i]); } for (int j = 0; j < M; j++) { maximumFlow.addEdge(N + j, N + M + 1, C[j]); } for (int j = 0; j < M; j++) { // 作画監督jについて考える int Q = nextInt(); boolean[] hate = new boolean[Q]; for (int q = 0; q < Q; q++) { hate[nextInt() - 1] = true; } for (int i = 0; i < N; i++) { if (!hate[i]) { // 原画マンiが作画監督jに嫌われていなければ、iからjにフロー maximumFlow.addEdge(i, N + j, J[i]); } } } int maximum = maximumFlow.fordFulkerson(); if (maximum >= W) { System.out.println("SHIROBAKO"); } else { System.out.println("BANSAKUTSUKITA"); } } static int nextInt() { int c; try { c = System.in.read(); while (c != '-' && (c < '0' || c > '9')) c = System.in.read(); if (c == '-') return -nextInt(); int res = 0; while (c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = System.in.read(); } return res; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return -1; } } class MaximumFlow { public static final int INF = 100000000; int V; int source; int sink; ArrayList[] graph; boolean[] used; @SuppressWarnings("unchecked") public MaximumFlow(int V, int source, int sink) { this.V = V; this.source = source; this.sink = sink; graph = new ArrayList[V]; for (int i = 0; i < V; i++) { graph[i] = new ArrayList(); } used = new boolean[V]; } public void addEdge(int from, int to, int cap) { graph[from].add(new Edge(to, cap, graph[to].size())); graph[to].add(new Edge(from, 0, graph[from].size() - 1)); } public int fordFulkerson() { int flow = 0; while (true) { Arrays.fill(used, false); int f = dfsFF(source, sink, INF); if (f == 0) { break; } flow += f; } return flow; } private int dfsFF(int v, int t, int f) { if (v == t) { return f; } used[v] = true; for (int i = 0; i < graph[v].size(); i++) { Edge e = graph[v].get(i); if (!used[e.to] && e.cap > 0) { int d = dfsFF(e.to, t, Math.min(f, e.cap)); if (d > 0) { e.cap -= d; graph[e.to].get(e.rev).cap += d; return d; } } } return 0; } class Edge { int to; int cap; int rev; public Edge(int to, int cap, int rev) { this.to = to; this.cap = cap; this.rev = rev; } } }