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>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;

string s, t;
string str = "abcd";

int operate(int a, int b, char op){
    if(op == '+') return a | b;
    if(op == '*') return a & b;
    return a ^ b;
}

int calchash(string r){
    string s2 = s;
    stack<string> st;
    rep(i, 0, s.size()){
        size_t pos = str.find(s[i]);
        if(pos == string::npos) continue;
        s2[i] = r[pos];
    }
    // cout << s2 << endl;
    rep(i, 0, s.size()){
        if(isdigit(s2[i]) || s2[i] == '*' || s2[i] == '^' || s2[i] == '+'){
            string ts = "";
            ts += s2[i];
            st.push(ts);
        }else if(s2[i] == ']'){
            string a = st.top(); st.pop();
            string b = st.top(); st.pop();
            string op = st.top(); st.pop();
            int numa = stoi(a);
            int numb = stoi(b);
            char cop = op[0];
            int tmp = operate(numa, numb, cop);
            string ts = "";
            ts += to_string(tmp);
            st.push(ts);
        }
    }
    int res = stoi(st.top());
    return res;
}

int main(){
    while(1){
        cin >> s;
        if(s == ".") break;
        cin >> t;
        int ans = calchash(t);
        int cnt = 0;
        rep(i, 0, 10000){
            string tmp = to_string(i);
            while(tmp.size() < 4) tmp = "0" + tmp;
            if(calchash(tmp) == ans) cnt++;
        }
        cout << ans << " " << cnt << endl;
    }
}

C++: #include "bits/stdc++.h"

using namespace std;
#define int long long 
#define rep(i,a,b) for(int i=a;i<(b);i++)
using VI=vector<int>;
using VVI=vector<VI>;
using pii=pair<int, int>;
#define DBG 0


int _calc(string hash, int& idx) {
	if (isdigit(hash[idx])) {
		return hash[idx] - '0';
	}
	else if (hash[idx] == '[') {
		idx++;
		char op = hash[idx];
		idx++;
		int l = _calc(hash, idx);
		idx++;
		int r = _calc(hash, idx);
		idx++;
		int ret;
		if (op == '+') {
			ret = l | r;
		}
		else if (op == '*') {
			ret = l & r;
		}
		else {
			ret = l ^ r;
		}
		return ret;
	}
	else {
		assert(0);
	}
}

int calc(string hash, string pw) {

	rep(i, 0, hash.size()) {
		if ('a' <= hash[i] and hash[i] <= 'd') {
			hash[i] = pw[hash[i] - 'a'];
		}
	}
	int idx = 0;
	return _calc(hash, idx);

}

void solve(string hash) {
	string pw; cin >> pw;

	map<int, int>mp;
	rep(i, 0, 10000) {
		string in = to_string(i);
		reverse(in.begin(), in.end());
		while (in.size() < 4) {
			in.push_back('0');
		}
		reverse(in.begin(), in.end());
		int h = calc(hash, in);
		if (DBG) {
			assert(i == stoi(in));
			if (h != 0) {
				cout << "i:" << i << ", in:" << in << ", h:" << h << endl;
			}
		}
		mp[h]++;
	}

	cout << calc(hash, pw) << " " << mp[calc(hash, pw)] << endl;
}

signed main(void) {
	while (1) {
		string hash;
		cin >> hash;
		if (hash == ".")break;
		solve(hash);
	}
}

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

using namespace std;

int id, abcd[4];
string s;

int Hash() {
	if (isalpha(s[id])) return abcd[s[id++] - 'a'];
	if (s[id] == '[') {
		id++;
		char c = s[id++];
		int res = Hash();
		switch (c) {
		case '+': res |= Hash(); break;
		case '*': res &= Hash(); break;
		case '^': res ^= Hash(); break;
		}
		id++;
		return res;
	}
}

int main() {
	while (cin >> s, s != ".") {
		string p; cin >> p;
		for (int i = 0; i < 4; ++i) abcd[i] = p[i] - '0';
		int ans = 0, P = Hash();
		for (abcd[0] = 0; abcd[0] < 10; ++abcd[0])
			for (abcd[1] = 0; abcd[1] < 10; ++abcd[1])
				for (abcd[2] = 0; abcd[2] < 10; ++abcd[2])
					for (abcd[3] = 0; abcd[3] < 10; ++abcd[3], id = 0)
						if (P == Hash()) ans++;
		cout << P << " " << ans << endl;
	}

	return 0;
}