#include <cstdio>
#include <set>
#include <unordered_map>
#include <algorithm>
using namespace std;
typedef long long ll;
ll inf = (ll)1e9;
//关键点,用一个整数表示第几类编号为几的商品,方便处理排序,注意int有可能越界
struct Node {
ll type;
ll id;
int score;
Node(ll type, ll id, int score): type(type), id(id), score(score) {}
bool operator < (const Node& n1) const {
if(n1.score != score) return score > n1.score;
else if(n1.type != type) return type < n1.type;
else return id < n1.id;
}
};
unordered_map<ll, set<Node>::iterator> ma;
int num[55];
int main() {
int m, n; scanf("%d %d", &m, &n);
set<Node> s;
for(int i = 1; i <= n; i ++) {
ll id;
int score; scanf("%lld %d", &id, &score);
for(ll j = 0; j < m; j ++) {
ll temp = j * inf + id;
ma[temp] = s.insert(Node(j, id, score)).first; //s.insert()返回 pair<set<Node>::iterator, bool>
}
}
int op; scanf("%d", &op);
while(op --) {
int t; scanf("%d", &t);
if(t == 3) {
vector<vector<int> > ans(m); //用set报错暂时还没想明白
int k; scanf("%d", &k);
for(int i = 0; i < m; i ++) {
scanf("%d", &num[i]);
}
for(auto& u : s) {
if(ma.count(u.type * inf + u.id) && num[u.type]) {
num[u.type] --;
k --;
ans[u.type].push_back(u.id);
if(k == 0) break;
}
}
for(int i = 0; i < m; i ++) {
if(!ans[i].empty()) {
int first = ans[i][0];
for(auto& p : ans[i]) {
if(p != first) printf(" %d", p);
else printf("%d", p);
}
printf("\n");
}else {
printf("-1\n");
}
}
}else if(t == 2) {
ll type, id; scanf("%lld %lld", &type, &id);
ll temp = type * inf + id;
s.erase(ma[temp]);
ma.erase(temp);
}else {
ll type, id;
int score; scanf("%lld %lld %d", &type, &id, &score);
ll temp = type * inf + id;
ma[temp] = s.insert(Node(type, id, score)).first;
}
}
return 0;
}