#include <bits/stdc++.h>
using namespace std;
const int N = 1000010, mod = 1e9 + 7, INF = 0x3f3f3f3f;
const double eps = 1e-6;
int n;
long long a[20];
char s[1010];
map<string, int> mp;
int main() {
  a[4] = 3098;
  for (long long i = 5, fun = 10000; i <= 9; i++, fun *= 10)
    a[i] = fun + a[i - 1];
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s + 1);
    long long cnt = 0, sum = 0;
    string ans;
    for (int i = 5; s[i]; i++) cnt++, sum = sum * 10 + s[i] - '0', ans += s[i];
    if (cnt == 1) {
      if (sum <= 8)
        cout << "199" << ans << endl;
      else
        cout << "198" << ans << endl;
    } else if (cnt == 2) {
      if (sum <= 98)
        cout << "20" << ans << endl;
      else
        cout << "19" << ans << endl;
    } else if (cnt == 3) {
      if (sum <= 98)
        cout << "3" << ans << endl;
      else
        cout << "2" << ans << endl;
    } else {
      if (sum <= a[cnt])
        cout << "1" << ans << endl;
      else
        cout << ans << endl;
    }
  }
  return 0;
}
