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 sindex = 0;
int parse() {
	if (isalpha(s[sindex])) {
		return p[s[sindex++] - 'a'] - '0';
	}
	else {
		int x, y;
		sindex++;
		char op = s[sindex++];
		x = parse();
		y = parse();
		sindex++;
		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;
		sindex = 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';
			sindex = 0;

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

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



	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef string::const_iterator SC;
const int MOD = 1000000007;
const ll INF=2e18;

string s;
string p;
map<char,ll> mp;
ll Letter(SC &it){
    ll ret= mp[*it];
    it++;
    return ret;
}
ll Hash(SC &it){
    if(isalpha(*it)){
        return Letter(it);
    }
    else{
        it++;//[
        char op=*it;
        it++;//op
        ll l=Hash(it);
        ll r=Hash(it);
        it++;//]
        if(op=='+'){
            return l | r;
        }else if(op=='*'){
            return l & r;
        }else{
            return l^r;
        }
    }
}
int main(){
    while(cin>>s,s[0]!='.'){
        cin>>p;
        mp['a']=p[0]-'0';
        mp['b']=p[1]-'0';
        mp['c']=p[2]-'0';
        mp['d']=p[3]-'0';
        SC it=s.begin();
        ll hashNum=Hash(it);
        cout<<hashNum<<" ";
        ll ans=0;
        for(ll i=0;i<10000;i++){
            ll tmp=i;
            ll t[4];
            for(ll j=0;j<4;j++){
                ll mod=pow(10,3-j);
                t[j]=tmp/mod;
                tmp%=mod;
            }
            mp['a']=t[0];
            mp['b']=t[1];
            mp['c']=t[2];
            mp['d']=t[3];
            it=s.begin();
            if(Hash(it)==hashNum){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{
	string S;
	while (cin >> S, S != ".") {
		int P;
		cin >> P;
		reverse(S.begin(), S.end());
		vector<int> hs(10000);
		for (int x = 0; x < 10000; x++) {
			vector<int> v = { x / 1000, x % 1000 / 100, x % 100 / 10, x % 10 };
			vector<int> vs;
			for (auto c : S) {
				if ('a' <= c && c <= 'd') {
					vs.push_back(v[c - 'a']);
				}
				if (c == '+') {
					int a = vs.back(); vs.pop_back();
					int b = vs.back(); vs.pop_back();
					vs.push_back(a | b);
				}
				if (c == '*') {
					int a = vs.back(); vs.pop_back();
					int b = vs.back(); vs.pop_back();
					vs.push_back(a & b);
				}
				if (c == '^') {
					int a = vs.back(); vs.pop_back();
					int b = vs.back(); vs.pop_back();
					vs.push_back(a ^ b);
				}
			}
			hs[x] = vs.back();
		}
		cout << hs[P] << ' ' << count(hs.begin(), hs.end(), hs[P]) << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <tuple>

int parse(std::string const& s, size_t& i) {
  if (isdigit(s[i])) return s[i++]-'0';

  assert(s[i] == '[');
  ++i;
  char op = s[i++];
  int lhs = parse(s, i);
  int rhs = parse(s, i);
  assert(s[i] == ']');
  ++i;

  if (op == '+') return lhs | rhs;
  if (op == '*') return lhs & rhs;
  if (op == '^') return lhs ^ rhs;
  assert(false);
}

int testcase_ends() {
  char buf[128];
  scanf("%s", buf);
  std::string s = buf;
  if (s == ".") return 1;

  char a, b, c, d;
  scanf(" %c%c%c%c", &a, &b, &c, &d);

  std::string t = s;
  for (auto& ti: t) {
    if (ti == 'a') ti = a;
    if (ti == 'b') ti = b;
    if (ti == 'c') ti = c;
    if (ti == 'd') ti = d;
  }

  size_t k = 0;
  int hash = parse(t, k);
  int res = 0;
  for (size_t i = 0; i < 10000; ++i) {
    std::string t = s;
    char abcd[4] = {};
    for (int j = 0, tmp = i; j < 4; ++j) {
      abcd[3-j] = '0' + (tmp % 10);
      tmp /= 10;
    }
    char a, b, c, d;
    a = abcd[0];
    b = abcd[1];
    c = abcd[2];
    d = abcd[3];
    for (auto& ti: t) {
      if (ti == 'a') ti = a;
      if (ti == 'b') ti = b;
      if (ti == 'c') ti = c;
      if (ti == 'd') ti = d;
    }

    size_t k = 0;
    int hash0 = parse(t, k);
    if (hash0 == hash) ++res;
  }

  printf("%d %d\n", hash, res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}