#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2e5 + 10;
int T, n, m, p;
int w[N];
struct node {
int l, r;
int mul;
}tr[N << 2];
void pushup(int u)
{
tr[u].mul = (LL)tr[u << 1].mul * tr[u << 1 | 1].mul % m;
}
void build(int u, int l, int r)
{
tr[u] = {l, r, 1};
if (l == r) return;
int mid = l + r >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
pushup(u);
}
void modify(int u, int x, int d)
{
if (tr[u].l == x && tr[u].r == x) {
tr[u].mul = d % m;
return;
}
int mid = tr[u].l + tr[u].r >> 1;
if (x <= mid) modify(u << 1, x, d);
if (x > mid) modify(u << 1 | 1, x, d);
pushup(u);
}
void modify1(int u, int x)
{
if (tr[u].l == x && tr[u].r == x) {
tr[u].mul = 1;
return;
}
int mid = tr[u].l + tr[u].r >> 1;
if (x <= mid) modify1(u << 1, x);
if (x > mid) modify1(u << 1 | 1, x);
pushup(u);
}
int main() {
scanf("%d", &T);
while (T -- ) {
scanf("%d%d", &n, &m);
build(1, 1, n);
int pos = 1;
while (n -- ) {
int t, x;
scanf("%d%d", &t, &x);
if (t == 1) {
modify(1, pos, x);
printf("%d\n", tr[1].mul);
}
else {
modify1(1, x);
printf("%d\n", tr[1].mul);
}
pos ++;
}
}
return 0;
}