#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define maxs 256
using namespace std;
int n,type,opt,i,j,k,f[maxs][maxs],g[maxs][maxs],fans,gans;
char ch;
int get(int x,int y){
if (opt==1) return x&y;
if (opt==2) return x|y;
if (opt==3) return x^y;
}
void ins(int x){
int y=x&((1<<8)-1);
for(int i=0;i<1<<8;i++) {
int tmp=get(x>>8,i)<<8;
if (!g[i][y]||tmp>=f[i][y]){
if (tmp>f[i][y]) g[i][y]=0;
g[i][y]++,f[i][y]=tmp;
}
}
}
int main(){
scanf("%d ",&n);
ch=getchar();
if (ch=='a') opt=1,ch=getchar(),ch=getchar(); else
if (ch=='o') opt=2,ch=getchar(); else
if (ch=='x') opt=3,ch=getchar(),ch=getchar();
scanf("%d",&type);
scanf("%d",&k); ins(k);
for(i=1;i<n;i++) {
scanf("%d",&k);
gans=fans=0;
for(j=0;j<1<<8;j++) if (g[k>>8][j]){
int tmp=get(j,k&((1<<8)-1))+f[k>>8][j];
if (!gans||tmp>=fans){
if (tmp>fans) gans=0;
gans+=g[k>>8][j],fans=tmp;
}
}
printf("%d ",fans);
if (type) printf("%d",gans);
printf("\n");
ins(k);
}
}