#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1100
#define inf 0x3f3f3f3f
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0;char ch=gc();
while(ch<'0'||ch>'9') ch=gc();
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
return x;
}
struct node{
int y,z,next;
}data[N*20*2];
int num=1,h[N],level[N],k,n,T;
inline void insert1(int x,int y,int z){
data[++num].y=y;data[num].z=z;data[num].next=h[x];h[x]=num;
data[++num].y=x;data[num].z=0;data[num].next=h[y];h[y]=num;
}
inline bool bfs(){
memset(level,0,sizeof(level));level[0]=1;queue<int>q;q.push(0);
while(!q.empty()){
int x=q.front();q.pop();
for (int i=h[x];i;i=data[i].next){
int y=data[i].y,z=data[i].z;
if (level[y]||!z) continue;level[y]=level[x]+1;q.push(y);if (y==T) return 1;
}
}return 0;
}
inline int dfs(int x,int s){
if (x==T) return s;int ss=s;
for (int i=h[x];i;i=data[i].next){
int y=data[i].y,z=data[i].z;
if(level[x]+1==level[y]&&z){
int xx=dfs(y,min(s,z));if(!xx) level[y]=0;
s-=xx;data[i].z-=xx;data[i^1].z+=xx;if(!s) return ss;
}
}return ss-s;
}
int main(){
freopen("2763.in","r",stdin);
k=read();n=read();int sum=0;T=k+n+1;int p;
for (int i=1;i<=k;++i) p=read(),sum+=p,insert1(n+i,T,p);
for (int i=1;i<=n;++i){
int pp=read();for (int j=1;j<=pp;++j) insert1(i,n+read(),1);
insert1(0,i,1);
}int ans=0;while(bfs())
ans+=dfs(0,inf);
if (ans!=sum) printf("No Solution!");else{
for (int i=1;i<=k;++i){
printf("%d: ",i);
for (int j=h[i+n];j;j=data[j].next){
int y=data[j].y,z=data[j].z;
if (y<=n&&z) printf("%d ",y);
}puts("");
}
}
return 0;
}