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;

int calhash(string s){
    stack<char> st;
    for (int i = 0; i < s.size(); ++i) {
        st.push(s[i]);
        if(st.top()==']'){
            st.pop();
            st.pop();
            string r="";
            while(st.top()!=':'){
                r=st.top()+r;
                st.pop();
            }
            st.pop();
            string l="";
            while(isdigit(st.top())){
                l=st.top()+l;
                st.pop();
            }
            int ln=stoi(l);
            int rn=stoi(r);
            int t;
            switch (st.top()){
                case '+':
                    t=ln|rn;
                    break;
                case '*':
                    t=ln&rn;
                    break;
                case '^':
                    t=ln^rn;
                    break;
                default:
                    abort();
            }
            st.pop();
            assert(st.top()=='[');
            st.pop();
            string ts="";
            while(t!=0){
                ts=(char)('0'+t%10)+ts;
                t=t/10;
            }
            for(auto c:ts)st.push(c);
            if(ts=="")st.push('0');
            st.push(':');
        }
    }
    string ans="";
    while(!st.empty()){
        ans=st.top()+ans;
        st.pop();
    }
    return stoi(ans);
}

int main(){
    string s;
    while(true){
        cin>>s;
        if(s==".")break;
        string p;
        cin>>p;
        char a=p[0];
        char b=p[1];
        char c=p[2];
        char d=p[3];
        string s2="";
        for (int i = 0; i < s.size(); ++i) {
            switch (s[i]){
                case 'a':
                    s2.push_back(a);
                    s2.push_back(':');
                    break;
                case 'b':
                    s2.push_back(b);
                    s2.push_back(':');
                    break;
                case 'c':
                    s2.push_back(c);
                    s2.push_back(':');
                    break;
                case 'd':
                    s2.push_back(d);
                    s2.push_back(':');
                    break;
                default:
                    s2+=s[i];
                    break;
            }
        }
        int ans=calhash(s2);
        int ansn=0;
        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) {
                        string t;
                        t.push_back('0'+i);
                        t.push_back('0'+j);
                        t.push_back('0'+k);
                        t.push_back('0'+l);
                        char a=t[0];
                        char b=t[1];
                        char c=t[2];
                        char d=t[3];
                        s2="";
                        for (int i = 0; i < s.size(); ++i) {
                            switch (s[i]){
                                case 'a':
                                    s2.push_back(a);
                                    s2.push_back(':');
                                    break;
                                case 'b':
                                    s2.push_back(b);
                                    s2.push_back(':');
                                    break;
                                case 'c':
                                    s2.push_back(c);
                                    s2.push_back(':');
                                    break;
                                case 'd':
                                    s2.push_back(d);
                                    s2.push_back(':');
                                    break;
                                default:
                                    s2+=s[i];
                                    break;
                            }
                        }
                        if(calhash(s2)==ans)++ansn;
                    }
                }
            }
        }
        cout<<ans<<" "<<ansn<<endl;
    }
    return 0;
}