伪装成求逆元的线段树题目…
#include<iostream>
#define rep(i,n) for(int i=1;i<=n;i++)
#define ls i<<1
#define mid (l+r)/2
using namespace std;
const int N=200005;
int n,m,t,L,R,pos,x,c[N*4];
char ch;
void update(int i=1,int l=1,int r=n) {
if(l==r) {
c[i]*=x,c[i]%=m;
if(x==-1) c[i]=1;
return ;
}
if(mid>=pos) update(ls,l,mid);
else update(ls|1,mid+1,r);
c[i]=c[ls]*c[ls|1]%m;
}
void solve(int ans=1) {
cin>>n>>m;
rep(i,4*n) c[i]=1;
rep(i,n) {
cin>>ch>>t;
if(ch=='M') pos=i,x=t,update();
else pos=t,x=-1,update();
cout<<c[1]<<'\n';
}
}
int main() {
ios::sync_with_stdio(false);
int T;cin>>T;
while(T--) solve();
}