#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int>minn[M][40],adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=30;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=30;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
            relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
    relax(now);
    for(int i=30;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
            relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        cin>>tmp,id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        cout<<k<<" ";
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        cout<<endl;
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int> adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
vector<int>hlp;
void relax(vector<int>&tmp)
{
    if(!tmp.size())
        return;
    if(tmp.size()<=10)
    {
        sort(tmp.begin(),tmp.end());
        return;
    }
    hlp.clear();
    for(int i=1;i<=10;i++)
    {
        int ind=0;
        if(!tmp.size())
            break;
        int minn=tmp[0];
        for(int j=1;j<tmp.size();j++){
            if(minn>tmp[j])
                minn=tmp[j],ind=j;
        }
        hlp.pb(tmp[ind]);
        swap(tmp[ind],tmp[(int)tmp.size()-1]);
        tmp.pop_back();
    }
    tmp.clear();
    for(int i=0;i<hlp.size();i++)
        tmp.pb(hlp[i]);
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=18;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
       // relax(minn2[v][j]);
       relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=18;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            for(int j=0;j<minn2[v][i].size();j++)
                now.pb(minn2[v][i][j]);
       //     relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
  //  relax(now);
    for(int i=18;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            for(int j=0;j<minn2[v][i].size();j++)
                now.pb(minn2[v][i][j]);
            for(int j=0;j<minn2[u][i].size();j++)
                now.pb(minn2[u][i][j]);
          //  relax(now);
            v=tmp,u=tmp2;
        }
    }
    for(int j=0;j<id[par[v][0]].size();j++)
        now.pb(id[par[v][0]][j]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        scanf("%d%d",&a,&b),adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        scanf("%d",&tmp),id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        printf("%d ",k);
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        printf("\n");
    }
}


