#include <stdio.h>
const int N=600005, mo=998244353;
int n, m, i, j, k, x, y, l, r, a[N], b[N];
int main(){
scanf("%d", &m);
for(a[0]=i=1; i<=m; i++){
a[i] = a[i-1]*10ll % mo;
}
x = l = r = b[1] = 1;
while(m--){
scanf("%d", &k);
if(k == 1){
scanf("%d", &y);
x = (x*10ll + y) % mo;
n++, b[++r] = y;//增加1位
}
else if(k == 2){
x = (x-1ll*a[n]*b[l]) % mo + mo;//该位是b[l]*10^n
n--, l++;//删除1位
}
else printf("%d\n", x%mo);
}
return 0;
}