#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<map>
using namespace std;
struct Node
{
int hp,ak;
}p[2][8];
int main()
{
int n;
for(int i=1;i<=7;i++)
{
p[0][i].hp = -1;
p[1][i].hp = -1;
p[0][i].ak = -1;
p[1][i].ak = -1;
}
p[0][0].hp = 30;
p[0][0].ak = 0;
p[1][0].hp = 30;
p[1][0].ak = 0;
cin>>n;
int ct[2]={1,1},time=0;
string str;
for(int i=1;i<=n;i++)
{
//cout<<"dd"<<endl;
cin>>str;
if(str == "summon")
{
int pos,hp,ak;
cin>>pos>>ak>>hp;
if(ct[time]==8) continue;
for(int j=ct[time]+1;j>pos;j--)
{
p[time][j] = p[time][j-1];
//cout<<p[time][j].hp<<" "<<p[time][j-1].hp<<"后面替代前面"<<endl;
}
p[time][pos].hp = hp;
p[time][pos].ak = ak;
ct[time]++;
}
else if(str == "attack")
{
int atk,def;
cin>>atk>>def;
p[time][atk].hp = p[time][atk].hp - p[(time+1)%2][def].ak; //己方随从
p[(time+1)%2][def].hp = p[(time+1)%2][def].hp - p[time][atk].ak; //敌方随从或玩家
//cout<<p[time][atk].hp<<" "<< p[(time+1)%2][def].hp<<endl;
if(p[(time+1)%2][def].hp<=0 && def==0) //敌方英雄死亡
{
if(time%2==0) cout<<"1"<<endl; //先手玩家胜
else cout<<"-1"<<endl;
cout<<p[0][0].hp<<endl;
for(int j=1;j<=7;j++)
{
if(p[0][j].hp > 0)
{
cout<<j<<" "<<p[0][j].hp<<endl;
}
}
cout<<p[1][0].hp<<endl;
for(int j=1;j<=7;j++)
{
if(p[1][j].hp > 0)
{
cout<<j<<" "<<p[1][j].hp<<endl;
}
}
break;
}
if(p[time][atk].hp<=0) //己方随从死亡 前移
{
ct[time]--;
for(int j=atk;j<ct[time];j++)
{
p[time][j] = p[time][j+1];
}
p[time][ct[time]].hp = -1; //前移 然后清空末尾项 后移然后补足首项
}
if(p[(time+1)%2][def].hp<=0 && def!=0) //敌方随从死亡
{
ct[(time+1)%2]--;
for(int j=def;j<ct[(time+1)%2];j++)
{
p[(time+1)%2][j] = p[(time+1)%2][j+1];
}
p[(time+1)%2][ct[(time+1)%2]].hp = -1; //前移 然后清空末尾项 后移然后补足首项
}
}
else if(str == "end")
{
time = (time+1)%2;
}
}
if(p[0][0].hp>0 && p[1][0].hp>0)
{
cout<<"0"<<endl;
cout<<p[0][0].hp<<endl;
for(int j=1;j<=7;j++)
{
if(p[0][j].hp > 0)
{
cout<<j<<" "<<p[0][j].hp<<endl;
}
}
cout<<p[1][0].hp<<endl;
for(int j=1;j<=7;j++)
{
if(p[1][j].hp > 0)
{
cout<<j<<" "<<p[1][j].hp<<endl;
}
}
}
return 0;
}