#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int k = 0; k <= t; k++) {
    char a[1000];
    int i = 4;
    gets(a);
    int x = strlen(a);
    long long int n = atoi(a + i);
    int len = x - i;
    if (len == 1) {
      if (n == 9)
        cout << "1989"
             << "\n";
      else
        cout << "199" << n << "\n";
    } else if (len == 2) {
      if (n == 99)
        cout << "19" << n << "\n";
      else if (n >= 0 && n <= 9)
        cout << "200" << n << "\n";
      else
        cout << "20" << n << "\n";
    } else if (len == 3) {
      if (n == 99)
        cout << "20" << n << "\n";
      else if (n >= 0 && n <= 9)
        cout << "300" << n << "\n";
      else if (n >= 10 && n <= 98)
        cout << "30" << n << "\n";
      else
        cout << "2" << n << "\n";
    } else if (len == 4) {
      if (n >= 0 && n <= 9)
        cout << "1000" << n << "\n";
      else if (n >= 10 && n <= 99)
        cout << "100" << n << "\n";
      else if (n >= 100 && n <= 999)
        cout << "10" << n << "\n";
      else if (n >= 1000 && n <= 3098)
        cout << "1" << n << "\n";
      else
        cout << n << "\n";
    } else if (len == 5) {
      if (n >= 0 && n <= 9)
        cout << "10000" << n << "\n";
      else if (n >= 10 && n <= 99)
        cout << "1000" << n << "\n";
      else if (n >= 100 && n <= 999)
        cout << "100" << n << "\n";
      else if (n >= 1000 && n <= 9999)
        cout << "10" << n << "\n";
      else if (n >= 10000 && n <= 13098)
        cout << "1" << n << "\n";
      else
        cout << n << "\n";
    } else if (len == 6) {
      if (n >= 0 && n <= 9)
        cout << "100000" << n << "\n";
      else if (n >= 10 && n <= 99)
        cout << "10000" << n << "\n";
      else if (n >= 100 && n <= 999)
        cout << "1000" << n << "\n";
      else if (n >= 1000 && n <= 9999)
        cout << "100" << n << "\n";
      else if (n >= 10000 && n <= 99999)
        cout << "10" << n << "\n";
      else if (n >= 100000 && n <= 113098)
        cout << "1" << n << "\n";
      else
        cout << n << "\n";
    } else if (len == 7) {
      if (n >= 0 && n <= 9)
        cout << "1000000" << n << "\n";
      else if (n >= 10 && n <= 99)
        cout << "100000" << n << "\n";
      else if (n >= 100 && n <= 999)
        cout << "10000" << n << "\n";
      else if (n >= 1000 && n <= 9999)
        cout << "1000" << n << "\n";
      else if (n >= 10000 && n <= 99999)
        cout << "100" << n << "\n";
      else if (n >= 100000 && n <= 999999)
        cout << "10" << n << "\n";
      else if (n >= 1000000 && n <= 1113098)
        cout << "1" << n << "\n";
      else
        cout << n << "\n";
    } else if (len == 8) {
      if (n >= 0 && n <= 9)
        cout << "10000000" << n << "\n";
      else if (n >= 10 && n <= 99)
        cout << "1000000" << n << "\n";
      else if (n >= 100 && n <= 999)
        cout << "100000" << n << "\n";
      else if (n >= 1000 && n <= 9999)
        cout << "10000" << n << "\n";
      else if (n >= 10000 && n <= 99999)
        cout << "1000" << n << "\n";
      else if (n >= 100000 && n <= 999999)
        cout << "100" << n << "\n";
      else if (n >= 1000000 && n <= 9999999)
        cout << "10" << n << "\n";
      else if (n >= 10000000 && n <= 11113098)
        cout << "1" << n << "\n";
      else
        cout << n << "\n";
    } else if (len == 9) {
      if (n >= 0 && n <= 9)
        cout << "100000000" << n << "\n";
      else if (n >= 10 && n <= 99)
        cout << "10000000" << n << "\n";
      else if (n >= 100 && n <= 999)
        cout << "1000000" << n << "\n";
      else if (n >= 1000 && n <= 9999)
        cout << "100000" << n << "\n";
      else if (n >= 10000 && n <= 99999)
        cout << "10000" << n << "\n";
      else if (n >= 100000 && n <= 999999)
        cout << "1000" << n << "\n";
      else if (n >= 1000000 && n <= 9999999)
        cout << "100" << n << "\n";
      else if (n >= 10000000 && n <= 99999999)
        cout << "10" << n << "\n";
      else if (n >= 100000000 && n <= 111113098)
        cout << "1" << n << "\n";
      else
        cout << n << "\n";
    }
  }
  return 0;
}
