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 __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Bool = bool;
using Int = long long int;
using Real = long double;
using Char = char;
using String = std::string;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <class T>
using Matrix = Vector<Vector<T>>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

struct {
    String s;
    Vector<Int> pass;
    Int i;

    Int expr() {
        Int ret;
        if (s[i] == '[') {
            ++i;
            Char op = s[i];
            ++i;
            Int a = expr();
            Int b = expr();
            ++i;

            if (op == '+') {
                ret = (a | b);
            } else if (op == '*') {
                ret = (a & b);
            } else if (op == '^') {
                ret = (a ^ b);
            }
        } else {
            ret = pass[s[i] - 'a'];
            ++i;
        }
        return ret;
    }

    Int operator()() {
        i = 0;
        return expr();
    }

} parser;

Bool solve() {
    std::cin >> parser.s;
    if (parser.s == ".") return false;

    for (Int i = 0; i < 4; ++i) {
        Char c;
        std::cin >> c;
        parser.pass[i] = c - '0';
    }
    Int ans = parser();

    Int cnt = 0;
    for (Int x = 0; x < 10000; ++x) {
        Int y = x;
        for (Int i = 0; i < 4; ++i) {
            parser.pass[i] = y % 10;
            y /= 10;
        }
        if (parser() == ans) ++cnt;
    }

    std::cout << ans << ' ' << cnt << std::endl;
    return true;
}

int main() {
    parser.pass.resize(4);
    while (solve()) {}
    return 0;
}

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

string calc(string s, string t, char ch)
{
    int a = stoi(s), b = stoi(t);
    if(ch == '+') return to_string(a | b);
    if(ch == '*') return to_string(a & b);
    return to_string(a ^ b);
}

int solve(string s, string v)
{
    vector<string> t;
    for(int i = 0; i < (int)s.size(); i++)
    {
        if('a' <= s[i] and s[i] <= 'd')
        {
            string tmp = "";
            tmp += v[s[i] - 'a'];
            while(tmp.size() != 4) tmp.insert(tmp.begin(), '0');
            t.push_back(tmp);
        }
        else
        {
            string tmp = "";
            tmp += s[i];
            t.push_back(tmp);
        }
    }

    stack<string> st;
    for(int i = 0; i < (int)t.size(); i++)
    {
        if(t[i] == "]")
        {
            string res = "";
            while(true)
            {
                string ch = st.top(); st.pop();
                if(ch == "[") break;
                res += ch;
            }
            res = calc(res.substr(0, 4), res.substr(4, 4), res.back());
            while(res.size() != 4) res.insert(res.begin(), '0');
            st.push(res);
        }
        else
        {
            st.push(t[i]);
        }
    }
    return stoi(st.top());
}

int main(void)
{
    string s, v;
    while(cin >> s, s != ".")
    {
        cin >> v;
        int ans = solve(s, v);
        int cnt = 0;
        for(int i = 0; i <= 9999; i++)
        {
            string t = to_string(i);
            while(t.size() != 4) t.insert(t.begin(), '0');
            int v = solve(s, t);
            if(v == ans) cnt++;
        }
        cout << ans << " " << cnt << endl;
    }
    return 0;
}