#include<bits/stdc++.h>
#define st static
#define re return
#define MAX(a,b) (a)>(b)?(a):(b)
#define inc(i,l,r) for(int i=l;i<=r;i++)
const int maxn=200005;
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
inline int red()
{
int x= 0,f = 0;char ch = getc();
while (!isdigit (ch)) {if (ch == '-') f = 1;ch = getc();}
while (isdigit (ch)) {x = x* 10 + ch - 48;ch = getc();}
return f?-x:x;
}
int n,last,k,t[maxn<<2],maxx[maxn<<2];
void insert(int l,int r,int x,int rt,int add)
{
if(l==r&&r==x)
{
t[rt]=add;
maxx[rt]=add;
re;
}
int mid=(l+r)>>1;
if(mid<x)insert(mid+1,r,x,rt<<1|1,add);
else insert(l,mid,x,rt<<1,add);
maxx[rt]=MAX(maxx[rt<<1|1],maxx[rt<<1]);
}
int ask(int l,int r,int x,int y,int rt)
{
if(x<=l&&r<=y)re maxx[rt];
int mid=(l+r)>>1;
int a=-2147483364,b=-2147483364;
if(mid<y)
a=ask(mid+1,r,x,y,rt<<1|1);
if(mid>=x)
b=ask(l,mid,x,y,rt<<1);
re MAX(a,b);
}
int main()
{
//freopen("in.txt","r",stdin);
int n,mod,tt=0;
char c;long long vv;
scanf("%d%d\n",&n,&mod);
inc(i,1,n)
{
c=getchar();
if(c=='A')
{
scanf("%lld\n",&vv);
last++;
insert(1,n,last,1,(vv+tt)%mod);
}
else
{
scanf("%lld\n",&vv);
tt=ask(1,n,last-vv+1,last,1);
printf("%d\n",tt);
}
}
re 0;
}