#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long t = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') f = (ch == '-') ? -1 : f, ch = getchar();
  while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
  return t * f;
}
void work(long long num, int l) {
  int t = num % 10, now;
  num /= 10;
  if (t == 9)
    now = 1989;
  else
    now = 1990 + t;
  long long bin = 1;
  for (int i = 2; i <= l; i++) {
    t = num % 10, num /= 10, bin *= 10;
    t *= bin;
    int x = (now / bin) % 10 * bin;
    if (x < t)
      now += t - x;
    else
      now += 10 * bin + t - x;
  }
  printf("%d\n", now);
}
int main() {
  int n = read();
  int xx, len;
  char ch;
  for (int i = 1; i <= n; i++) {
    xx = 0;
    ch = getchar();
    while (ch != '\'') ch = getchar();
    len = 0;
    ch = getchar();
    while (ch >= '0' && ch <= '9')
      xx = xx * 10 + ch - '0', ch = getchar(), len++;
    work(xx, len);
  }
  return 0;
}
