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 A 0
#define B 1
#define C 2
#define D 3
using namespace std;
string s;

int makeHash(int a[]) {
	stack<int> st;
	for(int i=s.size()-1;i>=0;i--) {
		if('a'<=s[i] and s[i]<='d') {
				if(s[i]=='a') st.push(a[A]);
				else if(s[i]=='b') st.push(a[B]);
				else if(s[i]=='c') st.push(a[C]);
				else if(s[i]=='d') st.push(a[D]);
			}
			else if(s[i]=='+') {
				int x = st.top();
				st.pop();
				int y = st.top();
				st.pop();
				st.push(x | y);
			}
			else if(s[i]=='*') {
				int x = st.top();
                st.pop();
                int y = st.top();
                st.pop();
                st.push(x & y);
			}
			else if(s[i]=='^') {
				int x = st.top();
                st.pop();
                int y = st.top();
                st.pop();
                st.push(x ^ y);
			}
		}
	return st.top();

}
int main() {
	string p;
	while(cin >> s) {
		if(s==".") break;
		cin >> p;
		vector<int> a(4);
		for(int i=0;i<4;i++) {
			a[i] = p[i] - '0';
		}
		stack<int> st;
		for(int i=s.size()-1;i>=0;i--) {
			if('a'<=s[i] and s[i]<='d') {
				if(s[i]=='a') st.push(a[A]);
				else if(s[i]=='b') st.push(a[B]);
				else if(s[i]=='c') st.push(a[C]);
				else if(s[i]=='d') st.push(a[D]);
			}
			else if(s[i]=='+') {
				int x = st.top();
				st.pop();
				int y = st.top();
				st.pop();
				st.push(x | y);
			}
			else if(s[i]=='*') {
				int x = st.top();
                st.pop();
                int y = st.top();
                st.pop();
                st.push(x & y);
			}
			else if(s[i]=='^') {
				int x = st.top();
                st.pop();
                int y = st.top();
                st.pop();
                st.push(x ^ y);
			}
		}
		int value = st.top();
		int cnt = 0;
		int tmp[4];
		for(int i=0;i<=9;i++) {
			for(int j=0;j<=9;j++) {
				for(int k=0;k<=9;k++) {
					for(int l=0;l<=9;l++) {
						tmp[0] = i;
						tmp[1] = j;
						tmp[2] = k;
						tmp[3] = l;
						if(makeHash(tmp) == value) cnt++;
					}
				}
			}
		}
		cout << value << " " << cnt << endl;
	}
}

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


int gethash(const string& s, const vector<int>& v) {
    stack<int> st;
    for (char c : s) {
        if ('a' <= c && c <= 'd')
            st.push(v[c - 'a']);
        else if (c == '+') {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a | b);
        }
        else if (c == '*') {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a & b);
        }
        else if (c == '^') {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a ^ b);
        }
    }
    return st.top();
}

int main() {
    while (true) {
        string s;
        cin >> s;
        if (s == ".") return 0;

        int p;
        cin >> p;
        reverse(s.begin(), s.end());
        int h = gethash(s, { p / 1000, p / 100 % 10, p / 10 % 10, p % 10 });
        int c = 0;
        for (int i = 0; i < 10; ++i)
            for (int j = 0; j < 10; ++j)
                for (int k = 0; k < 10; ++k)
                    for (int l = 0; l < 10; ++l)
                        c += gethash(s, { i, j, k, l }) == h;

        cout << h << " " << c << "\n";
    }
}

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

using namespace std;

string s, p;
vector<int> v;

pair<int,int> read(int l){
    if(s[l] >= 'a' && s[l] <= 'd'){
        return make_pair(l + 1, v[s[l] - 'a']);
    }
    assert(s[l] == '[');
    ++l;
    char op = s[l];
    auto p_l = read(l + 1);
    auto p_r = read(p_l.first);
    if(op == '+')
        return make_pair(p_r.first + 1, p_l.second | p_r.second);
    if(op == '*')
        return make_pair(p_r.first + 1, p_l.second & p_r.second);
    if(op == '^')
        return make_pair(p_r.first + 1, p_l.second ^ p_r.second);

    assert(0);
}

bool solve(){
    cin >> s;
    if(s == ".")
        return false;
    cin >> p;
    v.assign(4, 0);
    
    map<int,int> m;
    
    for(int i = 0; i <= 9999; ++i){
        int t = i;
        for(int j = 0; j < 4; ++j){
            v[j] = t % 10;
            t /= 10;
        }
        auto ret = read(0);
        ++m[ret.second];
    }
    
    for(int i = 0; i < 4; ++i)
        v[i] = p[i] - '0';
    int val = read(0).second;
    cout << val << " "  << m[val] << endl;
    
    return true;
}

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