# 祖玛(Zuma)

### Description

Let’s play the game Zuma!

There are a sequence of beads on a track at the right beginning. All the beads are colored but no three adjacent ones are allowed to be with a same color. You can then insert beads one by one into the sequence. Once three (or more) beads with a same color become adjacent due to an insertion, they will vanish immediately.

Note that it is possible for such a case to happen for more than once for a single insertion. You can’t insert the next bead until all the eliminations have been done.

Given both the initial sequence and the insertion series, you are now asked by the fans to provide a playback tool for replaying their games. In other words, the sequence of beads after all possible eliminations as a result of each insertion should be calculated.

### Input

The first line gives the initial bead sequence. Namely, it is a string of capital letters from ‘A’ to ‘Z’, where different letters correspond to beads with different colors.

The second line just consists of a single interger n, i.e., the number of insertions.

The following n lines tell all the insertions in turn. Each contains an integer k and a capital letter Σ, giving the rank and the color of the next bead to be inserted respectively. Specifically, k ranges from 0 to m when there are currently m beads on the track.

### Output

n lines of capital letters, i.e., the evolutionary history of the bead sequence.

Specially, “-” stands for an empty sequence.

### Example

Input

ACCBA
5
1 B
0 A
2 B
4 C
0 A


Output

ABCCBA
AABCCBA
AABBCCBA
-
A


### Restrictions

0 <= n <= 10^4

0 <= length of the initial sequence <= 10^4

Time: 2 sec

Memory: 256 MB

List

### 限制

0 ≤ n ≤ 10^4

0 ≤ 初始珠子数量 ≤ 10^4

### 提示

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 #include #include using namespace std; string & trim(string & s){     if(s.empty())return s;     s.erase(0,s.find_first_not_of(" "));     s.erase(s.find_last_not_of(" ")+1);     return s; } bool process_once(string & str){     char c=str[0];     int cnt=1;     for(int i=1;i=3){                 str.erase(i-cnt,cnt);                 return true;             }else{                 c=str[i];                 cnt=1;             }         }     }     if(cnt>=3)str.erase(str.length()-cnt,cnt);     return false; } void process(string & str,int pos,char c){     str.insert(pos,1,c);     while(process_once(str));     return; } int main(){     ios::sync_with_stdio(false);     string str;     int n;     cin>>str>>n;     for(int i=0;i>pos>>c;         process(str,pos,c);         trim(str);         if(str.length()==0)cout<<"-"<