#include <bits/stdc++.h>

using namespace std;

const int NMax = 1e5 + 5;
string CHAR ("char");
string SHORT ("short");
string INT ("int");
string UNSIG ("unsigned");

pair < int, int > v[NMax];

inline int getType(string s) {
    if(s == CHAR) return 1;
    if(s == SHORT) return 2;
    if(s == INT) return 4;
    return 0;
}

int main() {

    string type;
    cin >> type;
    if(type == UNSIG) cin >> type;

    int memUsed = 0;
    string s;
    while(cin >> s) {
        int n = (int)s.size();

        memUsed = 0;
        int aux = 0;
        for(int i = 0; i < n; i++) {
            if(s[i] == ',') {
                memUsed += getType(type);
                continue;
            }
            if(s[i] == '[') {
                aux = getType(type);
                while(i < n && s[i] == '[') {
                    i++;

                    int x = 0;
                    while(isdigit(s[i])) {
                        x = x * 10 + (s[i] - '0');
                        i++;
                    }
                    i++;

                    aux = aux * x;
                }

                memUsed += aux;
            }
        }

        if(s[n - 1] != ']') memUsed += getType(type);
        cout << memUsed << "\n";

        if(cin >> type) {
            if(type == UNSIG) cin >> type;
        } else {
            return 0;
        }
    }

    return 0;
}