#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int calc(int lhs, int rhs, char op){
    if(op == '+') return lhs | rhs;
    else if(op == '*') return lhs & rhs;
    else return lhs ^ rhs;
}

int expr(string &s, int &i, string &p);
int number(string &s, int &i, string &p);

int expr(string &s, int &i, string &p){
    if(s[i] == '['){
        ++i;
        char op = s[i];
        ++i;
        int lhs = expr(s, i, p), rhs = expr(s, i, p);
        ++i;
        return calc(lhs, rhs, op);
    }
    return number(s, i, p);
}

int number(string &s, int &i, string &p){
    int ret = p[s[i]-'a'] - '0';
    ++i;
    return ret;
}

void dfs(int cur, int tmp, int &cnt, string &t, string &s){
    if(cur == 4){
        int i = 0;
        cnt += (expr(s, i, t) == tmp);
        return;
    }
    for(char c='0'; c<='9'; ++c){
        t += c;
        dfs(cur + 1, tmp, cnt, t, s);
        t.pop_back();
    }
}

int main(){
    string s, p;
    while(cin >> s && s != "."){
        cin >> p;
        int i = 0;
        int tmp = expr(s, i, p);
        int cnt = 0;
        string t;
        dfs(0, tmp, cnt, t, s);
        printf("%d %d\n", tmp, cnt);
    }
}
