#include <stdio.h>
#include <stdlib.h>

/* the number of base-11 digits we have (56 rounded up) */
#define MAX 60

/* We save our base-11 digits in this array */
unsigned int f[MAX];

/* Set all digits to 0 */
void initf(void) {
    int i;
    
    for (i=0; i<MAX; i++) {
        f[i]=0;
    }
}

/* Print the base-11 number */
void print() {
    int i=MAX-1;
    while (f[i]==0) { /* Skip leading zeroes */
        i -= 1;
        if (i<0) { /* Number was all zero at the end... */
            putchar('0');
            putchar('\n');
            return;
        }
    }
    while (i>=0) { /* Now, print all digits */
        if (f[i]==10) {
            putchar(' ');
        } else {
            putchar('0'+f[i]);
        }
        i--;
    }
    putchar('\n');
}

/* Multiply our number with 23
 * We call this function before each new base-23 digit is read.
 */
void multiply(void) {
    int ueber=0, pos=0, zwi=0, alt;
    do { alt = f[pos];
        zwi = f[pos] * 23 + ueber;
        f[pos] = zwi % 11;
        ueber = zwi / 11;
        pos++;
    } while (pos < MAX);
    
    if (ueber != 0) {
        printf("SHIFT OVERFLOW");
        exit(1);
    }
}

/* Add a read base23 digit to our base11 number */
void add(int newdigit) {
    int pos=0;
    int zwi=0;
    int ueber = newdigit;
    do {
        zwi = f[pos] + ueber;
        f[pos] = zwi % 11;
        ueber = zwi / 11;
        pos++;
        if (pos==MAX) {
            printf("ADD OVERFLOW");
            exit(1);
        }
    } while (ueber != 0);
}

/* The main function */
int main(int argc, char* args[]) {
    int c;
    int cur;
    
    /* Initialize our array */
    initf();
    
    /* While we have data in the file: */
    while ((c=getchar()) != EOF) {
        /* We have an "usual" digit */
        if ((c>='0') && (c<='9')) {
            cur = c - '0';
            multiply();
            add(cur);
            
        /* Or maybe we have an small letter digit */
        } else if ((c>='a') && (c<='m')) {
            cur = c - 'a' + 10;
            multiply();
            add(cur);
            
        /* Or, sometimes, we have a capital letter digit */
        } else if ((c>='A') && (c<='M')) {
            cur = c - 'A' + 10;
            multiply();
            add(cur);
            
        /* Everything else has to be a linefeed then. */
        } else {
            print();
            initf();
        }
    }
    return 0;   
}

