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;

string s;

//[l, r)のハッシュ値を返す
int f(int a, int b, int c, int d, int l, int r){
    //num1 op num2を実行する
    int op;
    int num1, num2;
    if(s[l] != '['){
        if(s[l] == 'a') return a;
        if(s[l] == 'b') return b;
        if(s[l] == 'c') return c;
        if(s[l] == 'd') return d;
    }

    //cout << "l " << l << " r " << r << endl;
    if(s[l + 1] == '+') op = 0;
    else if(s[l + 1] == '*') op = 1;
    else op = 2;

    if(s[l + 2] == '['){
        int dpt = 1;
        for(int idx = l + 3; idx < r; idx++){
            if(s[idx] == '[') dpt++;
            else if(s[idx] == ']') dpt--;
            
            if(dpt == 0){
                num1 = f(a, b, c, d, l + 2, idx + 1);
                l = idx + 1;
                break;
            }
        }
    }else{

        if(s[l + 2] == 'a') num1 = a;
        if(s[l + 2] == 'b') num1 = b;
        if(s[l + 2] == 'c') num1 = c;
        if(s[l + 2] == 'd') num1 = d;
        l = l + 3;
    }

    if(s[l] == '['){
        int dpt = 1;
        for(int idx = l + 1; idx < r; idx++){
            if(s[idx] == '[') dpt++;
            else if(s[idx] == ']') dpt--;
            
            if(dpt == 0){
                num2 = f(a, b, c, d, l, idx + 1);
                break;
            }
        }
    }else{
        if(s[l] == 'a') num2 = a;
        if(s[l] == 'b') num2 = b;
        if(s[l] == 'c') num2 = c;
        if(s[l] == 'd') num2 = d;
    }

    int rec;
    if(op == 0) rec = num1 | num2;
    else if(op == 1) rec = num1 & num2;
    else rec = num1 ^ num2;
    //cout << num1 << " " << num2 << " " << op << endl;
    return rec;
}

int main(){

    //実験
    //s = "[*b[*[*cd]a]]";
    //cout << f(7, 7, 7, 7, 0, 13) << endl;


    while(1){
        cin >> s;
        if(s == ".") break;
        string pass; cin >> pass;
        int a = (int)(pass[0] - '0');
        int b = (int)(pass[1] - '0');
        int c = (int)(pass[2] - '0');
        int d = (int)(pass[3] - '0');
        int l = 0;
        int r = (int)s.size();
        int x = f(a, b, c, d, l, r);
        int cnt = 0;
        for(a = 0; a < 10; a++){
            for(b = 0; b < 10; b++){
                for(c = 0; c < 10; c++){
                    for(d = 0; d < 10; d++){
                        if(x == f(a, b, c, d, l, r)) cnt++;
                    }
                }
            }
        }

        cout << x << " " << cnt << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define REP(i,n) rep(i,0,n)

using ll=long long;
using P=pair<ll,ll>;
string s;
int a[4];

P letter(int p);

P hash_(int p){
    //cout<<p<<endl;
    if(s[p]=='+'){
        p++;
        P ret1 = letter(p);
        p = ret1.second;
        P ret2 = letter(p);
        p=ret2.second;
        return {ret1.first | ret2.first,p};
    }else if(s[p]=='*'){
        p++;
        P ret1 = letter(p);
        p = ret1.second;
        P ret2 = letter(p);
        p=ret2.second;
        return {ret1.first & ret2.first,p};
    }else{
        p++;
        P ret1 = letter(p);
        p = ret1.second;
        P ret2 = letter(p);
        p=ret2.second;
        //cout<<p<<" "<<ret1.first<<endl;
        return {ret1.first ^ ret2.first,p};
    }
}

P letter(int p){
    if(s[p]=='['){
        p++;
        P ret1 = hash_(p);
        p=ret1.second;
        p++;//skip ']'
        return {ret1.first, p};
    }else{
        return {a[s[p]-'a'], p+1};
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    while(cin>>s){
        if(s==".") break;
        string t;
        cin>>t;
        REP(i,4) a[i]=t[i]-'0';
        P ret = letter(0);
        ll ans=ret.first;

        ll con=0;
        REP(i,10000){
            int x=i;
            REP(j,4){
                a[j] = x%10;
                x/=10;
            }
            
            P ret2 = letter(0);
            if(ret2.first==ans) con++;
        }
        cout<<ans<<" "<<con<<"\n";

    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

string s,p;

int H(int &idx){
    if(s[idx]=='['){
        ++idx;
        char op = s[idx];
        ++idx;

        int val=-1;
        if(op=='+') val = H(idx)|H(idx);
        else if(op=='*') val = H(idx)&H(idx);
        else if(op=='^') val = H(idx)^H(idx);
        else assert(false);

        assert(s[idx]==']');
        ++idx;

        return val;
    }
    else{
        int letter = s[idx]-'a';
        ++idx;
        assert(0<=letter && letter<=3);
        return p[letter]-'0';
    }
}

int main(){
    while(cin >>s,(s!=".")){
        cin >>p;

        int idx = 0;
        int v = H(idx);

        int ct = 0;
        rep(i,10000){
            int t = i;
            rep(j,4){
                p[3-j] = t%10+'0';
                t/=10;
            }
            idx = 0;
            if(H(idx) == v) ++ct;
        }

        cout << v << " " << ct << endl;
    }
    return 0;
}