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>



char cal(char op,char l1,char l2){
    int f=l1-'0';
    int s=l2-'0';
    if(op=='+')return static_cast<char>((f | s) + '0');
    if(op=='*')return static_cast<char>((f & s) + '0');
    if(op=='^')return static_cast<char>((f ^ s) + '0');
}

int main(){
    while(true){
        std::stack<char> h;
        std::string s;
        std::string p;
        int ans=0;
        std::cin>>s;
        if(s[0]=='.')break;
        std::cin>>p;
        for (char i : s) {
            switch (i){
                case 'a':
                    h.push(p[0]);
                    break;
                case 'b':
                    h.push(p[1]);
                    break;
                case 'c':
                    h.push(p[2]);
                    break;
                case 'd':
                    h.push(p[3]);
                    break;
                default:
                    h.push(i);
            }
            if(h.top()==']'){
                h.pop();
                char l2=h.top();
                h.pop();
                char l1=h.top();
                h.pop();
                char op=h.top();
                h.pop();
                h.pop();
                h.push(cal(op,l1,l2));
            }
        }
        char hv=h.top();
        h.pop();
        for (char d1 = '0'; d1 <= '9'; ++d1) {
            for (char d2 = '0'; d2 <= '9'; ++d2) {
                for (char d3 = '0'; d3 <= '9'; ++d3) {
                    for (char d4 = '0'; d4 <= '9'; ++d4) {
                        for (char i : s) {
                            switch (i){
                                case 'a':
                                    h.push(d1);
                                    break;
                                case 'b':
                                    h.push(d2);
                                    break;
                                case 'c':
                                    h.push(d3);
                                    break;
                                case 'd':
                                    h.push(d4);
                                    break;
                                default:
                                    h.push(i);
                            }
                            if(h.top()==']'){
                                h.pop();
                                char l2=h.top();
                                h.pop();
                                char l1=h.top();
                                h.pop();
                                char op=h.top();
                                h.pop();
                                h.pop();
                                h.push(cal(op,l1,l2));
                            }
                        }
                        if(hv==h.top())++ans;
                        h.pop();
                    }
                }
            }
        }
        int a=hv-'0';
        std::cout<<a<<" "<<ans<<std::endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {if (a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmin(A &a, B b) {if (a > b) {a = b; return 1;} return 0;}
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/****************************/

struct SyntaxAnalysis {
	string s;
	int i;
	int val;
	
	SystaxAnalysis() {}
	
	int init(string _s) {
		s = _s;
		i = 0;
		
		val = expr(i);
		return val;
	}
	
	int expr(int &i) {
		int res = 0;
		if (s[i] >= '0' && s[i] <= '9') {
			res = s[i] - '0';
		}
		else {
			res = term(++i);
			++i;
		}
		return res;
	}
	
	int term(int &i) {
		int ope;
		if (s[i] == '+') ope = 0;
		else if (s[i] == '*') ope = 1;
		else ope = 2;
		
		int val1 = expr(++i);
		int val2 = expr(++i);
		
		int res;
		if (ope == 0) res = val1 | val2;
		else if (ope == 1) res = val1 & val2;
		else res = val1 ^ val2;
		return res;
	}
};

string make(int i) {
	string num = to_string(i);
	reverse(ALL(num));
	while (num.size() < 4) num += '0';
	reverse(ALL(num));
	return num;
}

string arrange(string str, string num) {
	REP(i, str.size()) {
		if (str[i] >= 'a' && str[i] <= 'd') {
			str[i] = num[str[i]-'a'];
		}
	}
	return str;
}

int main() {
	string s;
	while (cin >> s, s != ".") {
		string num;
		cin >> num;
		
		string tmp = arrange(s, num);
		
		SyntaxAnalysis sa;
		int hsorg = sa.init(tmp);
		
		int ans = 0;
		REP(i, 10000) {
			string cur = make(i);
			if (hsorg == sa.init(arrange(s, cur))) {
				ans++;
			}
		}
		
		if (debug) printf("@ ");
		cout << hsorg << " " << ans << endl;
	}
	return 0;
}

// C