// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
int hashed(string hash, int a, int b, int c, int d) {
  stack<int> num;
  int x, y;
  for (int i = hash.length()-1; i >= 0; i--) {
    switch (hash[i]) {
      case 'a':
        num.push(a);
        break;
      case 'b':
        num.push(b);
        break;
      case 'c':
        num.push(c);
        break;
      case 'd':
        num.push(d);
        break;
      case '+':
        x = num.top(); num.pop();
        y = num.top(); num.pop();
        num.push(x|y);
        break;
      case '*':
        x = num.top(); num.pop();
        y = num.top(); num.pop();
        num.push(x&y);
        break;
      case '^':
        x = num.top(); num.pop();
        y = num.top(); num.pop();
        num.push(x^y);
        break;
    }
  }
  return num.top();
}

signed main() {
  string hash;
  while (cin >> hash, hash != ".") {
    int a[4];
    for (int i = 0; i < 4; i++) {
      char c; cin >> c;
      a[i] = c-'0';
    }
    int original = hashed(hash, a[0], a[1], a[2], a[3]);
    int ans = 0;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          for (int l = 0; l < 10; l++) {
            if (original == hashed(hash, i, j, k, l)) {
              ans++;
            }
          }
        }
      }
    }
    cout << original << " " << ans << endl;
  }
}


