#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll _,mod;
char op;
ll x;
ll ans=0;
ll top=0;
struct Tree{
ll l,r,maxn;
}t[800010];
ll read()
{
ll x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void write(ll x){
if(x<0) putchar('-'),x=abs(x);
if(x>9){
write(x/10);
}
putchar(x%10+'0');
}
ll qpow(ll a,ll n){
if(n==0) return 0;
if(n==1) return a;
ll tmp=qpow(a,n/2);
if(n%2==0) return tmp*tmp;
else return tmp*tmp*a;
}
void build(ll q,ll l,ll r){
t[q].l=l;
t[q].r=r;
if(l==r){
return ;
}
ll mid=(l+r)/2;
build(q*2,l,mid);
build(q*2+1,mid+1,r);
}
void change(ll q,ll seat,ll num){
if(t[q].l>=seat&&t[q].r<=seat){
t[q].maxn=num;
return ;
}
ll mid=(t[q].l+t[q].r)/2;
if(seat<=mid) change(q*2,seat,num);
else change(q*2+1,seat,num);
t[q].maxn=max(t[q*2].maxn,t[q*2+1].maxn)%mod;
}
ll ask(ll q,ll l,ll r){
if(t[q].l>=l&&t[q].r<=r){
return t[q].maxn;
}
ll val=-1145141919810;
ll mid=(t[q].l+t[q].r)/2;
if(l<=mid){
val=max(val,ask(q*2,l,r)%mod);
}
if(r>mid){
val=max(val,ask(q*2+1,l,r)%mod);
}
return val;
}
signed main(){
_=read();
build(1,1,_);
mod=read();
for (int i=1;i<=_;i++){
op=getchar();
x=read();
if(op=='A'){
top++;
change(1,top,(x+ans)%mod);
} else {
ans=ask(1,top-x+1,_)%mod;
write(ans);
puts("");
}
}
return 0;
}