#include <bits/stdc++.h>
using namespace std;
using ll = long long;
deque<pair<int,int>> snake;
set<pair<int,int>>s;
bool moveSnake(int dir) {
// TODO: 请实现移动逻辑
set<pair<int,int>>s;//检查碰撞的临时容器
pair<int,int>new_head=snake.back();
if(dir==1){
new_head.second++;
}
if(dir==2){
new_head.second--;
}
if(dir==3){
new_head.first--;
}
if(dir==4){
new_head.first++;
}//计算蛇头
snake.push_back(new_head);//加新头
snake.pop_front();//删尾巴
for(int i=0;i<snake.size();i++){
s.insert(snake[i]);
}//碰撞检测 存在重复set会更小
if(s.size()!=snake.size()){
return true;
}
return false;
}
bool eatSnake(int dir) {
// TODO: 请实现吃果子生长逻辑
set<pair<int,int>>s;//检查碰撞的临时容器
pair<int,int>new_head=snake.back();
if(dir==1){
new_head.second++;
}
if(dir==2){
new_head.second--;
}
if(dir==3){
new_head.first--;
}
if(dir==4){
new_head.first++;
}//计算蛇头
snake.push_back(new_head);//加新头
// snake.pop_front();//删尾巴
for(int i=0;i<snake.size();i++){
s.insert(snake[i]);
}//碰撞检测 存在重复set会更小
if(s.size()!=snake.size()){
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
snake.clear();
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
snake.emplace_back(x, y);
}
for (int i = 0; i < q; i++) {
int op, dir;
cin >> op >> dir;
bool collision = (op == 1 ? moveSnake(dir) : eatSnake(dir));
if (collision) {
cout << -1 << '\n';
return 0;
} else {
for (auto it = snake.rbegin(); it != snake.rend(); ++it) {
cout << it->first << ' ' << it->second << '\n';
}
}
}
return 0;
}