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 <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;
}

C++: #include<bits/stdc++.h>
#define LL long long
#define REP(i, n) for(int i=0;i<(n);++i)
#define REPA(i, n) for(int i=1;i<(n);++i)
#define lp(i, n) for(int i=-;i<(n);++i)
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define DEKAI ((int)1e9+7)
#define ALL(x) (x).begin(), (x).end()
#define BIT(x) (1<<(x))
#define foreach(i, n) for(auto &i:(n))
using namespace std;

int num;
int getnum(char c){
    int x = num;
    if(c=='a')return (x/1000)%10;
    if(c=='b')return (x/100)%10;
    if(c=='c')return (x/10)%10;
    if(c=='d')return x%10;
}

PII func(string &str, int place){
    if(str[place]!='[')return PII(getnum(str[place]), place+1);
    ++place;
    PII res=PII(0, 0);
    if(str[place]=='+'){
        ++place;
        res = func(str, place);
        place=res.second;
        PII d = func(str, place);
        res.first|=d.first;
        res.second=d.second;
    }else if(str[place]=='*'){
        ++place;
        res = func(str, place);
        place=res.second;
        PII d = func(str, place);
        res.first&=d.first;
        res.second=d.second;
    }else{
        ++place;
        res = func(str, place);
        place=res.second;
        PII d = func(str, place);
        res.first^=d.first;
        res.second=d.second;
    }
    ++res.second;
    return res;
}

int main(){
    string str;
    while(cin>>str&&str!="."){
        cin >> num;
        int ans = func(str, 0).first;
        int count = 0;
        REP(i, 10000){
            num=i;
            if(func(str, 0).first==ans)++count;
        }
        cout << ans << " " << count << endl;
    }
    return 0;
}