#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
int f[][],n,type,V[],g[][],ans,cnt;
char op[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int fun(int x,int y){
if (op[]=='a') return x&y;
else
if (op[]=='o') return x|y;
return x^y;
}
void add(int x){
int A=x>>,B=x&;
V[A]=;
for (int i=;i<;i++){
int k=fun(i,B);
if (k>f[A][i]) f[A][i]=k,g[A][i]=;
else if (k==f[A][i]) g[A][i]++;
}
}
void ask(int x){
int A=x>>,B=x&;
ans=cnt=;
for (int i=;i<;i++)if (V[i]){
int k=fun(i,A)<<|f[i][B];
if (k>ans) ans=k,cnt=g[i][B];else
if (k==ans) cnt+=g[i][B];
}
}
int main(){
n=read();scanf("%s",op);type=read();
for (int i=;i<=n;i++){
int x;
scanf("%d",&x);
if (i!=){
ask(x);
if (type) printf("%d %d\n",ans,cnt);
else printf("%d\n",ans);
}
add(x);
}
return ;
}