#Dinic法で最大流を求める #deque のimport が必要 #逆辺追加しなきゃいけないから、 #グラフの構成はadd_edgeで行う #最大流は flow メソッドで from collections import deque class Dinic: def __init__(self,N): self.N = N self.G = [[] for _ in range(N)] self.level = None self.progress = None def add_edge(self,fr,to,cap): forward = [to,cap,None] forward[2] = backward = [fr,0,forward] self.G[fr].append(forward) self.G[to].append(backward) def add_multi_edge(self,v1,v2,cap1,cap2): edge1 = [v2,cap1,None] edge1[2] = edge2 = [v1,cap2,edge1] self.G[v1].append(edge1) self.G[v2].append(edge2) def bfs(self,s,t): self.level = level = [None] * self.N q = deque([s]) level[s] = 0 G = self.G while q: v = q.popleft() lv = level[v] + 1 for w,cap,_ in G[v]: if cap and level[w] is None: level[w] = lv q.append(w) return level[t] is not None def dfs(self,v,t,f): if v == t:return f level = self.level Gv = self.G[v] for i in range(self.progress[v],len(Gv)): self.progress[v] = i w,cap,rev = e = Gv[i] if cap and level[v] < level[w]: d = self.dfs(w,t,min(f,cap)) if d: e[1] -= d rev[1] += d return d return 0 def flow(self,s,t,): flow = 0 inf = 1 << 30 G = self.G while self.bfs(s,t): self.progress = [0] * self.N f = inf while f: f = self.dfs(s,t,inf) flow += f return flow def min_cut(self,s): #最小カットを実現する頂点の分割を与える #True なら source側 #False なら sink側 visited = [False for i in range(self.N)] q = deque([s]) while q: now = q.popleft() visited[now] = True for to,cap,_ in self.G[now]: if cap and not visited[to]: visited[to] = True q.append(to) return visited W = int(input()) N = int(input()) J = list(map(int,input().split())) M = int(input()) C = list(map(int,input().split())) dinic = Dinic(N + M + 2) for i in range(N): dinic.add_edge(0,i+1,J[i]) for j in range(M): dinic.add_edge(N+j+1,N+M+1,C[j]) inf = 1 << 30 for j in range(M): l = list(map(int,input().split())) s = set(l[1:]) for i in range(N): if i+1 not in s: dinic.add_edge(i+1,N+j+1,inf) ans = "SHIROBAKO" if W <= dinic.flow(0,N+M+1) else "BANSAKUTSUKITA" print(ans)