import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto s = readln.strip;
		auto t = s[4..$];
		auto v = t.to !(long);
		long n = 1989 - 1;
		int len = 1;
		while (len <= t.length)
		{
			do
			{
				n += 10L ^^ (len - 1);
			}
			while (n.text[$ - len..$] != t[$ - len..$]);
			len++;
		}
		writeln (n);
	}
}
