#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
#define fastio ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
/////////////////////////////

ll cal(vector<ll>s){
    ll ls=s.size();
    while(s.size()>=2){
        
        ls=s.size();
        bool debugflag=false;
        vector<ll>t;
        rep(i,0,ls-1){
            bool flag=false;
            if(i<=ls-5)if(s[i]==100&&s[i+4]==200){
                if(0<=s[i+2]&&s[i+2]<=15){
                    if(0<=s[i+3]&&s[i+3]<=15){
                        ll add=0;
                        if(s[i+1]==300){
                            add=(s[i+2]|s[i+3]);
                            flag=true;
                            
                        }else if(s[i+1]==400){
                            add=(s[i+2]^s[i+3]);
                            flag=true;
                        }else if(s[i+1]==500){
                            add=(s[i+2]&s[i+3]);
                            flag=true;
                        }
                        
                        if(flag){
                            t.pb(add);
                        }
                    }
                }
            }
            if(!flag){
                t.pb(s[i]);
            }else{
                i+=4;
                debugflag=true;
            }
        }
        /*if(debugflag==false){
            for(auto x:s){
                cout<<x<<" ";
            }cout<<endl;
            return -1;
        }*/
        s.clear();
        for(auto x:t)s.pb(x);
    }
    return s[0];
}

bool ansproblem(string moto){
    string t;cin>>t;
    vector<ll>s;
    ll ls=moto.length();
    rep(i,0,ls-1){
        if(moto[i]=='[')s.pb(100);
        else if(moto[i]==']')s.pb(200);
        else if(moto[i]=='+')s.pb(300);
        else if(moto[i]=='^')s.pb(400);
        else if(moto[i]=='*')s.pb(500);
        else{
            if(moto[i]=='a')s.pb(t[0]-'0');
            else if(moto[i]=='b')s.pb(t[1]-'0');
            else if(moto[i]=='c')s.pb(t[2]-'0');
            else s.pb(t[3]-'0');
        }
    }
    ll ans=cal(s);
    ll count=0;
    rep(a,0,9){
        rep(b,0,9){
            rep(c,0,9){
                rep(d,0,9){
                    vector<ll>s;
                    rep(i,0,ls-1){
                        if(moto[i]=='[')s.pb(100);
                        else if(moto[i]==']')s.pb(200);
                        else if(moto[i]=='+')s.pb(300);
                        else if(moto[i]=='^')s.pb(400);
                        else if(moto[i]=='*')s.pb(500);
                        else{
                            if(moto[i]=='a')s.pb(a);
                            else if(moto[i]=='b')s.pb(b);
                            else if(moto[i]=='c')s.pb(c);
                            else s.pb(d);
                        }
                    }
                    if(cal(s)==ans)count++;
                }
            }
        }
    }
    cout<<ans<<" "<<count<<endl;
    
    return 0;
}

int main(){fastio
    
    while(1){
        string s;cin>>s;
        if(s[0]=='.'){
            break;
        }
        ansproblem(s);
    }
    return 0;
}


Measured memory_bytes: 3232