#include<iostream>
//#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int>minn[M][30],adj[M];
vector<int>minn2[M][30];
int h[M],lg[M];
vector<int>now;
int par[M][30];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=20;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=20;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
            relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
    relax(now);
    for(int i=20;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(par[tmp][0]!=par[tmp2][0])
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
            relax(now);
            v=tmp,u=tmp2;
        }
    }
    if(par[v][0]!=par[u][0])
        v=par[v][0];
    mer(now,minn2[v][0]);
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        cin>>tmp,id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        cin>>v>>u>>siz;
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        cout<<k<<" ";
        for(int i=0;i<k;i++)
            cout<<now[i]<<" ";
        cout<<endl;
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int> adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    vector<int>hlp;
    if(!tmp.size())
        return;
    if(tmp.size()<=10)
    {
        sort(tmp.begin(),tmp.end());
        return;
    }
    for(int i=1;i<=10;i++)
    {
        int ind=0;
        if(!tmp.size())
            break;
        int minn=tmp[0];
        for(int j=1;j<tmp.size();j++){
            if(minn>tmp[j])
                minn=tmp[j],ind=j;
        }
        hlp.pb(tmp[ind]);
        swap(tmp[ind],tmp[(int)tmp.size()-1]);
        tmp.pop_back();
    }
    tmp.clear();
    for(int i=0;i<hlp.size();i++)
        tmp.pb(hlp[i]);
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=20;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=20;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
       //     relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
  //  relax(now);
    for(int i=20;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
          //  relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        scanf("%d",&tmp),id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        printf("%d ",k);
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        printf("\n");
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int>minn[M][40],adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=20;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=20;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
            relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
    relax(now);
    for(int i=20;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
            relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        cin>>tmp,id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        cout<<k<<" ";
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        cout<<endl;
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int>minn[M][40],adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=30;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=30;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
            relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
    relax(now);
    for(int i=30;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
            relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        cin>>tmp,id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        cout<<k<<" ";
        for(int i=0;i<k;i++)
            printf("%d",now[i]);
        cout<<endl;
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int> adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
vector<int>hlp;
void relax(vector<int>&tmp)
{
    if(!tmp.size())
        return;
    if(tmp.size()<=10)
    {
        sort(tmp.begin(),tmp.end());
        return;
    }
    hlp.clear();
    for(int i=1;i<=10;i++)
    {
        int ind=0;
        if(!tmp.size())
            break;
        int minn=tmp[0];
        for(int j=1;j<tmp.size();j++){
            if(minn>tmp[j])
                minn=tmp[j],ind=j;
        }
        hlp.pb(tmp[ind]);
        swap(tmp[ind],tmp[(int)tmp.size()-1]);
        tmp.pop_back();
    }
    tmp.clear();
    for(int i=0;i<hlp.size();i++)
        tmp.pb(hlp[i]);
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=18;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=18;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
       //     relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
  //  relax(now);
    for(int i=18;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
          //  relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        scanf("%d%d",&a,&b),adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        scanf("%d",&tmp),id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        printf("%d ",k);
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        printf("\n");
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int> adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    vector<int>hlp;
    if(!tmp.size())
        return;
    for(int i=1;i<=10;i++)
    {
        int ind=0;
        if(!tmp.size())
            break;
        int minn=tmp[0];
        for(int j=1;j<tmp.size();j++){
            if(minn>tmp[j])
                minn=tmp[j],ind=j;
        }
        hlp.pb(tmp[ind]);
        swap(tmp[ind],tmp[(int)tmp.size()-1]);
        tmp.pop_back();
    }
    tmp.clear();
    for(int i=0;i<hlp.size();i++)
        tmp.pb(hlp[i]);
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=20;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=20;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
       //     relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
  //  relax(now);
    for(int i=20;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
          //  relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        scanf("%d",&tmp),id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        printf("%d ",k);
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        printf("\n");
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int> adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=20;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=20;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
       //     relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
  //  relax(now);
    for(int i=20;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
          //  relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        scanf("%d",&tmp),id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        printf("%d ",k);
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        printf("\n");
    }
}


#include<iostream>
//#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int>minn[M][30],adj[M];
vector<int>minn2[M][30];
int h[M],lg[M];
vector<int>now;
int par[M][30];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=20;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=20;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
            relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
    relax(now);
    for(int i=20;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(par[tmp][0]!=par[tmp2][0])
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
            relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,minn2[v][0]);
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        cin>>tmp,id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        cin>>v>>u>>siz;
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        cout<<k<<" ";
        for(int i=0;i<k;i++)
            cout<<now[i]<<" ";
        cout<<endl;
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int>minn[M][40],adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=20;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=20;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
       //     relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
  //  relax(now);
    for(int i=20;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
          //  relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        cin>>tmp,id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        cout<<k<<" ";
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        cout<<"\n";
    }
}


#include<iostream>
//#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int>minn[M][40],adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=30;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=30;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
            relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
    relax(now);
    for(int i=30;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
            relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        cin>>tmp,id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        cin>>v>>u>>siz;
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        cout<<k<<" ";
        for(int i=0;i<k;i++)
            cout<<now[i]<<" ";
        cout<<endl;
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int>minn[M][40],adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=20;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=20;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
       //     relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
  //  relax(now);
    for(int i=20;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
          //  relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        scanf("%d",&tmp),id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        cout<<k<<" ";
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        printf("\n");
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int> adj[M];
vector<int>minn2[M][40];
int h[M],lg[M];
vector<int>now;
int par[M][40];
void relax(vector<int>&tmp)
{
    vector<int>hlp;
    if(!tmp.size())
        return;
    if(tmp.size()<=10)
    {
        sort(tmp.begin(),tmp.end());
        return;
    }
    for(int i=1;i<=10;i++)
    {
        int ind=0;
        if(!tmp.size())
            break;
        int minn=tmp[0];
        for(int j=1;j<tmp.size();j++){
            if(minn>tmp[j])
                minn=tmp[j],ind=j;
        }
        hlp.pb(tmp[ind]);
        swap(tmp[ind],tmp[(int)tmp.size()-1]);
        tmp.pop_back();
    }
    tmp.clear();
    for(int i=0;i<hlp.size();i++)
        tmp.pb(hlp[i]);
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=18;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=18;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
       //     relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
  //  relax(now);
    for(int i=18;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(tmp!=tmp2)
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
          //  relax(now);
            v=tmp,u=tmp2;
        }
    }
    mer(now,id[par[v][0]]);
    //cerr<<v<<" "<<u<<"************"<<endl;
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        scanf("%d",&tmp),id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        scanf("%d%d%d",&v,&u,&siz);
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        printf("%d ",k);
        for(int i=0;i<k;i++)
            printf("%d ",now[i]);
        printf("\n");
    }
}


#include<iostream>
//#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
//define size(x) (int)x.size();
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
vector<int>id[M];
vector<int>minn[M][30],adj[M];
vector<int>minn2[M][30];
int h[M],lg[M];
vector<int>now;
int par[M][30];
void relax(vector<int>&tmp)
{
    sort(tmp.begin(),tmp.end());
    while(tmp.size()>10)
        tmp.pop_back();
}
void mer(vector<int>&ne,vector<int>&pa)
{
    for(int i=0;i<pa.size();i++)
        ne.pb(pa[i]);
}
void dfs(int v,int l)
{
 //   cerr<<v<<" "<<"****"<<endl;
    h[v]=h[l]+1;
    for(int i=0;i<id[l].size();i++)
        minn2[v][0].pb(id[l][i]);
    relax(minn2[v][0]);
    par[v][0]=l;
    for(int j=1;j<=20;j++)
    {
        par[v][j]=par[par[v][j-1]][j-1];
        int jad=par[v][j-1];
        mer(minn2[v][j],minn2[v][j-1]);
        mer(minn2[v][j],minn2[jad][j-1]);
        relax(minn2[v][j]);
      //  if(v==5 && j==1)
        //    cerr<<minn2[v][j].size()<<" "<<jad<<" "<<id[l].size()<<" "<<"****"<<endl;
    }
    for(int i=0;i<adj[v].size();i++)
    {
        int u=adj[v][i];
        if(u==l)
            continue;
        dfs(u,v);
    }
}
void lca(int v,int u)
{
    int p1=v,p2=u;
    if(h[v]<h[u])
        swap(v,u);
    mer(now,id[v]);
    for(int i=20;i>=0;i--)
    {
        if(h[v]-(1<<i)>=h[u]){
            mer(now,minn2[v][i]);
            relax(now);
            v=par[v][i];
        }
    }
   // if(p1+p2==6)
     //   cerr<<v<<" "<<u<<" "<<"*****";
    if(v==u)
        return;
    mer(now,id[u]);
    relax(now);
    for(int i=20;i>=0;i--)
    {
        int tmp=par[v][i];
        int tmp2=par[u][i];
        if(par[tmp][0]!=par[tmp2][0])
        {
            mer(now,minn2[v][i]);
            mer(now,minn2[u][i]);
            relax(now);
            v=tmp,u=tmp2;
        }
    }
    if(v!=u)
        v=par[v][0];
    mer(now,minn2[v][0]);
    relax(now);
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,q,tmp,a,b;
	cin>>n>>m>>q;
	for(int i=1;i<=n-1;i++)
        cin>>a>>b,adj[a].pb(b),adj[b].pb(a);
    for(int i=1;i<=m;i++)
        cin>>tmp,id[tmp].pb(i);
    dfs(1,0);
    while(q--)
    {
        int v,u,siz;
        cin>>v>>u>>siz;
        int len=h[u]-h[v];
        now.clear();
        lca(u,v);
        relax(now);
        int k=min((int)now.size(),siz);
        cout<<k<<" ";
        for(int i=0;i<k;i++)
            cout<<now[i]<<" ";
        cout<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100005;
int father[MAXN], n;
int x[MAXN];
bool isok[MAXN], vis[MAXN];
void init()
{
    for(int i = 0; i <= n; i++)
    {
        father[i] = i;
        isok[i] = false;
        vis[i] = false;
    }
}
int findfather(int son)
{
    return (father[son] == son) ? son : (father[son] = findfather(father[son]));
}
void merge(int a, int b)
{
    father[findfather(a)] = findfather(b);
}
struct line
{
    int u, v;
    ll length;
} Edge[2 * MAXN];
bool operator < (line a, line b)
{
    return a.length < b.length;
}
int main(void)
{
    int m, k, u, v;
    ll length;
    scanf("%d%d%d", &n, &m, &k);

    init();

    for(int i = 0; i < k; i++)
    {
        scanf("%d", &x[i]);
        isok[x[i]] = true;
    }

    int cnt = 0;
    for(int i = 0; i < m; i++)
    {
        scanf("%d%d%I64d", &u, &v, &length);
        Edge[cnt] = (line){u, v, length};
        ++cnt;
        if(u != v)
        {
            Edge[cnt] = (line){v, u, length};
            ++cnt;
        }
    }

    sort(Edge, Edge + cnt);

    ll answer = 0;
    int tot = 0;
    int tot2 = 0;
    for(int i = 0; i < cnt; i++)
    {
        //cout << Edge[i].u << " " << Edge[i].v << endl;
        if(findfather(Edge[i].u) != findfather(Edge[i].v))
        {
            if(!vis[Edge[i].u])
            {
                vis[Edge[i].u] = true;
                ++tot2;
                if(isok[Edge[i].u])
                    ++tot;
            }
            if(!vis[Edge[i].v])
            {

                vis[Edge[i].v] = true;
                ++tot2;
                if(isok[Edge[i].v])
                    ++tot;
            }
            merge(Edge[i].u, Edge[i].v);
            if(tot == k && tot2 == n)
            {
                answer = Edge[i].length;
                break;
            }
        }
    }

    for(int i = 0; i < k; i++)
    {
        if(i > 0)
            printf(" ");
        printf("%I64d", answer);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100005;
int father[MAXN], n;
int x[MAXN];
void init()
{
    for(int i = 0; i <= n; i++)
    {
        father[i] = i;
    }
}
int findfather(int son)
{
    return (father[son] == son) ? son : (father[son] = findfather(father[son]));
}
void merge(int a, int b)
{
    father[findfather(a)] = findfather(b);
}
struct line
{
    int u, v;
    ll length;
} Edge[2 * MAXN];
bool operator < (line a, line b)
{
    return a.length < b.length;
}
int main(void)
{
    int m, k, u, v;
    ll length;
    scanf("%d%d%d", &n, &m, &k);

    init();

    for(int i = 0; i < k; i++)
    {
        scanf("%d", &x[i]);
    }

    int cnt = 0;
    for(int i = 0; i < m; i++)
    {
        scanf("%d%d%I64d", &u, &v, &length);
        Edge[cnt] = (line){u, v, length};
        ++cnt;
        if(u != v)
        {
            Edge[cnt] = (line){v, u, length};
            ++cnt;
        }
    }

    sort(Edge, Edge + cnt);

    ll answer = 0;

    for(int i = 0; i < cnt; i++)
    {
        //cout << Edge[i].u << " " << Edge[i].v << endl;
        if(findfather(Edge[i].u) != findfather(Edge[i].v))
        {
            merge(Edge[i].u, Edge[i].v);
            answer = max(answer, Edge[i].length);
        }
    }

    for(int i = 0; i < k; i++)
    {
        if(i > 0)
            printf(" ");
        printf("%I64d", answer);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100005;
int father[MAXN], n;
int x[MAXN];
bool isok[MAXN], vis[MAXN];
void init()
{
    for(int i = 0; i <= n; i++)
    {
        father[i] = i;
        isok[i] = false;
        vis[i] = false;
    }
}
int findfather(int son)
{
    return (father[son] == son) ? son : (father[son] = findfather(father[son]));
}
void merge(int a, int b)
{
    father[findfather(a)] = findfather(b);
}
struct line
{
    int u, v;
    ll length;
} Edge[2 * MAXN];
bool operator < (line a, line b)
{
    return a.length < b.length;
}
int main(void)
{
    int m, k, u, v;
    ll length;
    scanf("%d%d%d", &n, &m, &k);

    init();

    for(int i = 0; i < k; i++)
    {
        scanf("%d", &x[i]);
        isok[x[i]] = true;
    }

    int cnt = 0;
    for(int i = 0; i < m; i++)
    {
        scanf("%d%d%I64d", &u, &v, &length);
        Edge[cnt] = (line){u, v, length};
        ++cnt;
        if(u != v)
        {
            Edge[cnt] = (line){v, u, length};
            ++cnt;
        }
    }

    sort(Edge, Edge + cnt);

    ll answer = 0;
    int tot = 0;
    int tot2 = 0;
    int id = -1;
    for(int i = 0; i < cnt; i++)
    {
        //cout << Edge[i].u << " " << Edge[i].v << endl;
        if(findfather(Edge[i].u) != findfather(Edge[i].v))
        {
            if(id == -1)
                id = Edge[i].u;
            merge(Edge[i].u, Edge[i].v);
            if(!vis[Edge[i].u])
            {
                if(isok[Edge[i].u] && findfather(Edge[i].u) == findfather(id))
                {
                    vis[Edge[i].u] = true;
                    ++tot;
                }
            }
            if(!vis[Edge[i].v])
            {
                if(isok[Edge[i].v] && findfather(Edge[i].v) == findfather(id))
                {
                    vis[Edge[i].v] = true;
                    ++tot;
                }
            }
            if(tot == k)
            {
                answer = Edge[i].length;
                break;
            }
        }
    }

    for(int i = 0; i < k; i++)
    {
        if(i > 0)
            printf(" ");
        printf("%I64d", answer);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100005;
int father[MAXN], n;
int x[MAXN];
bool isok[MAXN];
void init()
{
    for(int i = 0; i <= n; i++)
    {
        father[i] = i;
        isok[i] = false;
    }
}
int findfather(int son)
{
    return (father[son] == son) ? son : (father[son] = findfather(father[son]));
}
void merge(int a, int b)
{
    father[findfather(a)] = findfather(b);
}
struct line
{
    int u, v;
    ll length;
    int type;
} Edge[2 * MAXN];
bool operator < (line a, line b)
{
    return a.type < b.type || (a.type == b.type && a.length < b.length);
}
int main(void)
{
    int m, k, u, v;
    ll length;
    scanf("%d%d%d", &n, &m, &k);

    init();

    for(int i = 0; i < k; i++)
    {
        scanf("%d", &x[i]);
        isok[x[i]] = true;
    }

    int cnt = 0;
    for(int i = 0; i < m; i++)
    {
        scanf("%d%d%I64d", &u, &v, &length);
        int type;
        if(isok[u] && isok[v])
            type = 0;
        else if(!isok[u] && !isok[v])
            type = 1;
        else
            type = 2;
        Edge[cnt] = (line){u, v, length, type};
        ++cnt;
        if(u != v)
        {
            Edge[cnt] = (line){v, u, length, type};
            ++cnt;
        }
    }

    sort(Edge, Edge + cnt);

    ll answer = 0;

    for(int i = 0; i < cnt; i++)
    {
        //cout << Edge[i].u << " " << Edge[i].v << endl;
        if(findfather(Edge[i].u) != findfather(Edge[i].v))
        {
            merge(Edge[i].u, Edge[i].v);
            answer = max(answer, Edge[i].length);
        }
    }

    for(int i = 0; i < k; i++)
    {
        if(i > 0)
            printf(" ");
        printf("%I64d", answer);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100005;
int father[MAXN], n;
int x[MAXN];
bool isok[MAXN], vis[MAXN];
void init()
{
    for(int i = 0; i <= n; i++)
    {
        father[i] = i;
        isok[i] = false;
        vis[i] = false;
    }
}
int findfather(int son)
{
    return (father[son] == son) ? son : (father[son] = findfather(father[son]));
}
void merge(int a, int b)
{
    father[findfather(a)] = findfather(b);
}
struct line
{
    int u, v;
    ll length;
} Edge[2 * MAXN];
bool operator < (line a, line b)
{
    return a.length < b.length;
}
int main(void)
{
    int m, k, u, v;
    ll length;
    scanf("%d%d%d", &n, &m, &k);

    init();

    for(int i = 0; i < k; i++)
    {
        scanf("%d", &x[i]);
        isok[x[i]] = true;
    }

    int cnt = 0;
    for(int i = 0; i < m; i++)
    {
        scanf("%d%d%I64d", &u, &v, &length);
        Edge[cnt] = (line){u, v, length};
        ++cnt;
        if(u != v)
        {
            Edge[cnt] = (line){v, u, length};
            ++cnt;
        }
    }

    sort(Edge, Edge + cnt);

    ll answer = 0;
    int tot = 0;
    for(int i = 0; i < cnt; i++)
    {
        //cout << Edge[i].u << " " << Edge[i].v << endl;
        if(findfather(Edge[i].u) != findfather(Edge[i].v))
        {
            if(!vis[Edge[i].u] && isok[Edge[i].u])
            {
                vis[Edge[i].u] = true;
                ++tot;
            }
            if(!vis[Edge[i].v] && isok[Edge[i].v])
            {
                vis[Edge[i].v] = true;
                ++tot;
            }
            merge(Edge[i].u, Edge[i].v);
            if(tot == k)
            {
                answer = Edge[i].length;
                break;
            }
        }
    }

    for(int i = 0; i < k; i++)
    {
        if(i > 0)
            printf(" ");
        printf("%I64d", answer);
    }

    return 0;
}


// practice with kaiboy
import java.io.*;
import java.util.*;

public class CF1081B extends PrintWriter {
	CF1081B() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1081B o = new CF1081B(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int[] aa = new int[n];
		Integer[] ii = new Integer[n];
		for (int i = 0; i < n; i++) {
			aa[i] = n - sc.nextInt();
			ii[i] = i;
		}
		Arrays.sort(ii, (i, j) -> aa[i] - aa[j]);
		int[] bb = new int[n];
		int b = 1;
		for (int i = 0, j; i < n; i = j) {
			int a = aa[ii[i]];
			j = i + 1;
			while (j < n && aa[ii[j]] == a)
				j++;
			if ((j - i) % a != 0) {
				println("Impossible");
				return;
			}
			for (int h = i; h < j; h++)
				bb[ii[h]] = b + (h - i) / a;
			b += (j - i) / a;
		}
		println("Possible");
		for (int i = 0; i < n; i++)
			print(bb[i] + " ");
		println();
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first
#define se second

void solve(){

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

  map<int,int> M;
  for(int i=0;i<n;i++) M[a[i]]++;

  bool flag=true;

  for(int i=0;i<n;i++){
    int w=n-a[i];
    if(M[a[i]]!=w){
        flag=false;
        break;
    }
  }

  if(flag==false){
    cout<<"Imposible"<<endl;
    return;
  }

  vector<int> ans(n);

  map<int,vector<int>> ms;

  for(int i=0;i<n;i++){
    ms[a[i]].pb(i);
  }

  int ind=1;
  for(auto it=ms.begin();it!=ms.end();it++){
    for(int i=0;i<it->second.size();i++){
        ans[it->second[i]]=ind;
    }
    ind++;
  }

  cout<<"Possible"<<endl;

  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;

  return;

}

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll t;
      // cin>>t;
         t=1;
        while(t--){
            solve();
        }
       return 0;
   }


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first
#define se second

void solve(){

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

  map<int,int> M;
  for(int i=0;i<n;i++) M[a[i]]++;

  bool flag=true;

  for(int i=0;i<n;i++){
    int w=n-a[i];
    if(M[a[i]]%w!=0){
        flag=false;
        break;
    }
  }

  if(flag==false){
    cout<<"Impossible"<<endl;
    return;
  }

  bool zero=0;

  for(int i=0;i<n;i++){
    if(a[i]==0){
        zero=true;
        break;
    }
  }
  if(zero){

    cout<<"Possible"<<endl;

    for(int i=0;i<n;i++) cout<<1<<" ";
        cout<<endl;
    return;

  }

  vector<int> ans(n);

  map<int,vector<int>> ms;

  for(int i=0;i<n;i++){
    ms[a[i]].pb(i);
  }

  int ind=1;
  for(auto it=ms.begin();it!=ms.end();it++){
    int num=it->second.size();
    if(num%it->first==0){
    int ot=num/(it->first);
    int lim=ot;
    int i=0;
   while(lim<=num){
    for(i;i<lim;i++){
        ans[it->second[i]]=ind;
    }
    ind++;
    lim+=ot;
   }
   }
   else{
    for(int i=0;i<it->second.size();i++){
        ans[it->second[i]]=ind;
    }
    ind++;
   }

  }

  cout<<"Possible"<<endl;

  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;

  return;

}

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll t;
      // cin>>t;
         t=1;
        while(t--){
            solve();
        }
       return 0;
   }


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first
#define se second

void solve(){

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

  map<int,int> M;
  for(int i=0;i<n;i++) M[a[i]]++;

  bool flag=true;

  for(int i=0;i<n;i++){
    int w=n-a[i];
    if(M[a[i]]%w!=0){
        flag=false;
        break;
    }
  }

  if(flag==false){
    cout<<"Impossible"<<endl;
    return;
  }

  bool zero=0;

  for(int i=0;i<n;i++){
    if(a[i]==0){
        zero=true;
        break;
    }
  }
  if(zero){

    cout<<"Possible"<<endl;

    for(int i=0;i<n;i++) cout<<1<<" ";
        cout<<endl;
    return;

  }

  vector<int> ans(n);

  map<int,vector<int>> ms;

  for(int i=0;i<n;i++){
    ms[a[i]].pb(i);
  }

  int ind=1;
  for(auto it=ms.begin();it!=ms.end();it++){
    int num=it->second.size();
    int ot=num/(it->first);
    int lim=ot;
    int i=0;
   while(lim<=num){
    for(i;i<lim;i++){
        ans[it->second[i]]=ind;
    }
    ind++;
    lim+=ot;
   }

  }

  cout<<"Possible"<<endl;

  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;

  return;

}

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll t;
      // cin>>t;
         t=1;
        while(t--){
            solve();
        }
       return 0;
   }


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first
#define se second

void solve(){

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

  map<int,int> M;
  for(int i=0;i<n;i++) M[a[i]]++;

  bool flag=true;

  for(int i=0;i<n;i++){
    int w=n-a[i];
    if(M[a[i]]%w!=0){
        flag=false;
        break;
    }
  }

  if(flag==false){
    cout<<"Impossible"<<endl;
    return;
  }

  bool zero=0;

  for(int i=0;i<n;i++){
    if(a[i]==0){
        zero=true;
        break;
    }
  }
  if(zero){

    cout<<"Possible"<<endl;

    for(int i=0;i<n;i++) cout<<1<<" ";
        cout<<endl;

  }

  vector<int> ans(n);

  map<int,vector<int>> ms;

  for(int i=0;i<n;i++){
    ms[a[i]].pb(i);
  }

  int ind=1;
  for(auto it=ms.begin();it!=ms.end();it++){
    int num=it->second.size();
    if(num%it->first==0){
    int ot=num/(it->first);
    int lim=ot;
    int i=0;
   while(lim<=num){
    for(i;i<lim;i++){
        ans[it->second[i]]=ind;
    }
    ind++;
    lim+=ot;
   }
   }
   else{
    for(int i=0;i<it->second.size();i++){
        ans[it->second[i]]=ind;
    }
    ind++;
   }

  }

  cout<<"Possible"<<endl;

  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;

  return;

}

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll t;
      // cin>>t;
         t=1;
        while(t--){
            solve();
        }
       return 0;
   }


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first
#define se second

void solve(){

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

  map<int,int> M;
  for(int i=0;i<n;i++) M[a[i]]++;

  bool flag=true;

  for(int i=0;i<n;i++){
    int w=n-a[i];
    if(M[a[i]]%w!=0){
        flag=false;
        break;
    }
  }

  if(flag==false){
    cout<<"Impossible"<<endl;
    return;
  }

  bool zero=0;

  for(int i=0;i<n;i++){
    if(a[i]==0){
        zero=true;
        break;
    }
  }
  if(zero){

    cout<<"Possible"<<endl;

    for(int i=0;i<n;i++) cout<<1<<" ";
        cout<<endl;
    return;

  }

  vector<int> ans(n);

  map<int,vector<int>> ms;

  for(int i=0;i<n;i++){
    ms[n-a[i]].pb(i);
  }

  int ind=1;
  for(auto it=ms.begin();it!=ms.end();it++){
    int num=it->second.size();
    if(num%it->first==0){
    int ot=num/(it->first);
    int lim=ot;
    int i=0;
   while(lim<=num){
    for(i;i<lim;i++){
        ans[it->second[i]]=ind;
    }
    ind++;
    lim+=ot;
   }
   }
   else{
    for(int i=0;i<it->second.size();i++){
        ans[it->second[i]]=ind;
    }
    ind++;
   }

  }

  cout<<"Possible"<<endl;

  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;

  return;

}

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll t;
      // cin>>t;
         t=1;
        while(t--){
            solve();
        }
       return 0;
   }


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first
#define se second

void solve(){

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

  map<int,int> M;
  for(int i=0;i<n;i++) M[a[i]]++;

  int zero=0;

  for(int i=0;i<n;i++){
    if(a[i]==0){
        zero++;
    }
  }
  if(zero){

    if(zero==n){

    cout<<"Possible"<<endl;

    for(int i=0;i<n;i++) cout<<1<<" ";
        cout<<endl;
    return;}
    else{
        cout<<"Impossible"<<endl;
        return;
    }

  }

  vector<int> ans(n);

  map<int,vector<int>> ms;

  for(int i=0;i<n;i++){
    ms[n-a[i]].pb(i);
  }

  int ind=1;
  for(auto it=ms.begin();it!=ms.end();it++){
    int num=it->second.size();
    if(num%(it->first)==0){
        int lim=num;
        int cnt=0;
        while(true){
            if(cnt>=lim) break;
            int t=cnt;
            for(cnt;cnt<t+it->first;cnt++){
                ans[it->second[cnt]]=ind;
            }
            ind++;
        }
   }
   else{
    cout<<"Impossible"<<endl;
    return;

   }

  }

  cout<<"Possible"<<endl;

  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;

  return;

}

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll t;
      // cin>>t;
         t=1;
        while(t--){
            solve();
        }
       return 0;
   }


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first
#define se second

void solve(){

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

  map<int,int> M;
  for(int i=0;i<n;i++) M[a[i]]++;

  bool flag=true;

  for(int i=0;i<n;i++){
    int w=n-a[i];
    if(M[a[i]]!=w){
        flag=false;
        break;
    }
  }

  if(flag==false){
    cout<<"Impossible"<<endl;
    return;
  }

  vector<int> ans(n);

  map<int,vector<int>> ms;

  for(int i=0;i<n;i++){
    ms[a[i]].pb(i);
  }

  int ind=1;
  for(auto it=ms.begin();it!=ms.end();it++){
    for(int i=0;i<it->second.size();i++){
        ans[it->second[i]]=ind;
    }
    ind++;
  }

  cout<<"Possible"<<endl;

  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;

  return;

}

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll t;
      // cin>>t;
         t=1;
        while(t--){
            solve();
        }
       return 0;
   }


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first
#define se second

void solve(){

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

  map<int,int> M;
  for(int i=0;i<n;i++) M[a[i]]++;

  bool flag=true;

  for(int i=0;i<n;i++){
    int w=n-a[i];
    if(M[a[i]]%w!=0){
        flag=false;
        break;
    }
  }

  if(flag==false){
    cout<<"Impossible"<<endl;
    return;
  }

  vector<int> ans(n);

  map<int,vector<int>> ms;

  for(int i=0;i<n;i++){
    ms[a[i]].pb(i);
  }

  int ind=1;
  for(auto it=ms.begin();it!=ms.end();it++){
    int num=it->second.size();
    int ot=num/(it->first);
    int lim=ot;
    int i=0;
   while(lim<=num){
    for(i;i<lim;i++){
        ans[it->second[i]]=ind;
    }
    ind++;
    lim+=ot;
   }

  }

  cout<<"Possible"<<endl;

  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;

  return;

}

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll t;
      // cin>>t;
         t=1;
        while(t--){
            solve();
        }
       return 0;
   }


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define mod 998244353
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll f[100009];
ll c[100009];
int main() {
    int n;
    cin>>n;
    ll arr[n];
    ll val[n];
    for(int i = 0;i<n;i++){
        cin>>arr[i];
        f[arr[i]]++;
    }
    bool is = f[0]==n;
    if(n%2 == 0)
        is |= f[n/2] == n;
    for(int i = 1;i<=(n-1)/2;i++){
        if(f[i] == n-i && f[n-i] == i){
            is |=1;
        }
    }
    if(!is){
        cout<<"Impossible";
        return 0;
    }
    cout<<"Possible"<<endl;
    for(int i = 0;i<n;i++){
        cout<<arr[i]+1<<' ';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define mod 998244353
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll f[100009];
int main() {
    int n;
    cin>>n;
    ll arr[n];
    for(int i = 0;i<n;i++){
        cin>>arr[i];
        f[arr[i]]++;
    }
    bool is = f[0]==n || f[n-1] == n;
    if(n%2 == 0)
        is |= f[n/2] == n;
    for(int i = 1;i<=(n-1)/2;i++){
        if(f[i] == n-i && f[n-i] == i){
            is |=1;
        }
    }
    if(!is){
        cout<<"Impossible";
        return 0;
    }
    cout<<"Possible"<<endl;
    if(f[n/2] == n && n%2 == 0){
        for(int i = 0;i<n/2;i++)
            cout<<1<<' ';
        for(int i = 0;i<n/2;i++)
            cout<<2<<' ';
    }else if(f[n-1] == n){
        for(int i = 0;i<n;i++){
            cout<<i+1<<' ';
        }
    }else{
        for(int i = 0;i<n;i++){
            cout<<arr[i]+1<<' ';
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define pi (atan(1)*4)
#define mod 998244353
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int f[100005];
vector<vector<int>>v(100005);
int main(){
    int n;
    cin>>n;
    for(int i = 0;i<n;i++){
        int x;
        cin>>x;
        f[n-x]++;
        v[n-x].push_back(i);
    }
    for(int i = 1;i<=n;i++){
        if(f[i]%i != 0){
            return puts("Impossible");
        }
    }
    int arr[n];
    int x = 1;
    for(int i = 1;i<=n;i++){
        while(!v[i].empty()){
            int y = i;
            while(y--){
                arr[v[i].back()] = x;
                v[i].pop_back();
            }
            x++;
        }
    }
    printf("Possible\n");
    for(int i = 0;i<n;i++){
        cout<<arr[i]<<' ';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define mod 998244353
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll f[100009];
int main() {
    int n;
    cin>>n;
    ll arr[n];
    for(int i= 0;i<n;i++){
        cin>>arr[i];
        f[arr[i]]++;
    }
    for(int i = 0;i<n;i++){
        if(n-f[arr[i]] != arr[i]){
            cout<<"Impossible";
            return 0;
        }
    }
    cout<<"Possible"<<endl;
    for(int i = 0;i<n;i++){
        cout<<arr[i]+1<<' ';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define mod 998244353
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll f[100009];
int main() {
    int n;
    cin>>n;
    ll arr[n];
    for(int i = 0;i<n;i++){
        cin>>arr[i];
        f[arr[i]]++;
    }
    bool is = f[0]==n;
    if(n%2 == 0)
        is |= f[n/2] == n;
    for(int i = 1;i<=(n-1)/2;i++){
        if(f[i] == n-i && f[n-i] == i){
            is |=1;
        }
    }
    if(!is){
        cout<<"Impossible";
        return 0;
    }
    cout<<"Possible"<<endl;
    if(f[n/2] == n && n%2 == 0){
        for(int i = 0;i<n/2;i++)
            cout<<1<<' ';
        for(int i = 0;i<n/2;i++)
            cout<<2<<' ';
    }else{
        for(int i = 0;i<n;i++){
            cout<<arr[i]+1<<' ';
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define mod 998244353
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll f[100009];
int main() {
    int n;
    cin>>n;
    ll arr[n];
    ll val[n];
    for(int i = 0;i<n;i++){
        cin>>arr[i];
        f[arr[i]]++;
    }
    bool is = f[0]==n;
    if(n%2 == 0)
        is |= f[n/2] == n;
    for(int i = 1;i<=(n-1)/2;i++){
        if(f[i] == n-i && f[n-i] == i){
            is |=1;
        }
    }
    if(!is){
        cout<<"Impossible";
        return 0;
    }
    cout<<"Possible"<<endl;
    if(f[n/2] == n){
        for(int i = 0;i<n/2;i++)
            cout<<1<<' ';
        for(int i = 0;i<n/2;i++)
            cout<<2<<' ';
    }else{
        for(int i = 0;i<n;i++){
            cout<<arr[i]+1<<' ';
        }
    }
    return 0;
}


// i think im dropping to grey this time


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vi;

void fastio(){ios_base::sync_with_stdio(false); cin.tie(NULL);}

int size[100005], p[100005];

int find(int x) {return (x==p[x])?x:p[x]=find(p[x]);}
void merge(int i, int j) {
    if (find(i)!=find(j)) {
        int x=find(i), y=find(j);
        p[x]=p[y];
        size[y]+=size[x];
    }
}

struct cmp {
    bool operator()(ii a, ii b) {
        return a.second<b.second;
    }
};

int main () {
    fastio();

    int n; cin>>n;
    for (int i=0;i<100005;i++) {
        size[i]=1;
        p[i]=1;
    }

    vector<vector<pair<int, int>>> adjlist;
    vi arr;
    for (int i=0;i<n;i++) {
        int a; cin>>a;
        arr.push_back({i+1, n-a});
        sort(arr.begin(),arr.end(),cmp());
    }

    int hat=1, cur=0;
    vector<int> ans; ans.assign(n+1, 0);
    for (int i=0;i<n;i++) {
        cur++;
        ans[arr[i].first]=hat;
        if (i>0 and arr[i].second != arr[i-1].second and cur-1 != 0) {
            cout<<"Impossible"<<"\n";
            return 0;
        }
        if (cur == arr[i].second) {
            cur=0;
            hat++;
        }
    }

    cout<<"Possible"<<"\n";
    for (int i=1;i<=n;i++) cout<<ans[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vi;

void fastio(){ios_base::sync_with_stdio(false); cin.tie(NULL);}

struct cmp {
    bool operator()(ii a, ii b) {
        return a.second<b.second;
    }
};

int main () {
    fastio();

    int n; cin>>n;
    vector<vector<pair<int, int>>> adjlist;
    vi arr;
    for (int i=0;i<n;i++) {
        int a; cin>>a;
        arr.push_back({i+1, n-a});
    }
            sort(arr.begin(),arr.end(),cmp());
    int hat=1, cur=0;
    vector<int> ans; ans.assign(n+1, 0);
    for (int i=0;i<n;i++) {
        cur++;
        ans[arr[i].first]=hat;
        if (i>0 and arr[i].second != arr[i-1].second and cur-1 != 0) {
            cout<<"Impossible"<<"\n";
            return 0;
        }

        if (i==n-1 and cur!=arr[i].second) {
            cout<<"Impossible"<<"\n";
            return 0;
        }

        if (cur == arr[i].second) {
            cur=0;
            hat++;
        }
    }

    cout<<"Possible"<<"\n";
    for (int i=1;i<=n;i++) cout<<ans[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vi;

void fastio(){ios_base::sync_with_stdio(false); cin.tie(NULL);}

// int size[100005], p[100005];

// int find(int x) {return (x==p[x])?x:p[x]=find(p[x]);}
// void merge(int i, int j) {
//     if (find(i)!=find(j)) {
//         int x=find(i), y=find(j);
//         p[x]=p[y];
//         size[y]+=size[x];
//     }
// }

struct cmp {
    bool operator()(ii a, ii b) {
        return a.second<b.second;
    }
};

int main () {
    fastio();

    int n; cin>>n;
    // for (int i=0;i<100005;i++) {
    //     size[i]=1;
    //     p[i]=1;
    // }

    vector<vector<pair<int, int>>> adjlist;
    vi arr;
    for (int i=0;i<n;i++) {
        int a; cin>>a;
        arr.push_back({i+1, n-a});
        sort(arr.begin(),arr.end(),cmp());
    }

    int hat=1, cur=0;
    vector<int> ans; ans.assign(n+1, 0);
    for (int i=0;i<n;i++) {
        cur++;
        ans[arr[i].first]=hat;
        if (i>0 and arr[i].second != arr[i-1].second and cur-1 != 0) {
            cout<<"Impossible"<<"\n";
            return 0;
        }
        if (cur == arr[i].second) {
            cur=0;
            hat++;
        }
    }

    cout<<"Possible"<<"\n";
    for (int i=1;i<=n;i++) cout<<ans[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vi;

void fastio(){ios_base::sync_with_stdio(false); cin.tie(NULL);}

// int size[100005], p[100005];

// int find(int x) {return (x==p[x])?x:p[x]=find(p[x]);}
// void merge(int i, int j) {
//     if (find(i)!=find(j)) {
//         int x=find(i), y=find(j);
//         p[x]=p[y];
//         size[y]+=size[x];
//     }
// }

struct cmp {
    bool operator()(ii a, ii b) {
        return a.second<b.second;
    }
};

int main () {
    fastio();

    int n; cin>>n;
    // for (int i=0;i<100005;i++) {
    //     size[i]=1;
    //     p[i]=1;
    // }

    vector<vector<pair<int, int>>> adjlist;
    vi arr;
    for (int i=0;i<n;i++) {
        int a; cin>>a;
        arr.push_back({i+1, n-a});
        sort(arr.begin(),arr.end(),cmp());
    }

    int hat=1, cur=0;
    vector<int> ans; ans.assign(n+1, 0);
    for (int i=0;i<n;i++) {
        cur++;
        ans[arr[i].first]=hat;
        if (i>0 and arr[i].second != arr[i-1].second and cur-1 != 0) {
            cout<<"Impossible"<<"\n";
            return 0;
        }

        if (i==n-1 and cur!=arr[i].second) {
            cout<<"Impossible"<<"\n";
            return 0;
        }

        if (cur == arr[i].second) {
            cur=0;
            hat++;
        }
    }

    cout<<"Possible"<<"\n";
    for (int i=1;i<=n;i++) cout<<ans[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
 	int b[t];
 	int ans[t];
   set <int> s;
   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	b[i]=p;
   	ans[i]=-1;
      s.insert(p);

   }
   if(s.size()==1)
   {
      cout<<"Possible"<<endl;
      for(int i=0;i<b[0];++i)
         cout<<i+1<<" ";

      for(int i=0;i<t-b[0]-1;++i)
      {
         cout<<"1"<<" ";
      }
      return 0;
   }

   /*while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	if(y==0) {
   		ans.push_back(1);
   		continue;
   	}
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }*/
   int hat=1;
   for(int i=0;i<t;++i)
   {
   	if(ans[i]==-1)
   	{

   	int y=t-b[i]-1;
   	if(y==0)
   	{
   		ans[i]=hat;
   		hat++;
   		continue;
   	}ans[i]=hat;
   	int p=0;
   	for(int j=0;j<t;++j)
   	{
   		if(b[j]==b[i] && ans[j]==-1)
   		{
   			p++;
   			ans[j]=hat;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else{
   		hat++;
   	}
   }
   else continue;
}cout<<"Possible"<<endl;
for(int i=0;i<t;++i) cout<<ans[i]<<" ";
  /* cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }*/
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
  int b[t];
  int ans[t];
   for(int i=0;i<t;++i) {
    int p;
    cin>>p;
    b[i]=p;
    ans[i]=-1;

   }

   /*while(v.size()!=0)
   {
    int y=t-v[0]-1;
    int p=0;
    int x=v[0];
    v.erase(v.begin());
    if(y==0) {
      ans.push_back(1);
      continue;
    }
    for(int j=0;j<v.size();++j)
    {

      if(v[j]==x)
      {
        p++;
        v.erase(v.begin()+j);j--;
      }
    }
    if(p!=y)
    {
      cout<<"Impossible"<<endl;
      return 0;
    }
    else
    {

      ans.push_back(p+1);
    }
    hat++;
   }*/
   int hat=1;
   for(int i=0;i<t;++i)
   {
    if(ans[i]==-1)
    {

    int y=t-b[i]-1;
    if(y==0)
    {
      ans[i]=hat;
      hat++;
      continue;
    }ans[i]=hat;
    int p=0;
    for(int j=0;j<t;++j)
    {
      if(b[j]==b[i] && ans[j]==-1)
      {
        p++;
        ans[j]=hat;
      }
    }
    if(p!=y)
    {
      cout<<"Impossible"<<endl;
      return 0;
    }
    else{
      hat++;
    }
   }
   else continue;
}cout<<"Possible"<<endl;
for(int i=0;i<t;++i) cout<<ans[i]<<" ";
  /* cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
    for(int j=0;j<ans[i];++j)
    {
      cout<<i+1<<" ";
    }
   }*/
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
   vector<int> v;
   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	v.push_back(p);
   }
   	vector<int> ans;
   int  hat=1;
   while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }
   cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
 	int b[t];
 	int ans[t];
   set <int> s;
   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	b[i]=p;
   	ans[i]=-1;
      s.insert(p);

   }
   if(s.size()==1)
   {

     int y=t-b[0];
     if(y*b[0]==t)
     {
       cout<<"Possible"<<endl;
       int hat=1;
       for(int j=0;j<b[0];++j)
       {
       for(int i=0;i<y;++i)
       {
         cout<<hat<<" ";

       }
       hat++;
    }

     }
     else
     {
      cout<<"Impossible";
     }
     return 0;
   }

   /*while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	if(y==0) {
   		ans.push_back(1);
   		continue;
   	}
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }*/
   int hat=1;
   for(int i=0;i<t;++i)
   {
   	if(ans[i]==-1)
   	{

   	int y=t-b[i]-1;
   	if(y==0)
   	{
   		ans[i]=hat;
   		hat++;
   		continue;
   	}ans[i]=hat;
   	int p=0;
   	for(int j=0;j<t;++j)
   	{
   		if(b[j]==b[i] && ans[j]==-1)
   		{
   			p++;
   			ans[j]=hat;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else{
   		hat++;
   	}
   }
   else continue;
}cout<<"Possible"<<endl;
for(int i=0;i<t;++i) cout<<ans[i]<<" ";
  /* cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }*/
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
 	int b[t];
 	int ans[t];

   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	b[i]=p;
   	ans[i]=-1;

   }
   /*if(s.size()==1 && b[0]>0)
   {

     int y=t-b[0];
     if(y*b[0]==t)
     {
       cout<<"Possible"<<endl;
       int hat=1;
       for(int j=0;j<b[0];++j)
       {
       for(int i=0;i<y;++i)
       {
         cout<<hat<<" ";

       }
       hat++;
    }

     }
     else
     {
      cout<<"Impossible";
     }
     return 0;
   }

   while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	if(y==0) {
   		ans.push_back(1);
   		continue;
   	}
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }*/
   int hat=1;
   for(int i=0;i<t;++i)
   {
   	if(ans[i]==-1)
   	{

   	int y=t-b[i]-1;
   	if(y==0)
   	{
   		ans[i]=hat;
   		hat++;
   		continue;
   	}ans[i]=hat;
   	int p=0;
   	for(int j=0;j<t;++j)
   	{
         if(ans[j]!=-1) continue;
   		if(b[j]==b[i])
   		{
   			p++;
   			ans[j]=hat;
            if(p==y) break;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else{
   		hat++;
   	}
   }
   else continue;
}cout<<"Possible"<<endl;
for(int i=0;i<t;++i) cout<<ans[i]<<" ";
  /* cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }*/
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef long long int ll;
ll mod=1e9+7;
ll power(ll a,ll b)
{
	if(b==0) return 1;
	else if(b%2==0)
	{
		return power(a*a%mod,b/2);
	}
	else return (a*power(a*a%mod,b/2))%mod;
}
vector<int> v[100001];
int root(int a[],int i)
{
    while(a[i]!=i)
    {
        a[i]=a[a[i]];
        i=a[i];
    }
    return i;
}
void un(int a[],int size[],int A,int B)
{
    int root1=root(a,A);
    int root2=root(a,B);

    if(size[root1]<size[root2])
    {
        a[root1]=a[root2];
        size[root2]=size[root2]+size[root1];
    }
    else
    {
        a[root2]=a[root1];
        size[root1]=size[root2]+size[root1];
    }
}

int main()
{
     IOS
     int n;
     cin>>n;
     int a[n];
     vector<pair<int,int>>v;
     for(int i=0;i<n;++i)
     	{ cin>>a[i];
     		if(a[i]>n-1)
     		{
     			cout<<"IMPOSSIBLE"<<endl;
     			return 0;
     		}

     			a[i]=n-a[i]-1;
     			v.push_back(make_pair(a[i],i));
     	}
     	sort(v.begin(),v.end());

     	int hat=1;
     	vector<pair<int,int>>ans;

     	for(int i=0;i<n;++i)
     	{
     		ans.push_back(make_pair(v[i].second,hat));
     		for(int j=i+1;j<=i+v[i].first;++j)
     		{
     			if(v[j].first!=v[i].first)
     			{
     				cout<<"Impossible"<<endl;
     				return 0;
     			}
     			else
     			{
     				ans.push_back(make_pair(v[j].second,hat));
     			}
     		}
     		i=i+v[i].first;
     		hat++;
     	}
     	cout<<"Possible"<<endl;
     	sort(ans.begin(),ans.end());
     	for(int i=0;i<n;++i) cout<<ans[i].second<<" ";

}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
 	int b[t];
 	int ans[t];
   set <int> s;
   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	b[i]=p;
   	ans[i]=-1;
      s.insert(p);

   }
   /*if(s.size()==1 && b[0]>0)
   {

     int y=t-b[0];
     if(y*b[0]==t)
     {
       cout<<"Possible"<<endl;
       int hat=1;
       for(int j=0;j<b[0];++j)
       {
       for(int i=0;i<y;++i)
       {
         cout<<hat<<" ";

       }
       hat++;
    }

     }
     else
     {
      cout<<"Impossible";
     }
     return 0;
   }

   while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	if(y==0) {
   		ans.push_back(1);
   		continue;
   	}
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }*/
   int hat=1;
   for(int i=0;i<t;++i)
   {
   	if(ans[i]==-1)
   	{

   	int y=t-b[i]-1;
   	if(y==0)
   	{
   		ans[i]=hat;
   		hat++;
   		continue;
   	}ans[i]=hat;
   	int p=0;
   	for(int j=0;j<t;++j)
   	{
   		if(b[j]==b[i] && ans[j]==-1)
   		{
   			p++;
   			ans[j]=hat;
            if(p==y) break;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else{
   		hat++;
   	}
   }
   else continue;
}cout<<"Possible"<<endl;
for(int i=0;i<t;++i) cout<<ans[i]<<" ";
  /* cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }*/
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef long long int ll;
ll mod=1e9+7;
ll power(ll a,ll b)
{
	if(b==0) return 1;
	else if(b%2==0)
	{
		return power(a*a%mod,b/2);
	}
	else return (a*power(a*a%mod,b/2))%mod;
}
vector<int> v[100001];
int root(int a[],int i)
{
    while(a[i]!=i)
    {
        a[i]=a[a[i]];
        i=a[i];
    }
    return i;
}
void un(int a[],int size[],int A,int B)
{
    int root1=root(a,A);
    int root2=root(a,B);

    if(size[root1]<size[root2])
    {
        a[root1]=a[root2];
        size[root2]=size[root2]+size[root1];
    }
    else
    {
        a[root2]=a[root1];
        size[root1]=size[root2]+size[root1];
    }
}

int main()
{
     IOS
     int n;
     cin>>n;
     int a[n];
     vector<pair<int,int>>v;
     for(int i=0;i<n;++i)
     	{ cin>>a[i];
     		if(a[i]>n-1)
     		{
     			cout<<"IMPOSSIBLE"<<endl;
     			return 0;
     		}

     			a[i]=n-a[i]-1;
     			v.push_back(make_pair(a[i],i));
     	}
     	sort(v.begin(),v.end());

     	int hat=1;
     	vector<pair<int,int>>ans;

     	for(int i=0;i<n;++i)
     	{
     		ans.push_back(make_pair(v[i].second,hat));
     		for(int j=i+1;j<=i+a[i];++j)
     		{
     			if(v[j].first!=v[i].first)
     			{
     				cout<<"Impossible"<<endl;
     				return 0;
     			}
     			else
     			{
     				ans.push_back(make_pair(v[j].second,hat));
     			}
     		}
     		i=i+v[i].first;
     		hat++;
     	}
     	cout<<"Possible"<<endl;
     	sort(ans.begin(),ans.end());
     	for(int i=0;i<n;++i) cout<<ans[i].second<<" ";

}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
 	int b[t];
 	int ans[t];
   set <int> s;
   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	b[i]=p;
   	ans[i]=-1;
      s.insert(p);

   }
   if(s.size()==1)
   {
      cout<<"Possible"<<endl;

      for(int i=0;i<t-b[0]-1;++i)
      {
         cout<<"1"<<" ";
      }
      for(int i=0;i<=b[0];++i)
         cout<<i+1<<" ";

      return 0;
   }

   /*while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	if(y==0) {
   		ans.push_back(1);
   		continue;
   	}
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }*/
   int hat=1;
   for(int i=0;i<t;++i)
   {
   	if(ans[i]==-1)
   	{

   	int y=t-b[i]-1;
   	if(y==0)
   	{
   		ans[i]=hat;
   		hat++;
   		continue;
   	}ans[i]=hat;
   	int p=0;
   	for(int j=0;j<t;++j)
   	{
   		if(b[j]==b[i] && ans[j]==-1)
   		{
   			p++;
   			ans[j]=hat;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else{
   		hat++;
   	}
   }
   else continue;
}cout<<"Possible"<<endl;
for(int i=0;i<t;++i) cout<<ans[i]<<" ";
  /* cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }*/
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
 	int b[t];
 	int ans[t];
   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	b[i]=p;
   	ans[i]=-1;

   }

   /*while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	if(y==0) {
   		ans.push_back(1);
   		continue;
   	}
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }*/
   int hat=1;
   for(int i=0;i<t;++i)
   {
   	if(ans[i]==-1)
   	{

   	int y=t-b[i]-1;
   	if(y==0)
   	{
   		ans[i]=hat;
   		hat++;
   		continue;
   	}ans[i]=hat;
   	int p=0;
   	for(int j=0;j<t;++j)
   	{
   		if(b[j]==b[i] && ans[j]==-1)
   		{
   			p++;
   			ans[j]=hat;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else{
   		hat++;
   	}
   }
   else continue;
}cout<<"Possible"<<endl;
for(int i=0;i<t;++i) cout<<ans[i]<<" ";
  /* cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }*/
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
 	int b[t];
 	int ans[t];
   set <int> s;
   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	b[i]=p;
   	ans[i]=-1;
      s.insert(p);

   }
   if(s.size()==1 && b[0]>0)
   {

     int y=t-b[0];
     if(y*b[0]==t)
     {
       cout<<"Possible"<<endl;
       int hat=1;
       for(int j=0;j<b[0];++j)
       {
       for(int i=0;i<y;++i)
       {
         cout<<hat<<" ";

       }
       hat++;
    }

     }
     else
     {
      cout<<"Impossible";
     }
     return 0;
   }

   /*while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	if(y==0) {
   		ans.push_back(1);
   		continue;
   	}
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }*/
   int hat=1;
   for(int i=0;i<t;++i)
   {
   	if(ans[i]==-1)
   	{

   	int y=t-b[i]-1;
   	if(y==0)
   	{
   		ans[i]=hat;
   		hat++;
   		continue;
   	}ans[i]=hat;
   	int p=0;
   	for(int j=0;j<t;++j)
   	{
   		if(b[j]==b[i] && ans[j]==-1)
   		{
   			p++;
   			ans[j]=hat;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else{
   		hat++;
   	}
   }
   else continue;
}cout<<"Possible"<<endl;
for(int i=0;i<t;++i) cout<<ans[i]<<" ";
  /* cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }*/
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
 	int b[t];
 	int ans[t];

   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	b[i]=p;
   	ans[i]=-1;

   }
   /*if(s.size()==1 && b[0]>0)
   {

     int y=t-b[0];
     if(y*b[0]==t)
     {
       cout<<"Possible"<<endl;
       int hat=1;
       for(int j=0;j<b[0];++j)
       {
       for(int i=0;i<y;++i)
       {
         cout<<hat<<" ";

       }
       hat++;
    }

     }
     else
     {
      cout<<"Impossible";
     }
     return 0;
   }

   while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	if(y==0) {
   		ans.push_back(1);
   		continue;
   	}
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }*/
   int hat=1;
   for(int i=0;i<t;++i)
   {
   	if(ans[i]==-1)
   	{

   	int y=t-b[i]-1;
   	/*if(y==0)
   	{
   		ans[i]=hat;
   		hat++;
   		continue;
   	}*/ans[i]=hat;
   	int p=0;
   	for(int j=0;j<t;++j)
   	{
         if(ans[j]!=-1) continue;
   		if(b[j]==b[i])
   		{
   			p++;
   			ans[j]=hat;
            if(p==y) break;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else{
   		hat++;
   	}
   }
   else continue;
}cout<<"Possible"<<endl;
for(int i=0;i<t;++i) cout<<ans[i]<<" ";
  /* cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }*/
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
   vector<int> v;
   for(int i=0;i<t;++i) {
   	int p;
   	cin>>p;
   	v.push_back(p);
   }
   	vector<int> ans;
   int  hat=1;
   while(v.size()!=0)
   {
   	int y=t-v[0]-1;
   	int p=0;
   	int x=v[0];
   	v.erase(v.begin());
   	if(y==0) {
   		ans.push_back(1);
   		continue;
   	}
   	for(int j=0;j<v.size();++j)
   	{

   		if(v[j]==x)
   		{
   			p++;
   			v.erase(v.begin()+j);j--;
   		}
   	}
   	if(p!=y)
   	{
   		cout<<"Impossible"<<endl;
   		return 0;
   	}
   	else
   	{

   		ans.push_back(p+1);
   	}
   	hat++;
   }
   cout<<"Possible"<<endl;
   for(int i=0;i<ans.size();++i)
   {
   	for(int j=0;j<ans[i];++j)
   	{
   		cout<<i+1<<" ";
   	}
   }
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

typedef long long int ll;
ll mod=1e9+7;
ll power(ll a,ll b)
{
	if(b==0) return 1;
	else if(b%2==0)
	{
		return power(a*a%mod,b/2);
	}
	else return (a*power(a*a%mod,b/2))%mod;
}
vector<int> v[100001];
int root(int a[],int i)
{
    while(a[i]!=i)
    {
        a[i]=a[a[i]];
        i=a[i];
    }
    return i;
}
void un(int a[],int size[],int A,int B)
{
    int root1=root(a,A);
    int root2=root(a,B);

    if(size[root1]<size[root2])
    {
        a[root1]=a[root2];
        size[root2]=size[root2]+size[root1];
    }
    else
    {
        a[root2]=a[root1];
        size[root1]=size[root2]+size[root1];
    }
}

int main()
{
     IOS
     int n;
     cin>>n;
     int a[n];
     for(int i=0;i<n;++i)
     	{ cin>>a[i];
     		if(a[i]>n-1)
     		{
     			cout<<"IMPOSSIBLE"<<endl;
     			return 0;
     		}

     			a[i]=n-a[i]-1;
     	}
     	sort(a,a+n);

     	int hat=1;
     	int ans[n];
     	for(int i=0;i<n;++i)
     	{
     		ans[i]=hat;
     		for(int j=i+1;j<=i+a[i];++j)
     		{
     			if(a[j]!=a[i])
     			{
     				cout<<"Impossible"<<endl;
     				return 0;
     			}
     			else
     			{
     				ans[j]=ans[i];
     			}
     		}
     		i=i+a[i];
     		hat++;
     	}
     	cout<<"Possible"<<endl;
     	for(int i=0;i<n;++i) cout<<ans[i]<<" ";

}


#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long

int32_t main()
{
	FastIO;
	int n,cnt=0,col=1;
	cin>>n;
	int b[n+1],a[n+1],h[n+5]={};
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		a[i]=n-a[i];
	}

	{
		for(int i=1; i<=n; i++)
		{
			cnt=a[i];
			int j=i,curr=a[i],visit=0;
			if(h[i]==1)
			    continue;
//			cout<<i<<"- ";
			while(cnt>0 && j<=n)
			{
//			    cout<<j<<" ";
				if(a[j]==curr)
				{
				    visit=1;
					b[j]=col;
					h[j]=1;
					cnt--;
				}
				j++;
			}
//            cout<<": ";
//			cout<<cnt<<" ";
//			cout<<"\n";
			if(cnt>0)
			{
			    cout<<"Impossible";
			    return 0;
			}
			if(visit==1)
    			col++;
		}

        cout<<"Possible\n";
		for(int i=1; i<=n; i++)
			cout<<b[i]<<" ";
	}

}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main()
{
    FastIO;
    int n;
    cin>>n;
    int a,b[n+1], ans=1;
    vector <pair <int, int> > v;
    for(int i=0; i<n; i++)
    {
    	cin>>a;
    	v.push_back({a, i});
    }

    sort(v.begin(), v.end());

	b[n] = -1;
	int c = 1;
    for(int i=0; i<n; )
    {
    	int t = n-v[i].first;
    	int f = v[i].first;
    	while(t--)
    	{
    		if(v[i].first != f)
    		{
    			ans = 0;
    			break;
    		}
    		b[v[i].second] = c;
    		i++;
    	}
    	c++;
    }

    if(ans == 0)
    	cout<<"Impossible";
    else
    {
    	cout<<"Possible\n";
    	for(int i=0; i<n; i++)
    		cout<<b[i]<<" ";
    }
}