rt
#include<bits/stdc++.h>
#define lson l,mid,x<<1
#define rson mid+1,r,x<<1|1
#define ls x<<1
#define rs x<<1|1
#define ll long long
using namespace std;
const int N=1e5+5;
ll q,m;
struct segment_tree
{
int l,r;
ll val;
}t[N<<2];
void push_up(int x)
{
t[x].val=t[x<<1].val*t[x<<1|1].val%m;
}
void build(int l,int r,int x)
{
t[x].l=l;
t[x].r=r;
if(l==r)
{
t[x].val=1;
return;
}
int mid=l+r>>1;
build(l,mid,x<<1);
build(mid+1,r,x<<1|1);
push_up(x);
}
void update(int id,int k,int l,int r,int x)
{
if(l==r)
{
t[id].val=k;
return;
}
int mid=l+r>>1;
if(id<=mid)
update(id,k,l,mid,x<<1);
else
update(id,k,mid+1,r,x<<1|1);
push_up(x);
}
void solve()
{
cin>>q>>m;
build(1,q,1);
for(int i=1;i<=q;i++)
{
int op,kas;
cin>>op>>kas;
if(op==1)
{
update(i,kas,1,q,1);
}
if(op==2)
{
update(kas,1,1,q,1);
}
cout<<t[1].val<<'\n';
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}