#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct school{
	int quota;
	int fact;
	int ge;
	int gi;
	vector<int> admit;
};

struct student{
	int id;
	float ge;
	float gi;
	int choose[5];
};

bool cmp1(student a, student b){
	return a.ge > b.ge ;
}

bool cmp2(student a, student b){
	return (a.ge+a.gi)/2 > (b.ge+b.gi)/2 ;
}

int main(){
	int n, m, k;
	while( cin >> n >> m >> k ){
		school sch[m];
		student stu[n];
		for(int i=0; i<m; i++){
			cin >> sch[i].quota;
			sch[i].fact = 0;
		}
			
		for(int i=0; i<n; i++){
			cin >> stu[i].ge >> stu[i].gi;
			stu[i].id = i;
			for(int j=0; j<k; j++){
				cin >> stu[i].choose[j];
			}	
		}
		
		// 稳定排序 
		stable_sort(stu, stu+n, cmp1);
		stable_sort(stu, stu+n, cmp2);
		
		// 分高的学生先选学校 
		for(int i=0; i<n; i++){
			for(int j=0; j<k; j++){
				if( sch[ stu[i].choose[j] ].quota > 0 ){
					sch[ stu[i].choose[j] ].quota--;
					sch[stu[i].choose[j]].ge = stu[i].ge;
					sch[stu[i].choose[j]].gi = stu[i].gi;
					sch[stu[i].choose[j]].admit.push_back(stu[i].id);
					break;
				}
				else{
					if( sch[stu[i].choose[j]].ge==stu[i].ge
					&&sch[stu[i].choose[j]].gi==stu[i].gi){
						sch[stu[i].choose[j]].admit.push_back(stu[i].id);
						break;
					}
				}
			}
		}
		// 对每个学校的录取名单进行排序 
		for(int i=0; i<m; i++){
			int x = sch[i].admit.size();
			for(int j=0; j<x-1; j++){
				for(int k=0; k<x-1; k++){
					if( sch[i].admit[k] > sch[i].admit[k+1]){
						int temp = sch[i].admit[k];
						sch[i].admit[k] = sch[i].admit[k+1];
						sch[i].admit[k+1] = temp;
					}
				}
			}
		}
		// 输出结果 
		for(int i=0; i<m; i++){
			for(int j=0; j<sch[i].admit.size(); j++){
				if( j == sch[i].admit.size()-1 ){
					cout << sch[i].admit[j];
				}
				else{
					cout << sch[i].admit[j] << " ";
				}
			}
			cout << endl;
		}
	}
	
	return 0;
}