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++: 
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>
#include <sstream>

#define all_range(C) std::begin(C), std::end(C)


struct Tree{
	char ope_type = '\0';
	std::unique_ptr<Tree> node1, node2;
	Tree(){}
	const char* construct(const char* str)
	{
		if (*str == '[') {
			++str;
			ope_type = *str++;
			node1 = std::make_unique<Tree>();
			str = node1->construct(str);
			node2 = std::make_unique<Tree>();
			str = node2->construct(str);
			assert(*str == ']');
			return ++str;
		}
		else {
			ope_type = *str;
			return ++str;
		}
	}
	unsigned hash(const int value[4])
	{
		if (!node1) {
			return value[ope_type - 'a'];
		}
		if (ope_type == '+') {
			return node1->hash(value) | node2->hash(value);
		}
		if (ope_type == '*') {
			return node1->hash(value) & node2->hash(value);
		}
		if (ope_type == '^') {
			return node1->hash(value) ^ node2->hash(value);
		}
		assert(false);
		return 0;
	}
};

int main()
{
	using std::endl;
	using std::cout;
	using std::cin;

	while (true)
	{
		std::string function;
		cin >> function;
		if (function == ".") {
			break;
		}
		std::string pass;
		cin >> pass;

		Tree tree;
		tree.construct(function.c_str());
		int pass_int[4];
		for (int i = 0; i < 4; i++)
		{
			pass_int[i] = pass[i] - '0';
		}
		int count = 0;
		unsigned hash_my = tree.hash(pass_int);
		for (int i = 0; i < 10000; i++)
		{
			pass_int[0] = i;
			pass_int[3] = pass_int[0] % 10; pass_int[0] /= 10;
			pass_int[2] = pass_int[0] % 10; pass_int[0] /= 10;
			pass_int[1] = pass_int[0] % 10; pass_int[0] /= 10;

			if (tree.hash(pass_int) == hash_my) {
				++count;
			}
		}

		cout << hash_my << ' ' << count << std::endl;
	}

	return 0;
}
#endif

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

// hash_parse ::= letter | '[' op hash_parse hash_parse ']'
// op ::= '+' | '*' | '^'
// letter ::= 
//
int hash_parse(const string &str, int &idx, const int data){
	if(isalpha(str[idx])){
		idx++;
		switch(str[idx-1]){
			case 'a': return data/1000;
			case 'b': return (data/100)%10;
			case 'c': return (data/10)%10;
			case 'd': return data%10;
		}
	}
	if('['){
		char op = str[++idx]; ++idx;
		int lhs = hash_parse(str, idx, data);
		int rhs = hash_parse(str, idx, data);
		assert(str[idx] == ']'); ++idx;
		switch(op){
			case '*': return lhs & rhs;
			case '+': return lhs | rhs;
			case '^': return lhs ^ rhs;
		}
	}
	assert(0);
	return -1;
}

signed main(){
	while(true){
		string str; cin >> str;
		if(str == ".")break;
		int idx = 0;
		int raw; cin >> raw;
		int val = hash_parse(str, idx, raw);
		int ans = 0;
		for(int i = 0; i < 10000; i++){
			idx = 0;
			if(val == hash_parse(str, idx, i)){
				ans++;
			}
		}
		cout << val << " " << ans << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
#include <iomanip>
#include <sstream>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int get_hash(void);
int get_val(vector<int>);
char change(char, string);
int get_cnt(int, string);

string s;
int pos;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    while(cin >> s)
    {
        if(s == ".") break;
        string p; cin >> p;
        int num; pos = 0;
        if(s[0] == '[' && s[s.size() - 1] == ']') s = s.substr(1, s.size() - 2);
        string tmp = s;
        for(int i = 0; i < s.size(); i++) s[i] = change(s[i], p);
        num = get_hash();
        cout << num << " " << get_cnt(num, tmp) << endl;
    }
	return 0;
}
int get_cnt(int num, string tmp)
{
    int ret = 0;
    for(int i = 0; i <= 9999; i++)
    {
        s = tmp, pos = 0;
        ostringstream sout;
        sout << setfill('0') << setw(4) << i;
        string password = sout.str();
        for(int i = 0; i < s.size(); i++) s[i] = change(s[i], password);
        int x = get_hash();
        if(x == num) ret++;
    }
    return ret;
}
int get_hash()
{
    vector<int> vec;
    if(s.size() < 3) return s[0] -'0';
    while(s[pos] != ']')
    {
        if(pos >= s.size()) break;
        if(s[pos] == '[')
        {
            pos++;
            vec.push_back(get_hash());
        }
        else
        {
            if(s[pos] >= 48 && s[pos] <= 57) vec.push_back(s[pos] - '0');
            else vec.push_back(s[pos]);
        }
        pos++;
    }
    return get_val(vec);
}
char change(char ch, string p)
{
    if(ch == 'a') return p[0];
    else if(ch == 'b') return p[1];
    else if(ch == 'c') return p[2];
    else if(ch == 'd') return p[3];
    else return ch;
}
int get_val(vector<int> vec)
{
    char ch = (char)vec[0];
    int a = vec[1], b = vec[2];
    if(ch == '+') return a | b;
    else if(ch == '*') return a & b;
    else return a ^ b;
}