#include<bits/stdc++.h>
#define con continue
using namespace std;
int a,m,d,x,n;
int t;
char c;
int tr[200005];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>m>>d;
while(m--)
{
cin>>c>>x;
if(c=='A')
{
tr[++a]=((long long)x+t)%d;
assert(tr[a]>=0);
}
else
{
t=0;
while(x--)
{
t=max(t,tr[a-x]);
}
cout<<t<<endl;
}
}
return 0;
}