#includeusing namespace std;const int maxn = 1000 + 5;int n,x,root;int pos[maxn];vector A[maxn];int main(){ // freopen("data.in","r",stdin); // freopen("data.out","w",stdout); while(scanf("%d",&n) != EOF){ for(int i = 1;i <= n;i++){ scanf("%d",&x); pos[x] = i; A[i].clear(); } stack S; scanf("%d",&root); S.push(root); for(int i = 1;i < n;i++){ scanf("%d",&x); while(1){ int t = S.top(); if(t == root || pos[t]+1 < pos[x]){ A[t].push_back(x); S.push(x); break; } else S.pop(); } } for(int i = 1;i <= n;i++){ printf("%d:",i); for(int j = 0;j < A[i].size();j++) printf(" %d",A[i][j]); putchar('\n'); } } return 0;}