#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <complex>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <limits>
#include <numeric>

using namespace std;
#define all(a) begin(a), end(a)

using ll = long long;
using ull = unsigned long long;
template <typename T>
using vec = vector<T>;
template <typename T>
using vec2 = vector<vec<T>>;

template <typename V, typename H>
void resize(vector<V> &vec, const H h)
{
    vec.resize(h);
}

template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &h, const T... t)
{
    vec.resize(h);
    for (auto &v : vec)
    {
        resize(v, t...);
    }
}

template <typename V, typename T>
void fill(V &x, const T &val)
{
    x = val;
}

template <typename V, typename T>
void fill(vector<V> &vec, const T &val)
{
    for (auto &v : vec)
    {
        fill(v, val);
    }
}

struct pre_
{
    pre_()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(6);
    }
} pre__;

string S, P;
int a, b, c, d;
stack<int> st;

void parser()
{
    for (int i = 0; i < S.size(); ++i)
    {
        if (S[i] >= 'a' && S[i] <= 'd')
        {
            int s;
            switch (S[i])
            {
            case 'a':
                s = a;
                break;
            case 'b':
                s = b;
                break;
            case 'c':
                s = c;
                break;
            case 'd':
                s = d;
                break;
            default:
                break;
            }

            st.push(s);
        }
        else if (S[i] == '[' || S[i] == ']')
            continue;
        else
        {
            int x = st.top();
            st.pop();
            int y = st.top();
            st.pop();
            int z;
            if (S[i] == '+')
            {
                z = x | y;
            }
            else if (S[i] == '*')
            {
                z = x & y;
            }
            else
            {
                z = x ^ y;
            }
            st.push(z);
        }
    }
}
int main(void)
{
    while (1)
    {

        cin >> S;
        if (S == ".")
            break;
        cin >> P;

        reverse(all(S));

        a = (int)P[0] - (int)'0';
        b = (int)P[1] - (int)'0';
        c = (int)P[2] - (int)'0';
        d = (int)P[3] - (int)'0';

        parser();
        int ans = st.top();
        cout << ans;
        st.pop();

        int cnt = 0;
        for (int i = 0; i <= 9999; ++i)
        {
            string test = to_string(i);
            string zero = "";
            for (int j = 0; j < 4 - test.size(); ++j)
            {
                zero += "0";
            }
            test = zero + test;
            a = (int)test[0] - (int)'0';
            b = (int)test[1] - (int)'0';
            c = (int)test[2] - (int)'0';
            d = (int)test[3] - (int)'0';
            parser();
            int ans_test = st.top();
            if (ans == ans_test)
                cnt++;

            st.pop();
        }
        cout << " " << cnt << endl;
    }

    return 0;
}
