#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef string::iterator state;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
string pass;

string S;
int f(state &itr) {
    if(*itr == '[') {
        itr++;
        char operation = *itr;
        itr++;
        int a = f(itr);
        int b = f(itr);
        itr++;
        if(operation == '+') return a | b;
        if(operation == '*') return a & b;
        if(operation == '^') return a ^ b;
    }
    char moji = *itr;
    itr++;
    if(moji == 'a') return pass[0] - '0';
    if(moji == 'b') return pass[1] - '0';
    if(moji == 'c') return pass[2] - '0';
    if(moji == 'd') return pass[3] - '0';
}
int myhash;
int ans;
void g() {
    if(pass.size() == 4) {
        auto itr = S.begin();
        if(f(itr) == myhash) ans++;
        return;
    }
    for(char moji = '0'; moji <= '9'; moji++) {
        pass.push_back(moji);
        g();
        pass.pop_back();
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> S;
        if(S == ".") break;
        cin >> pass;
        state itr = S.begin();
        myhash = f(itr);
        ans = 0;
        pass = "";
        g();
        cout << myhash << " " << ans << endl;
    }
    return 0;
}

