#include <iostream>
#include <set>
#include <vector>
using namespace std;
struct Good{//商品结构体
int type;
int id;
int score;
};
struct Del{//删除的物品
int type;
int id;
};
int m,n;
bool operator <(const Good& x,const Good& y){
if(x.score!=y.score)
return x.score>y.score;
else{
if(x.type!=y.type)
return x.type<y.type;
else
return x.id<y.id;
}
}
bool operator <(const Del& x,const Del& y){
if(x.type!=y.type)
return x.type<y.type;
else
return x.id<y.id;
}
set<Good> good;
set<Del> del;
int main()
{
cin>>m>>n;
for(int i=0;i<n;i++){
Good temp;
cin>>temp.id>>temp.score;
for(int j=0;j<m;j++){
temp.type=j;
good.insert(temp);
}
}
int oper;
cin>>n;
while(n--){
cin>>oper;
if(oper==1){
Good temp;
cin>>temp.type>>temp.id>>temp.score;
good.insert(temp);
}
else if(oper==2){
Del tmp;
cin>>tmp.type>>tmp.id;
del.insert(tmp);
}
else if(oper==3){
int k,type_k[55]={0};
vector<int> vec[55];
cin>>k;
for(int i=0;i<m;i++)
cin>>type_k[i];
for(set<Good>::iterator it=good.begin();it!=good.end()&&k>0;){
if(type_k[(*it).type]>0){//该类商品还能再接着拿
Del tmp;
tmp.id=(*it).id,tmp.type=(*it).type;
if(del.find(tmp)!=del.end()){//这个商品被删除了
good.erase(it++);//it++不能单独写出来,erase之后原来的it指向NULL再++就会指向未知的地方
}
else{
vec[(*it).type].push_back((*it).id);
k--;
type_k[(*it).type]--;
it++;
}
}
else
it++;
}
//输出
for(int i=0;i<m;i++){
if(vec[i].size()>0){
for(int j=0;j<vec[i].size();j++){
cout<<vec[i][j];
if(j!=vec[i].size()-1)
cout<<" ";
}
cout<<endl;
}
else
cout<<"-1\n";
}
}
}
return 0;
}