#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll m,d;
stack<ll> s;
stack<ll> t;
int maxx(ll n)
{
ll maxn=-1145141919810;
ll cnt=0;
while(cnt!=n)
{
ll x=s.top();
s.pop();
t.push(x);
maxn=max(maxn,x);
cnt++;
}
cnt=0;
while(cnt!=n)
{
ll x=t.top();
t.pop();
s.push(x);
cnt++;
}
return maxn;
}
int main()
{
cin>>m>>d;
ll tmp=0;
char c;
ll x;
while(m--)
{
cin>>c>>x;
if(c=='A')
{
x+=tmp;
x=(x+d)%d;
s.push(x);
}
else
{
tmp=maxx(x);
cout<<tmp<<endl;
}
}
return 0;
}