// G. Hagopian doing Kattis Owl and Fox problem...in progress..

#include <sstream>
#include <iostream>

using namespace std;

string backwards(string st) {
	string reverse;
	for (int i = st.size() - 1; i >= 0; --i)
		reverse += st[i];
	return reverse;
}

int findAnswer(int n) {
	char ch;
	stringstream ss{};
	ostringstream output{};
	bool done = false;
	//cout << "hi\n";
	ss << n;  //extract the contents of the int n into the stringstream ss
	//cout << "mom";
	//cout << ss.str() << endl;
	string reverse = backwards(ss.str());
	ss.str(reverse); //replace ss's string with the reverse of it
	//cout << "ss.str() == " << ss.str() << endl;
	//cin.get();
	while (ss >> ch) {  // read digit characters one at a time from left to right
		//cout << ch;
		//cin.get();
		if (ch > 48 && !done) { // the ascii value of '0' is 48, so ch > 48 means it's a positive digit
			output << char(--ch); //the first non zero digit gets decremented by 1
			done = true; //only do this once
		}
		else
			output << ch;
	}
	//cout << "output.str() == " << output.str() << endl;
	//cout << "stoi(" << output.str() << ") == " << stoi(output.str()) << endl;
	return stoi(backwards(output.str()));
}

int main() {
	int T, N;
	cin >> T;
	while (T--) {
		//cout << "T = " << T << endl;
		cin >> N;
		cout << findAnswer(N) << endl;
	}
}