Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		S := io.NextLine()
		if S == "." {
			break
		}
		P := io.NextLine()
		i := 0
		val := hash(S, P, &i)
		cnt := 0
		for j := 0; j < 10000; j++ {
			i = 0
			if hash(S, fmt.Sprintf("%04d", j), &i) == val {
				cnt++
			}
		}
		io.Println(val, cnt)
	}
}

func hash(s, n string, i *int) int {
	if s[*i] == '[' {
		*i++
		switch s[*i] {
		case '+':
			*i++
			l := hash(s, n, i)
			r := hash(s, n, i)
			*i++
			return l | r
		case '*':
			*i++
			l := hash(s, n, i)
			r := hash(s, n, i)
			*i++
			return l & r
		case '^':
			*i++
			l := hash(s, n, i)
			r := hash(s, n, i)
			*i++
			return l ^ r
		}
	}
	x := int(n[s[*i]-'a'] - '0')
	*i++
	return x
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)


int calc(string pass) {
    stack<char> s;
    for (int i = SZ(pass) - 1; i >= 0; --i) {
        if (pass[i] == ']') continue;
        if (pass[i] == '[') {
            char op = s.top();
            s.pop();
            int a = s.top() - '0';
            s.pop();
            int b = s.top() - '0';
            s.pop();
            if (op == '+') a |= b;
            else if (op == '*') a &= b;
            else a ^= b;
            s.push(a + '0');
        }
        else s.push(pass[i]);
    }
    //out(SZ(s));
    int tmp = s.top() - '0';
    return tmp;
}
string make_pass2(string pass, string num) {
    rep(i, SZ(pass)) {
        if ('a' <= pass[i] && pass[i] <= 'd') {
            pass[i] = num[pass[i] - 'a'];
        }
    }
    return pass;
}
int main() {
    string pass;
    while (cin >> pass && pass != ".") {
        string num; cin >> num;
        string pass2 = make_pass2(pass, num);
        int tmp = calc(pass2);
        int ans = 0;
        
        
        rep(i, 10) rep(j, 10) rep(k, 10) rep(l, 10) {
            num = ""; num += i + '0';
            num += j + '0';
            num += k + '0';
            num += l + '0';
            pass2 = make_pass2(pass, num);
            
            if (calc(pass2) == tmp) {
                ans++;
            }
        }
        out(tmp << " " << ans);
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;

string s, t;
int p;

int calc(int p)
{
	int x[4];
	for(int i = 3; i >= 0; i--){
		x[i] = p % 10;
		p /= 10;
	}
	
	stack<int> stk;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '[' || s[i] == ']') continue;
		if(s[i] == 'a'){
			stk.push(x[0]);
			continue;
		}
		if(s[i] == 'b'){
			stk.push(x[1]);
			continue;
		}
		if(s[i] == 'c'){
			stk.push(x[2]);
			continue;
		}
		if(s[i] == 'd'){
			stk.push(x[3]);
			continue;
		}
		
		int op1 = stk.top(); stk.pop();
		int op2 = stk.top(); stk.pop();
		if(s[i] == '+') stk.push(op1|op2);
		if(s[i] == '*') stk.push(op1&op2);
		if(s[i] == '^') stk.push(op1^op2);
	}
	return stk.top();
}

int main(void)
{
	while(1){
		cin >> s;
		if(s == ".") break;
		cin >> p;
		
		reverse(s.begin(), s.end());
		int val = calc(p);
		
		int ans = 0;
		for(int i = 0; i < 10000; i++){
			if(val == calc(i)) ans++;
		}
		cout << val << " " << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

char tmp[111];
int place;

int dfs(){
	
	if(isdigit(tmp[place])){
		return tmp[place++] - '0';
	}
	else{
		place++;
		char c = tmp[place++];
		int A = dfs();
		int B = dfs();
		place++;
		if(c == '+'){
			return (A | B);
		}
		else if(c == '*'){
			return (A & B);
		}
		else{
			return (A ^ B);
		}
	}
}

int get_hash(string str,string num){
	REP(i,str.size()){
		if(str[i] >= 'a' && str[i] <= 'd'){
			tmp[i] = num[str[i] - 'a'];
		}
		else{
			tmp[i] = str[i];
		}
	}
	place = 0;
	return dfs();
}

int main(){
	
	string str;
	while(cin >> str,str[0] != '.'){
		
		string num;cin >> num;
		int hash = get_hash(str,num);
		cout << hash << ' ';
		
		int ans = 0;
		for(int i = 0;i < 10000;i++){
			string seica = "";
			int hoge = i;
			REP(j,4){
				seica += (char)('0' + (hoge % 10));
				hoge /= 10;
			}
			if(get_hash(str,seica) == hash)ans++;
		}
		
		cout << ans << endl;
	}
	return 0;
}