#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > output;
const int N = 40010;
int quota[110];
struct Applicant {
int id, Ge, Gi, rank, select[10];
double final; // 这里要注意把final定义为double类型,要不然会出错
bool operator <(const Applicant &w) const {
if (final != w.final) return final > w.final;
else if (Ge != w.Ge) return Ge > w.Ge;
else return Gi > w.Gi;
}
} app[N];
struct RES {
vector<int>applicant;
} res[110];
int main() {
// freopen("input.txt", "r", stdin);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < m; i++) scanf("%d", "a[i]);
for (int i = 0; i < n; i++) {
scanf("%d %d", &app[i].Ge, &app[i].Gi);
app[i].final = (app[i].Ge + app[i].Gi) * 0.1 / 2;
app[i].id = i;
for (int j = 0; j < k; j++) scanf("%d", &app[i].select[j]);
}
sort(app, app + n);
app[0].rank = 1;
int cnt = 1;
for (int i = 1; i < n; i++) {
cnt++;
if (app[i].final < app[i - 1].final) {
app[i].rank = cnt;
} else {
if (app[i].Ge < app[i - 1].Ge) {
app[i].rank = cnt;
} else {
if (app[i].Gi < app[i - 1].Gi) {
app[i].rank = cnt;
} else {
app[i].rank = app[i - 1].rank;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
int choice = app[i].select[j]; // choice表示选择学校的编号
if (quota[choice] > 0) {
quota[choice]--;
res[choice].applicant.push_back(i);
break;
} else {
int target_rank = app[res[choice].applicant.back()].rank;
if (app[i].rank == target_rank) {
res[choice].applicant.push_back(i);
break;
}
}
}
}
for (int i = 0; i < m; i++) {
for (auto x : res[i].applicant) {
output.push(app[x].id);
}
while (!output.empty()) {
cout << output.top() << " ";
output.pop();
}
puts("");
}
return 0;
}