/* Author : RISHAV GOYAL */

#include <bits/stdc++.h>
using namespace std;

#define LL long long int
#define UL unsigned long long int

#define imax INT_MAX
#define imin INT_MIN
#define LLmax LLONG_MAX
#define LLmin LLONG_MIN

#define FOR(i,a,b) for(int i= (int)a; i<= (int)b; i++)
#define rep(i,n) for(int i= int(1); i<= (int)n; i++)
#define FORd(i,a,b,d) for(int i=(int)a; i<= (int)b; i+=(int)d)

#define pr() printf("Reached here 1...\n");
#define pr1() printf("Reached here 2...\n");

#define CLR(a) memset(a,0,sizeof(a));
#define SET(a) memset(a,-1,sizeof(a));

#define str strlen
#define pb(x) push_back(x)
#define mp make_pair
#define ii pair<int,int>
#define ll pair<LL,LL>

#define F first
#define S second
#define gcd(a,b) __gcd(a,b)

#define mod int(1e9 + 7)
#define MAX int(1e5 + 10)

#define si(a) scanf("%d",&a);

#define VI vector<int>
#define VL vector<LL>
#define VS vector<string>
#define VC vector<char>

LL powmod(LL a,int b,int n){LL rm=1;while (b){if (b % 2) { rm = (rm * a) % n; }a = (a * a) % n;b /= 2;}return rm;}

map<int,int> hash;

int seg[4*MAX][6]={0},segct[4*MAX]={0},Q,k=0,a[MAX],q[MAX];
char s[MAX][5];

void add(int n,int it,int f,int q){
	if( it == f){
		segct[n] = 1;
		CLR(seg[n]);
		seg[n][3] = a[f];
		return ;
	}
	int m = ( it + f)/2;
	if( q <= m) add(n*2,it,m,q);
	else add(n*2+1,m+1,f,q);
	segct[n] = segct[n*2] + segct[n*2+1];

	for(int i=1;i<=5;++i){
		int st = i + segct[n*2] - 1;
		st %= 5;
		st++;
		seg[n][i] = seg[n*2][i] + seg[n*2+1][st];
	}

}

void remove(int n,int it,int f,int q){
	if(it == f){
		CLR(seg[n]); segct[n]=0;
		return ;
	}
	int m = ( it + f)/2;
	if( q <= m) remove(n*2,it,m,q);
	else remove(n*2+1,m+1,f,q);
	segct[n] = segct[n*2] + segct[n*2+1];

	for(int i=1;i<=5;++i){
		int st = i + segct[n*2] - 1;
		st %= 5;
		st++;
		seg[n][i] = (seg[n*2][i] + seg[n*2+1][st]) % mod;
	}
}

int main()
{
	cin >> Q;
	rep(i,Q){
		scanf("%s",s[i]);
		if(s[i][0] == 'a'){
			si(q[i]);
			if( hash[q[i]] == 0){
				hash[q[i]] = 1;
				a[++k] = q[i];
			}
		}
		else if(  s[i][0] == 'd'){
			si(q[i]);
		}
	}
	sort(a+1,a+k+1);
	rep(i,k) hash[a[i]] = i;
	rep(i,Q){
		if(s[i][0] == 'a'){
			add(1,1,k,hash[q[i]]);
		}
		else if(s[i][0] == 'd'){
			remove(1,1,k,hash[q[i]]);
		}
		else{
			int ans = seg[1][1];
			printf("%d\n",ans);
		}
	}
	return 0;
}

