#include using namespace std; struct Edge { typedef int CostType; const static int cost = 1; int from, to; Edge(int from, int to) : from(from), to(to) {}; }; template struct WeightedEdge : public Edge { typedef Cost CostType; Cost cost; WeightedEdge(int from, int to, Cost cost = 0) : Edge(from, to), cost(cost) {} }; template struct ResidualEdge : public Edge { typedef Capacity CapacityType; Capacity cap; int rev; ResidualEdge(int from, int to, Capacity cap) : Edge(from, to), cap(cap) {} ResidualEdge reverse() const {return ResidualEdge(to, from, 0);} }; template struct WeightedResidualEdge : public ResidualEdge { Cost cost; WeightedResidualEdge(int from, int to, Capacity cap, Cost cost) : ResidualEdge(from, to, cap), cost(cost) {} WeightedResidualEdge reverse() const {return WeightedResidualEdge(this->to, this->from, 0, -cost);} }; template class Graph { public: typedef Edge EdgeType; virtual int size() const = 0; template void addEdge(Args...) {} template void addUndirectedEdge(Args...) {} virtual vector getEdges() const = 0; virtual vector getEdges(int from) const = 0; virtual vector getEdges(int from, int to) const = 0; virtual int getDegree(int v) const = 0; }; template class AdjacencyList : public Graph { protected: vector> graph; public: AdjacencyList(int n) : graph(n) {} int size() const { return graph.size(); } template void addEdge(Args... args) { Edge edge(args...); graph[edge.from].emplace_back(edge); } template void addUndirectedEdge(Args... args) { Edge edge(args...); addEdge(edge); swap(edge.from, edge.to); addEdge(edge); } vector getEdges() const { vector res; for (const auto& edges : graph) { res.insert(res.end(), edges.begin(), edges.end()); } return res; } vector getEdges(int from) const { return graph[from]; } vector getEdges(int from, int to) const { vector res; for (const auto& edge : graph[from]) { if (edge.to == to) res.emplace_back(edge); } return res; } int getDegree(int v) const { return graph[v].size(); } vector& operator[](int v) { return graph[v]; } }; template class ResidualGraph : public AdjacencyList { public: ResidualGraph(int n) : AdjacencyList(n) {} template void addEdge(Args... args) { Edge edge(args...); edge.rev = this->graph[edge.to].size(); this->graph[edge.from].emplace_back(edge); Edge rev = edge.reverse(); rev.rev = this->graph[rev.to].size() - 1; this->graph[rev.from].emplace_back(rev); } template void addUndirectedEdge(Args... args) { Edge edge(args...); edge.rev = this->graph[edge.to].size(); this->graph[edge.from].emplace_back(edge); Edge rev = edge.reverse(); rev.rev = this->graph[rev.to].size() - 1; rev.cap = edge.cap; this->graph[rev.from].emplace_back(rev); } void flow(int v, int i, typename Edge::CapacityType f) { auto& e = this->graph[v][i]; e.cap -= f; this->graph[e.to][e.rev].cap += f; } }; class MaxFlow { private: template class Dinic { private: const Capacity INF; ResidualGraph>& graph; vector level, iter; void bfs(int source) { fill(level.begin(), level.end(), -1); level[source] = 0; queue que; que.push(source); while (!que.empty()) { int v = que.front(); que.pop(); for (const auto& edge : graph[v]) { if (edge.cap == 0 || level[edge.to] >= 0) continue; level[edge.to] = level[v] + 1; que.push(edge.to); } } } int dfs(int v, int sink, int flow) { if (v == sink) return flow; for (int& i = iter[v]; i < int(graph[v].size()); ++i) { auto& edge = graph[v][i]; if (edge.cap == 0 || level[v] >= level[edge.to]) continue; int f = dfs(edge.to, sink, min(flow, edge.cap)); if (f == 0) continue; graph.flow(v, i, f); return f; } return 0; } public: Dinic(ResidualGraph>& graph) : INF(numeric_limits::max()), graph(graph) {} Capacity solve(int source, int sink) { level = vector(graph.size(), 0); iter = vector(graph.size(), 0); int flow = 0, f; while (true) { bfs(source); if (level[sink] < 0) return flow; fill(iter.begin(), iter.end(), 0); while ((f = dfs(source, sink, INF)) > 0) flow += f; } } }; public: template Capacity solve(ResidualGraph>& graph, int source, int sink) { Dinic dinic(graph); return dinic.solve(source, sink); } }; int main() { int w, n; cin >> w >> n; ResidualGraph> graph(w + n + 2); int id = 0; int source = id++; int sink = id++; vector a(n); for (int& i : a) i = id++; for (int i = 0; i < n; ++i) { int j; cin >> j; graph.addEdge(source, a[i], j); } int m; cin >> m; vector b(m); for (int& i : b) i = id++; for (int i = 0; i < m; ++i) { int c; cin >> c; graph.addEdge(b[i], sink, c); } for (int i = 0; i < m; ++i) { int q; cin >> q; unordered_set x; for (int j = 0; j < q; ++j) { int k; cin >> k; x.insert(k - 1); } for (int j = 0; j < n; ++j) { if (x.count(j)) continue; graph.addEdge(a[j], b[i], w); } } MaxFlow mf; cout << (mf.solve(graph, source, sink) >= w ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl; }