/*  -*- coding: utf-8 -*-
 *
 * 2883.cc: Proof of Knowledge
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 4;
const char opcs[] = "abcd+*^";

/* typedef */

enum { OP_A, OP_B, OP_C, OP_D, OP_OR, OP_AND, OP_XOR };

struct Node {
  int op;
  Node *lpt, *rpt;
  Node() {}

  int calc(int ps[]) {
    if (op >= OP_A && op <= OP_D) return ps[op];
    int c0 = lpt->calc(ps), c1 = rpt->calc(ps), r;
    switch (op) {
    case OP_OR:  r = (c0 | c1); break;
    case OP_AND: r = (c0 & c1); break;
    case OP_XOR: r = (c0 ^ c1); break;
    }
    return r;
  }

  void print(int *ps = NULL) {
    if (op >= OP_A && op <= OP_D) {
      if (ps != NULL) printf("%d", ps[op]);
      else putchar('a' + op);
    }
    else {
      putchar('(');
      lpt->print(ps);
      putchar(opcs[op]);
      rpt->print(ps);
      putchar(')');
    }
  }
};

/* global variables */

char cmap[256];
char se[84], sp[6];
int ps[N], qs[N];
Node buf[80], *bpt;

/* subroutines */

Node *parse(char *(&cpt)) {
  Node *npt = bpt++;
  char c = *(cpt++);
  if (c == '[') {
    npt->op = cmap[*(cpt++)];
    npt->lpt = parse(cpt);
    npt->rpt = parse(cpt);
    cpt++; // ']'
  }
  else
    npt->op = cmap[c], npt->lpt = npt->rpt = NULL;
  return npt;
}

/* main */

int main() {
  for (int i = 0; opcs[i]; i++) cmap[opcs[i]] = i;

  while (scanf("%s", se) == 1 && se[0] != '.') {
    scanf("%s", sp);
    for (int i = 0; i < N; i++) qs[i] = sp[i] - '0';

    bpt = buf;
    char *cpt = se;
    Node *exp = parse(cpt);
    //exp->print(); putchar('\n');

    int qh = exp->calc(qs);
    //exp->print(qs); printf("=%d\n", qh);

    memset(ps, 0, sizeof(ps));
    int cnt = 0;

    for (;;) {
      int ph = exp->calc(ps);
      if (ph == qh) cnt++;

      int k = 0;
      while (k < N) {
	if (++ps[k] < 10) break;
	ps[k++] = 0;
      }
      if (k >= N) break;
    }

    printf("%d %d\n", qh, cnt);
  }
  return 0;
}

