public static void main(String[]args){
		String in="data/p1.in", out="data/p1.out";
		try(Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(in)))));
				PrintWriter bw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(out)))));) {
			int a;
			String t=sc.nextLine();
			a=Integer.parseInt(t.split("\\s+")[0]);
			String[] s=new String[a];
			for (int i=0;i<a;++i) s[i]=sc.nextLine().trim();
			t=sc.nextLine();
			Str[] rel=process(s, t);
			int[] iid=new int[a];
			for (int i=0;i<a;++i) iid[rel[i].id]=i;
			String p="Person #";
			Map<Integer, Integer> map=new HashMap<>();
			for (int i=0;i<a;++i)map.put(i, rel[i].id);
			int[] A=new int[a];
			for (int i=0,k=1;i<a;++i) {
				if (i==0)A[iid[i]]=k;
				else {
					if (rel[iid[i-1]].v==rel[iid[i]].v) A[iid[i]]=k;
					else A[iid[i]]=++k;
				}
			}	
			for (int i=0;i<a;++i) {
				bw.println(p+Integer.toString(i)+": "+(A[i])+".");
			}
		} catch(IOException e) {
			e.printStackTrace();
		}
	}