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<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<deque>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef deque<int> di;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

int f();

string s,pass;
int ind;


int f(){
    int ret;
    if(s[ind] >= 'a' && s[ind] <= 'd'){
        ret = pass[s[ind]-'a'] - '0';
        ind++;
        return ret;
    }else{
        ind++;

        if(s[ind] == '+'){
            ind++;
            int a = f();
            int b = f();
            ret = a | b;
        }else if(s[ind] == '*'){
            ind++;
            int a = f();
            int b = f();
            ret = a & b;
        }else if(s[ind] == '^'){
            ind++;
            int a = f();
            int b = f();
            ret = a ^ b;
        }
        ind++;
    }
    return ret;
}

signed main(void) {
    while(cin >> s, s != "."){
        cin >> pass;
        ind = 0;
        int ret = f();
        int ans = 0;
        rep(a,10)rep(b,10)rep(c,10)rep(d,10){
            pass = "";
            pass += char('0' + a);
            pass += char('0' + b);
            pass += char('0' + c);
            pass += char('0' + d);
            ind = 0;
            if(f() == ret)ans++;
        }
        cout << ret << " " << ans << endl;
    }

}

C++: #include <iostream>

using namespace std;

pair<int, int> solve(string s, string p, int l) {
    if(s[l] == '[') {
//        cerr << "op:" << l << '\n';
        l++;
        char op = s[l];

        auto r = solve(s, p, l + 1);
        auto ret = solve(s, p, r.second);
        int ans;
        if(op == '+'){
            ans = r.first | ret.first;
        }
        else if(op == '*') {
            ans = r.first & ret.first;
        }
        else if(op == '^') {
            ans = r.first ^ ret.first;
        }
        else {
            cerr << "??????\n";
        }
        return {ans, ret.second+1};
    }
    else {
//        cerr << "LT: " << l << '\n';
        return {p[s[l] - 'a'] - '0', l+1};
    }
}

string to_str(int k){
    string ans{"0000"};
    for (int i = 0; i < 4; ++i) {
        ans[3-i] = k % 10 + '0';
        k /= 10;
    }
    return ans;
}

int count(string s, int k){
    int c = 0;
    for (int i = 0; i < 10000; ++i) {
        string p = to_str(i);
        if(k == solve(s, p, 0).first){
            c++;
        }
    }
    return c;
}

int main(){
    string s,p;
    while(1){
        cin >> s;
        if(s == ".") return 0;
        cin >> p;
        int ans = solve(s, p, 0).first;
        int c = count(s, ans);
        cout << ans << ' ' << c << '\n';
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;

int num[4] = {};

int decode(string &s, int &ind) {
  if (s[ind] == '[') {
    ind++;
    int t = decode(s, ind);
    ind++;
    return t;
  } else if (s[ind] == '+') {
    ind++;
    int a = decode(s, ind);
    int b = decode(s, ind);
    return a | b;
  } else if (s[ind] == '*') {
    ind++;
    int a = decode(s, ind);
    int b = decode(s, ind);
    return a & b;
  } else if (s[ind] == '^') {
    ind++;
    int a = decode(s, ind);
    int b = decode(s, ind);
    return a ^ b;
  } else if(s[ind] == ']') {
    ind++;
    return decode(s, ind);
  } else {
    int n = num[s[ind] - 'a'];
    ind++;
    return n;
  }
}

int main() {
  string S;
  while (cin >> S, S != ".") {
    string P;
    cin >> P;
    REP (i, 0, 4) {
      num[i] = P[i] - '0';
    }
    int dummy = 0;
    int hsh = decode(S, dummy);
    cout <<  hsh << " ";
    int ans = 0;
    REP (i, 0, 10000) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
	num[j] = n % 10;
	n /= 10;
      }
      dummy = 0;
      if (hsh == decode(S, dummy)) {
	ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}