#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};
int key[4];
int number(State &);
int factor(State &);
int expr(State &);

int number(State &begin) {
	int ret = key[*begin - 'a'];
	begin++;
	return ret;
}

int expr(State &begin) {
	if (*begin == '[') {
		begin++;
		if (*begin == '+') {
			begin++;
			ll left  = expr(begin);
			ll right = expr(begin);
			begin++;
			return left | right;
		} else if (*begin == '*') {
			begin++;
			ll left  = expr(begin);
			ll right = expr(begin);
			begin++;
			return left & right;
		} else if (*begin == '^') {
			begin++;
			ll left  = expr(begin);
			ll right = expr(begin);
			begin++;
			return left ^ right;
		}
	} else {
		return number(begin);
	}
}

int main() {
	string s, t;
	while (1) {
		cin >> s;
		if (s == ".") break;
		cin >> t;
		for (int i = 0; i < 4; i++) {
			key[i] = t[i] - '0';
		}
		State begin = s.begin();
		ll tmp		= expr(begin);
		ll ans		= 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						key[0] = i, key[1] = j, key[2] = k, key[3] = l;
						begin   = s.begin();
						ll unko = expr(begin);
						if (tmp == unko) ans++;
					}
				}
			}
		}
		cout << tmp << " " << ans << endl;
	}
	return 0;
}
