#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back
#define INF (1e9+1)

string s;

int hf(int &p, string &id){
    if('a'<=s[p] && s[p]<='d'){
        int ret = id[s[p]-'a']-'0';
        p++;
        return ret;

    }else{
        assert('[');
        p++;
        char op = s[p];
        p++;
        int left = hf(p,id);
        int right = hf(p,id);
        assert(']');
        p++;

        if(op=='*')return left & right;
        if(op=='+')return left | right;
        if(op=='^')return left ^ right;
    }
    abort();
    return -1;
}

int main(){
    while(cin>>s&&s!="."){
        string id;
        cin>>id;

        int num = 0;
        int res = hf(num,id);

        int sum = 0;
        rep(i,10000){
            stringstream ss;
            ss<<i;
            string t = ss.str();
            while(t.size()<4)t = "0"+t;
            int num = 0;
            if(res==hf(num,t))sum++;
        }
        cout<<res<<" "<<sum<<endl;
    }
}

