def dinic(cf, nV, s, t): dist = get_distance(cf, s, t) while dist[t] > 0: df = dfs(dist, cf, s, t, float('inf')) while df: df = dfs(dist, cf, s, t, float('inf')) dist = get_distance(cf, s, t) return sum(cf[t].values()) def get_distance(cf, s, t): dist = [-1] * len(cf) dist[s] = 0 frontiers = [s] while frontiers: new_frontiers = [] for u in frontiers: for v, capacity in cf[u].items(): if dist[v] == -1 and capacity > 0: dist[v] = dist[u] + 1 new_frontiers.append(v) frontiers = new_frontiers return dist def dfs(dist, cf, u, t, df): if u == t: return df for v, capacity in cf[u].items(): if dist[v] > dist[u] and capacity > 0: new_df = dfs(dist, cf, v, t, min(df, capacity)) if new_df > 0: cf[u][v] -= new_df cf[v][u] += new_df return new_df return 0 W = int(input()) N = int(input()) Js = list(map(int, input().split())) M = int(input()) Cs = list(map(int, input().split())) s = N + M t = N + M + 1 caps = [dict() for i in range(t + 1)] for n, j in enumerate(Js): caps[s][n] = j caps[n][s] = 0 for m, c in enumerate(Cs, N): caps[m][t] = c caps[t][m] = 0 for m in range(N, N + M): QX = list(map(int, input().split())) Xs = set(QX[1:]) for x in range(N): if x + 1 not in Xs: caps[x][m] = min(caps[s][x], caps[m][t]) caps[m][x] = 0 w = dinic(caps, t + 1, s, t) if w >= W: print('SHIROBAKO') else: print('BANSAKUTSUKITA')