#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef string::const_iterator SC;
const int MOD = 1000000007;
const ll INF=2e18;

string s;
string p;
map<char,ll> mp;
ll Letter(SC &it){
    ll ret= mp[*it];
    it++;
    return ret;
}
ll Hash(SC &it){
    if(isalpha(*it)){
        return Letter(it);
    }
    else{
        it++;//[
        char op=*it;
        it++;//op
        ll l=Hash(it);
        ll r=Hash(it);
        it++;//]
        if(op=='+'){
            return l | r;
        }else if(op=='*'){
            return l & r;
        }else{
            return l^r;
        }
    }
}
int main(){
    while(cin>>s,s[0]!='.'){
        cin>>p;
        mp['a']=p[0]-'0';
        mp['b']=p[1]-'0';
        mp['c']=p[2]-'0';
        mp['d']=p[3]-'0';
        SC it=s.begin();
        ll hashNum=Hash(it);
        cout<<hashNum<<" ";
        ll ans=0;
        for(ll i=0;i<10000;i++){
            ll tmp=i;
            ll t[4];
            for(ll j=0;j<4;j++){
                ll mod=pow(10,3-j);
                t[j]=tmp/mod;
                tmp%=mod;
            }
            mp['a']=t[0];
            mp['b']=t[1];
            mp['c']=t[2];
            mp['d']=t[3];
            it=s.begin();
            if(Hash(it)==hashNum){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

