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 <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
const int MAX = 510000;

int main()
{
    string s;
    string P;
    while (cin >> s)
    {
        if (s == ".")
            break;
        cin >> P;

        map<int, int> mp;

        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)
                    {
                        stack<int> st;
                        stack<char> st2;

                        for (int idx = 0; idx < s.size(); ++idx)
                        {
                            if (s[idx] == '+' || s[idx] == '*' || s[idx] == '^')
                            {
                                st2.push(s[idx]);
                            }

                            if (s[idx] == 'a')
                            {
                                st.push(i);
                            }
                            else if (s[idx] == 'b')
                            {
                                st.push(j);
                            }
                            else if (s[idx] == 'c')
                            {
                                st.push(k);
                            }
                            else if (s[idx] == 'd')
                            {
                                st.push(l);
                            }

                            if (s[idx] == ']')
                            {
                                if (st2.top() == '+')
                                {
                                    st2.pop();
                                    int n = st.top();
                                    st.pop();
                                    int m = st.top();
                                    st.pop();
                                    st.push(m | n);
                                }
                                else if (st2.top() == '*')
                                {
                                    st2.pop();
                                    int n = st.top();
                                    st.pop();
                                    int m = st.top();
                                    st.pop();
                                    st.push(m & n);
                                }
                                else if (st2.top() == '^')
                                {
                                    st2.pop();
                                    int n = st.top();
                                    st.pop();
                                    int m = st.top();
                                    st.pop();
                                    st.push(m ^ n);
                                }
                            }
                        }

                        mp[st.top()]++;
                    }
                }
            }
        }
        int a = P[0] - '0';
        int b = P[1] - '0';
        int c = P[2] - '0';
        int d = P[3] - '0';

        stack<int> st;
        stack<char> st2;

        for (int idx = 0; idx < s.size(); ++idx)
        {
            if (s[idx] == '+' || s[idx] == '*' || s[idx] == '^')
            {
                st2.push(s[idx]);
            }

            if (s[idx] == 'a')
            {
                st.push(a);
            }
            else if (s[idx] == 'b')
            {
                st.push(b);
            }
            else if (s[idx] == 'c')
            {
                st.push(c);
            }
            else if (s[idx] == 'd')
            {
                st.push(d);
            }

            if (s[idx] == ']')
            {
                if (st2.top() == '+')
                {
                    st2.pop();
                    int n = st.top();
                    st.pop();
                    int m = st.top();
                    st.pop();
                    st.push(m | n);
                }
                else if (st2.top() == '*')
                {
                    st2.pop();
                    int n = st.top();
                    st.pop();
                    int m = st.top();
                    st.pop();
                    st.push(m & n);
                }
                else if (st2.top() == '^')
                {
                    st2.pop();
                    int n = st.top();
                    st.pop();
                    int m = st.top();
                    st.pop();
                    st.push(m ^ n);
                }
            }
        }

        cout << st.top() << " " << mp[st.top()] << endl;
    }
    return 0;
}