#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
#include <iomanip>
#include <sstream>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int get_hash(void);
int get_val(vector<int>);
char change(char, string);
int get_cnt(int, string);

string s;
int pos;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    while(cin >> s)
    {
        if(s == ".") break;
        string p; cin >> p;
        int num; pos = 0;
        if(s[0] == '[' && s[s.size() - 1] == ']') s = s.substr(1, s.size() - 2);
        string tmp = s;
        for(int i = 0; i < s.size(); i++) s[i] = change(s[i], p);
        num = get_hash();
        cout << num << " " << get_cnt(num, tmp) << endl;
    }
	return 0;
}
int get_cnt(int num, string tmp)
{
    int ret = 0;
    for(int i = 0; i <= 9999; i++)
    {
        s = tmp, pos = 0;
        ostringstream sout;
        sout << setfill('0') << setw(4) << i;
        string password = sout.str();
        for(int i = 0; i < s.size(); i++) s[i] = change(s[i], password);
        int x = get_hash();
        if(x == num) ret++;
    }
    return ret;
}
int get_hash()
{
    vector<int> vec;
    if(s.size() < 3) return s[0] -'0';
    while(s[pos] != ']')
    {
        if(pos >= s.size()) break;
        if(s[pos] == '[')
        {
            pos++;
            vec.push_back(get_hash());
        }
        else
        {
            if(s[pos] >= 48 && s[pos] <= 57) vec.push_back(s[pos] - '0');
            else vec.push_back(s[pos]);
        }
        pos++;
    }
    return get_val(vec);
}
char change(char ch, string p)
{
    if(ch == 'a') return p[0];
    else if(ch == 'b') return p[1];
    else if(ch == 'c') return p[2];
    else if(ch == 'd') return p[3];
    else return ch;
}
int get_val(vector<int> vec)
{
    char ch = (char)vec[0];
    int a = vec[1], b = vec[2];
    if(ch == '+') return a | b;
    else if(ch == '*') return a & b;
    else return a ^ b;
}

