#include<cstdio>
#include<algorithm>
#include<cstring>
#define Cu fclose(stdin);fclose(stdout);return 0;
#define Begin freopen("bzoj_1012.in","r",stdin);freopen("bzoj_1012.out","w",stdout);chul();Cu;
using namespace std;
//designed by New_Bee丶
const int maxn=200010;
long long s[maxn];/*原数列*/
long long a[maxn];/*单调栈*/
long long anst=0,d;
void ques(long long x){
long long lent=s[0];
lent=lent-x+1;
long long l=1,r=a[0];
while(l<r){
long long mid=(l+r)>>1;
if(lent<=a[mid])r=mid;
else l=mid+1;
}
anst=s[a[l]];
printf("%lld\n",anst);
}
void adds(long long x){
x=(x+anst)%d;
s[0]++;
s[s[0]]=x;
long long pit=a[0];
while(pit>0&&s[a[pit]]<x){
pit--;
}
a[0]=pit+1;
a[pit+1]=s[0];
}
void chul(){
char c;long long t;
long long n;scanf("%lld%lld",&n,&d);
for(int i=1;i<=n;i++){
while(c=getchar(),c!='A'&&c!='Q');
scanf("%lld",&t);
if(c=='A'){
adds(t);
}else{
ques(t);
}
}
}
int main(){
Begin;
}