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<string>
#include<stack>
using namespace std;

int hash( string s, int a );

int main()
{
    string s;
    int t;

    while( cin >> s )
    {
        if( s == "." )
            break;

        cin >> t;

        int res = hash( s, t );
        int cnt = 0;
        for( int i = 0; i <= 9999; i++ )
            if( hash( s, i ) == res )
                cnt++;
        
        cout << res << " " << cnt << endl;
    }
    return 0;
}

int hash( string s, int a )
{
    char b[4];
    stack<char> st;

    for( int i = 0; i < 4; i++ )
    {
        b[3-i] = a % 10 + '0';
        a /= 10;
    }

    for( int j = 0; j < s.size(); j++ )
    {
        if( s[j] == 'a' )
            s[j] = b[0];
        else if( s[j] == 'b' )
            s[j] = b[1];
        else if( s[j] == 'c' )
            s[j] = b[2];
        else if( s[j] == 'd' )
            s[j] = b[3];
        else;
    }

    for( int i = 0; i < s.size(); i++ )
    {
        if( s[i] == ']' )
        {
            int x = st.top() - '0';
            st.pop();
            int y = st.top() - '0';
            st.pop();
            char c = st.top();
            if( c == '+' )
                x = x | y;
            else if( c == '*' )
                x = x & y;
            else
                x = x ^ y;
            st.pop();
            st.pop();
            st.push( x + '0' );
        }
        else
            st.push(s[i]);
    }
    return st.top() - '0';
}

C++: #include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <complex>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <limits>
#include <numeric>

using namespace std;
#define all(a) begin(a), end(a)

using ll = long long;
using ull = unsigned long long;
template <typename T>
using vec = vector<T>;
template <typename T>
using vec2 = vector<vec<T>>;

template <typename V, typename H>
void resize(vector<V> &vec, const H h)
{
    vec.resize(h);
}

template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &h, const T... t)
{
    vec.resize(h);
    for (auto &v : vec)
    {
        resize(v, t...);
    }
}

template <typename V, typename T>
void fill(V &x, const T &val)
{
    x = val;
}

template <typename V, typename T>
void fill(vector<V> &vec, const T &val)
{
    for (auto &v : vec)
    {
        fill(v, val);
    }
}

struct pre_
{
    pre_()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(6);
    }
} pre__;

string S, P;
int a, b, c, d;
stack<int> st;

void parser()
{
    for (int i = 0; i < S.size(); ++i)
    {
        if (S[i] >= 'a' && S[i] <= 'd')
        {
            int s;
            switch (S[i])
            {
            case 'a':
                s = a;
                break;
            case 'b':
                s = b;
                break;
            case 'c':
                s = c;
                break;
            case 'd':
                s = d;
                break;
            default:
                break;
            }

            st.push(s);
        }
        else if (S[i] == '[' || S[i] == ']')
            continue;
        else
        {
            int x = st.top();
            st.pop();
            int y = st.top();
            st.pop();
            int z;
            if (S[i] == '+')
            {
                z = x | y;
            }
            else if (S[i] == '*')
            {
                z = x & y;
            }
            else
            {
                z = x ^ y;
            }
            st.push(z);
        }
    }
}
int main(void)
{
    while (1)
    {

        cin >> S;
        if (S == ".")
            break;
        cin >> P;

        reverse(all(S));

        a = (int)P[0] - (int)'0';
        b = (int)P[1] - (int)'0';
        c = (int)P[2] - (int)'0';
        d = (int)P[3] - (int)'0';

        parser();
        int ans = st.top();
        cout << ans;
        st.pop();

        int cnt = 0;
        for (int i = 0; i <= 9999; ++i)
        {
            string test = to_string(i);
            string zero = "";
            for (int j = 0; j < 4 - test.size(); ++j)
            {
                zero += "0";
            }
            test = zero + test;
            a = (int)test[0] - (int)'0';
            b = (int)test[1] - (int)'0';
            c = (int)test[2] - (int)'0';
            d = (int)test[3] - (int)'0';
            parser();
            int ans_test = st.top();
            if (ans == ans_test)
                cnt++;

            st.pop();
        }
        cout << " " << cnt << endl;
    }

    return 0;
}