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 <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;
template<typename T> void test(vector<T> v){for(int i=0;i<v.size();i++){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

int andd(int x,int y){
    int ret=0;
    rep(i,0,4){
        ret+=pow(2,i)*((x%2)&&(y%2));
        x/=2; y/=2;
    }
    return ret;
}

int orr(int x,int y){
    int ret=0;
    rep(i,0,4){
        ret+=pow(2,i)*((x%2)||(y%2));
        x/=2; y/=2;
    }
    return ret;

}

int hashh(string s,string ss){
    stack<int> st;
    int a,b,c,d;
    d=ss[3]-'0'; c=ss[2]-'0'; b=ss[1]-'0'; a=ss[0]-'0';
    reverse(all(s));
    rep(i,0,s.size()){
        if(s[i]=='a')st.push(a);
        else if(s[i]=='b')st.push(b);
        else if(s[i]=='c')st.push(c);
        else if(s[i]=='d')st.push(d);
        else if(s[i]=='+'){
            int x=st.top();
            st.pop();
            int y=st.top();
            st.pop();
            st.push(orr(x,y));
        }else if(s[i]=='*'){
            int x=st.top();
            st.pop();
            int y=st.top();
            st.pop();
            st.push(andd(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 s;
    while(cin>>s&&s!="."){
        string ss;
        cin>>ss;
        int ans=hashh(s,ss);
        cout<<ans<<" ";
        ss="0000";
        int ct=0;
        rep(i,0,10)rep(j,0,10)rep(k,0,10)rep(l,0,10){
            ss[0]='0'+i;
            ss[1]='0'+j;
            ss[2]='0'+k;
            ss[3]='0'+l;
            if(ans==hashh(s,ss)){
                ct++;
            }
        }
        cout<<ct<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {if (a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmin(A &a, B b) {if (a > b) {a = b; return 1;} return 0;}
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/****************************/

struct SyntaxAnalysis {
	string s;
	int i;
	int val;
	
	SystaxAnalysis() {}
	
	int init(string _s) {
		s = _s;
		i = 0;
		
		val = expr(i);
		return val;
	}
	
	int expr(int &i) {
		int res = 0;
		if (s[i] >= '0' && s[i] <= '9') {
			res = s[i] - '0';
		}
		else {
			res = term(++i);
			++i;
		}
		return res;
	}
	
	int term(int &i) {
		int ope;
		if (s[i] == '+') ope = 0;
		else if (s[i] == '*') ope = 1;
		else ope = 2;
		
		int val1 = expr(++i);
		int val2 = expr(++i);
		
		int res;
		if (ope == 0) res = val1 | val2;
		else if (ope == 1) res = val1 & val2;
		else res = val1 ^ val2;
		return res;
	}
};

string make(int i) {
	string num = to_string(i);
	reverse(ALL(num));
	while (num.size() < 4) num += '0';
	reverse(ALL(num));
	return num;
}

string arrange(string str, string num) {
	REP(i, str.size()) {
		if (str[i] >= 'a' && str[i] <= 'd') {
			str[i] = num[str[i]-'a'];
		}
	}
	return str;
}

int main() {
	string s;
	while (cin >> s, s != ".") {
		string num;
		cin >> num;
		
		string tmp = arrange(s, num);
		
		SyntaxAnalysis sa;
		int hsorg = sa.init(tmp);
		
		int ans = 0;
		REP(i, 10000) {
			string cur = make(i);
			if (hsorg == sa.init(arrange(s, cur))) {
				ans++;
			}
		}
		
		if (debug) printf("@ ");
		cout << hsorg << " " << ans << endl;
	}
	return 0;
}

// C