#include <bits/stdc++.h>

using namespace std;

int calhash(string s){
    stack<char> st;
    for (int i = 0; i < s.size(); ++i) {
        st.push(s[i]);
        if(st.top()==']'){
            st.pop();
            st.pop();
            string r="";
            while(st.top()!=':'){
                r=st.top()+r;
                st.pop();
            }
            st.pop();
            string l="";
            while(isdigit(st.top())){
                l=st.top()+l;
                st.pop();
            }
            int ln=stoi(l);
            int rn=stoi(r);
            int t;
            switch (st.top()){
                case '+':
                    t=ln|rn;
                    break;
                case '*':
                    t=ln&rn;
                    break;
                case '^':
                    t=ln^rn;
                    break;
                default:
                    abort();
            }
            st.pop();
            assert(st.top()=='[');
            st.pop();
            string ts="";
            while(t!=0){
                ts=(char)('0'+t%10)+ts;
                t=t/10;
            }
            for(auto c:ts)st.push(c);
            if(ts=="")st.push('0');
            st.push(':');
        }
    }
    string ans="";
    while(!st.empty()){
        ans=st.top()+ans;
        st.pop();
    }
    return stoi(ans);
}

int main(){
    string s;
    while(true){
        cin>>s;
        if(s==".")break;
        string p;
        cin>>p;
        char a=p[0];
        char b=p[1];
        char c=p[2];
        char d=p[3];
        string s2="";
        for (int i = 0; i < s.size(); ++i) {
            switch (s[i]){
                case 'a':
                    s2.push_back(a);
                    s2.push_back(':');
                    break;
                case 'b':
                    s2.push_back(b);
                    s2.push_back(':');
                    break;
                case 'c':
                    s2.push_back(c);
                    s2.push_back(':');
                    break;
                case 'd':
                    s2.push_back(d);
                    s2.push_back(':');
                    break;
                default:
                    s2+=s[i];
                    break;
            }
        }
        int ans=calhash(s2);
        int ansn=0;
        for (int i = 0; i <= 9; ++i) {
            for (int j = 0; j <= 9; ++j) {
                for (int k = 0; k <= 9; ++k) {
                    for (int l = 0; l <= 9; ++l) {
                        string t;
                        t.push_back('0'+i);
                        t.push_back('0'+j);
                        t.push_back('0'+k);
                        t.push_back('0'+l);
                        char a=t[0];
                        char b=t[1];
                        char c=t[2];
                        char d=t[3];
                        s2="";
                        for (int i = 0; i < s.size(); ++i) {
                            switch (s[i]){
                                case 'a':
                                    s2.push_back(a);
                                    s2.push_back(':');
                                    break;
                                case 'b':
                                    s2.push_back(b);
                                    s2.push_back(':');
                                    break;
                                case 'c':
                                    s2.push_back(c);
                                    s2.push_back(':');
                                    break;
                                case 'd':
                                    s2.push_back(d);
                                    s2.push_back(':');
                                    break;
                                default:
                                    s2+=s[i];
                                    break;
                            }
                        }
                        if(calhash(s2)==ans)++ansn;
                    }
                }
            }
        }
        cout<<ans<<" "<<ansn<<endl;
    }
    return 0;
}


Measured memory_bytes: 3172