#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e3 + 10;   int n;   pair<string, int> a[N];   string ans[N];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       char c;       cin >> c >> c >> c >> c;       cin >> a[i].first;       a[i].second = i;       if (a[i].first ==  9 ) ans[i] =  1989 ;       if (a[i].first ==  99 ) ans[i] =  1999 ;     }     sort(a, a + n);     for (int i = 0; i < n; ++i) {       if (a[i].first.length() == 1) {         if (a[i].first ==  9 ) continue;         ans[a[i].second] =  199 ;         ans[a[i].second] += a[i].first;       } else if (a[i].first.length() == 2) {         if (a[i].first ==  99 ) continue;         ans[a[i].second] =  20 ;         ans[a[i].second] += a[i].first;       } else if (a[i].first.length() == 3) {         if (a[i].first <  100  && a[i].first !=  099 ) {           ans[a[i].second] =  3 ;           ans[a[i].second] += a[i].first;         } else {           ans[a[i].second] =  2 ;           ans[a[i].second] += a[i].first;         }       } else if (a[i].first.length() == 4) {         if ( 0000  <= a[i].first && a[i].first <  3099 ) ans[a[i].second] =  1 ;         ans[a[i].second] += a[i].first;       } else if (a[i].first.length() == 5) {         if ( 00000  <= a[i].first && a[i].first <  13099 ) ans[a[i].second] =  1 ;         ans[a[i].second] += a[i].first;       } else if (a[i].first.length() == 6) {         if ( 000000  <= a[i].first && a[i].first <  113099 )           ans[a[i].second] =  1 ;         ans[a[i].second] += a[i].first;       } else if (a[i].first.length() == 7) {         if ( 0000000  <= a[i].first && a[i].first <  1113099 )           ans[a[i].second] =  1 ;         ans[a[i].second] += a[i].first;       } else if (a[i].first.length() == 8) {         if ( 00000000  <= a[i].first && a[i].first <  11113099 )           ans[a[i].second] =  1 ;         ans[a[i].second] += a[i].first;       } else if (a[i].first.length() == 9) {         if ( 000000000  <= a[i].first && a[i].first <  111113099 )           ans[a[i].second] =  1 ;         ans[a[i].second] += a[i].first;       }     }     for (int i = 0; i < n; ++i) cout << ans[i] << endl;     return 0;   }   