#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> total;
  int d, num, item, ko, cont = 0;
  while (cin >> d) {
    if (d == 0) break;
    cin.ignore();
    for (int i = 0; i < d; i++) {
      cin >> num >> item >> ko;
      item *= ko;
      if (item >= 1000000) {
        cont++;
        total.insert(make_pair(cont, num));
      }
    }
    if (total.size()) {
      map<int, int>::iterator it;
      for (it = total.begin(); it != total.end(); it++) {
        cout << (*it).second << endl;
      }
    } else
      cout << "MA" << endl;
    cont = 0;
    total.clear();
  }
}
