#include<iostream>
#include<map>

using namespace std;
using State = string::iterator;
class ParseError{};

map<char, int> vals;
map<pair<char, int>, int> assigns;
string line;

bool parse_declaration(State& begin);
bool parse_assignment(State& begin);
int parse_expression(State& begin);
int parse_number(State& begin);

void debug(State& begin, string msg) {
    cout << line << endl;
    int l = distance(line.begin(), begin);
    for (int i = 0; i < l; ++i) cout << " ";
    cout << "^ " << msg << endl;
}

bool parse_line(State& begin) {
    // debug(begin, "line");
    State start = begin;
    bool ret;
    try {
        ret = parse_declaration(begin);
    } catch(ParseError e) {
        begin = start;
        ret = parse_assignment(begin);
    }
    return ret;
}

bool is_digit(char c) {
    return c - '0' >= 0 && c - '0' <= 9;
}

void newline(State &begin) {
    if (begin != line.end()) throw ParseError();
}
void consume(State &begin, char c) {
    if (*begin != c) {
        // cout << line << endl;
        // debug(begin, string("expected ") + c + string(" but got ") + *begin);
        throw ParseError();
    }
    begin++;
}

bool parse_declaration(State& begin) {
    // debug(begin, "decl");
    char array_name = *begin;
    begin++;
    consume(begin, '[');
    int length = parse_number(begin);
    consume(begin, ']');
    newline(begin);
    vals[array_name] = length;
    return true;
}

bool parse_assignment(State& begin) {
    // debug(begin, "assi");
    char array_name = *begin;
    begin++;
    consume(begin, '[');
    int index = parse_expression(begin);
    if (index == -1) return false;
    consume(begin, ']');
    consume(begin, '=');
    int value = parse_expression(begin);
    newline(begin);
    if (value == -1) return false;
    if (index >= vals[array_name]) return false;
    auto key = make_pair(array_name, index);
    assigns[key] = value;
    return true;
}

int parse_expression(State& begin) {
    if (is_digit(*begin)) {
        return parse_number(begin);
    } else {
        char array_name = *begin;
        begin++;
        consume(begin, '[');
        int index = parse_expression(begin);
        consume(begin, ']');
        if (vals.find(array_name) != vals.end()) {
            auto key = make_pair(array_name, index);
            if (assigns.find(key) != assigns.end()) {
                return assigns[key];
            } else {
                return -1;
            }
        } else {
            return -1;
        }
    }
}


int parse_number(State& begin) {
    int ret = 0;
    while(*begin - '0' >= 0 && *begin - '0' <= 9) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

int main() {
    int cnt = 0;
    int lc = 1;
    int ans = 0;
    while(1) {
        cin >> line;
        if (line == ".") {
            cout << ans << endl;
            vals.clear();
            assigns.clear();
            lc = 1;
            ans = 0;
            cin >> line;
            if (line == ".") break;
        } else {
            cnt = 0;
        }
        if (ans == 0) {
            State begin = line.begin();
            if (!parse_line(begin)) {
                ans = lc;
            }
        }
        lc++;
    }
}


Measured memory_bytes: 3260