#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+100;
int a[N],num=0,d;
int m;
int c[N];
void add(int x,int v)
{
for(;x<=num;x+=x&-x)c[x]=max(c[x],v);
}
int ask(int l,int r)
{
if(l<r)
{
if(l<r-(r&-r))return max(ask(l,r-(r&-r)),c[r]);
else return max(ask(l,r-1),a[r]);
}
return a[l];
}
signed main()
{
cin>>m>>d;
int t=0;
while(m--)
{
char op[10];
int x;
scanf("%s%lld",op,&x);
if(op[0]=='A')
{
num++;
a[num]=(x%d+t)%d;
add(num,(x%d+t)%d);
}else{
t=ask(num-x+1,num);
printf("%lld\n",t);
}
}
return 0;
}