#include<bits/stdc++.h>
using namespace std;
typedef long long lint;

string S, P;

string itos(int n) {
	string S(4, '$');
	for(int i = 0; i < 4; ++i) {
		S[i] = n % 10 + '0';
		n /= 10;
	}
	return S;
}

int expr(int&);

int myhash(int& i) {
	// cerr << "myhash : " << i << endl;
	int ret;
	if (S[i] == '[') {
		++i;
		ret = expr(i);
		assert(S[i] == ']');
		++i;
	} else {
		assert('a' <= S[i] && S[i] <= 'd');
		ret = P[S[i] - 'a'] - '0';
		++i;
	}
	return ret;
}

int expr(int& i) {
	// cerr << "expr : " << i << endl;
	char c = S[i];
	++i;
	int a = myhash(i);
	int b = myhash(i);

	int ret;
	if (c == '+') {
		ret = a | b;
	} else if (c == '*') {
		ret = a & b;
	} else if (c == '^') {
		ret = a ^ b;
	} else {
		cerr << "op : " << c << endl;
		terminate();
	}
	return ret;
}

bool solve() {
	cin >> S;
	if (S == ".") return false;

	cin >> P;
	int i = 0;
	int h = myhash(i);

	int cnt = 0;
	for(int n = 0; n < 10000; ++n) {
		P = itos(n);
		i = 0;
		if (myhash(i) == h) ++cnt;
	}

	cout << h << " " << cnt << endl;
	return true;
}

int main() {
	while (solve());
	return 0;
}

