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++: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

string s;
string p;


int index = 0;
int parse() {
	if (isalpha(s[index])) {
		return p[s[index++] - 'a'] - '0';
	}
	else {
		int x, y;
		index++;
		char op = s[index++];
		x = parse();
		y = parse();
		index++;
		if (op == '+')return x | y;
		else if (op == '*')return x & y;
		else return x^y;
	}
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);


	

	while(cin>>s>>p){
		int ans = 0;
		index = 0;
		int h = parse();
		rep(x, 10000) {
			p[0] = x / 1 % 10 + '0';
			p[1] = x / 10 % 10 + '0';
			p[2] = x / 100 % 10 + '0';
			p[3] = x / 1000 % 10 + '0';
			index = 0;

			int g = parse();
			if (h == g)ans++;
		}

		cout << h << ' ' << ans << endl;
	}



	return 0;
}

C++: //#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <stack>

using namespace std;

int calc(string s, string x){
  stack<char> st;
  
  for(int i=0;i<(int)s.size();i++){
    if(s[i] == '[') continue;

    if('a' <= s[i] && s[i] <= 'd'){
      st.push(x[s[i]-'a'] - '0');
    }else if (s[i] != ']') {
      st.push(s[i]);
    }else{      
      char a = st.top(); st.pop();
      char b = st.top(); st.pop();
      char c = st.top(); st.pop();
        
      if(c == '+') st.push(a | b);
      if(c == '*') st.push(a & b);
      if(c == '^') st.push(a ^ b);
    }
  }

  return st.top();  
}

bool solve(){
  string s; string p;

  cin >> s >> p;

  if(s == ".") return false;
  
  int hash = calc(s, p);

  int ans = 0;
  
  for(int i=0;i<=9999;i++){
    char c[5];
    sprintf(c, "%04d", i);
    string t = c;

    ans += hash == calc(s, t);
  }

  cout << hash << " " << ans << endl;

  return true;
}

int main(){
  while(solve());


}

C++: #include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)

int enzan(int num1,int num2,int clc){
  int numa[4];
  int numb[4];
  int ans[4];
  lp(i,4){
    numa[i]=0;
    numb[i]=0;
  }
  if(num1>=8){
    numa[0]=1;
    num1-=8;
  }
  if(num1>=4){
    numa[1]=1;
    num1-=4;
  }
  if(num1>=2){
    numa[2]=1;
    num1-=2;
  }
  if(num1>=1){
    numa[3]=1;
    num1-=1;
  }
  if(num2>=8){
    numb[0]=1;
    num2-=8;
  }
  if(num2>=4){
    numb[1]=1;
    num2-=4;
  }
  if(num2>=2){
    numb[2]=1;
    num2-=2;
  }
  if(num2>=1){
    numb[3]=1;
    num2-=1;
  }
  //  lp(i,4){
  //  cout<<numa[i];
  //}
  //cout<<endl;
  //lp(i,4){
  //  cout<<numb[i];
  //}
  //cout<<endl;

  lp(i,4){
    if(clc==1){
      if(numa[i]==1&&numb[i]==1) ans[i]=1;
      else ans[i]=0;
    }
    if(clc==2){
      if(numa[i]==numb[i]) ans[i]=0;
      else ans[i]=1;
    }
    if(clc==3){
      if(numa[i]==0&&numb[i]==0) ans[i]=0;
      else ans[i]=1;
    }
  }
  return ans[0]*8+ans[1]*4+ans[2]*2+ans[3]*1;
}


int change(string calc){
  while(1){
    int num=0,ca=0;
    int memo[2];
    //int hoge;
    //cout<<calc<<endl;
    //cin>>hoge;
    if(calc.size()==1) break;
    for(int i=0;i<calc.size();i++){
      if(calc[i]=='['){
	num=0;
	ca=0;
      }
      if(calc[i]=='*') ca=1;
      if(calc[i]=='^') ca=2;
      if(calc[i]=='+') ca=3;
      if('0'<=calc[i]&&calc[i]<='9'){
	memo[num]=calc[i]-'0';
	num++;
      }
      if('a'<=calc[i]&&calc[i]<='z'){
	memo[num]=calc[i]-'a'+10;
	num++;
      }
      if(calc[i]==']'){
	if(num==1){
	  calc.erase(i,1);
	  calc.erase(i-2,1);
	  break;
	}
	else if(num==2){
	  int memori=enzan(memo[0],memo[1],ca);
	  if(memori<=9){
	    calc[i-1]=memori+'0';
	    calc.erase(i-2,1);
	    calc.erase(i-3,1);
	  }
	  else{
	    calc[i-1]=memori-10+'a';
	    calc.erase(i-2,1);
	    calc.erase(i-3,1);
	  }
	  break;
	}
      }
    }
  }
  if('a'<=calc[0]&&calc[0]<='z') return calc[0]-'a'+10;
  return calc[0]-'0';
}


int main(){
  while(1){
    string cast;
    cin>>cast;
    if(cast==".") break;
    int mez;
    cin>>mez;
    int xx[20];
    lp(i,20) xx[i]=0;
    int ansmemo;
    for(int i=0;i<10000;i++){
      string calc=cast;
      char a,b,c,d;
      a='0'+i/1000;
      b='0'+i%1000/100;
      c='0'+i%100/10;
      d='0'+i%10;
      lp(j,calc.size()){
	if(calc[j]=='a'){
	  calc[j]=a;
	}
	if(calc[j]=='b'){
	  calc[j]=b;
	}
	if(calc[j]=='c'){
	  calc[j]=c;
	}
	if(calc[j]=='d'){
	  calc[j]=d;
	}
      }
      int mems=change(calc);
      if(mez==i) ansmemo=mems;
      xx[mems]++;
    }
    cout<<ansmemo<<" "<<xx[ansmemo]<<endl;
  }
  return 0;
}