#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

string sum(string a, string b) {
	if (a.size() > b.size()) swap(a, b);
	
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	
	string res = "";
	int c = 0;
	REP(i, a.size()) {
		c += a[i] - '0' + b[i] - '0';
		res.push_back(c % 10 + '0');
		c /= 10;
	}
	FOR(i, a.size(), b.size()) {
		c += b[i] - '0';
		res.push_back(c % 10 + '0');
		c /= 10;
	}
	if (c > 0) res.push_back(c + '0');
	
	reverse(res.begin(), res.end());
	
	return res;
}

int main() {
	int T;
	cin >> T; cin.ignore();
	while (T--) {
		string S;
		getline(cin, S);
		
		int p[10];
		memset(p, -1, sizeof(p));
		
		REP(i, 10) {
			if (S.rfind(i + '0') == string::npos) continue;
			p[i] = S.rfind(i + '0');
		}
		
		int r = -1;
		REP(i, 10) chmax(r, p[i]);
		
		if (r == -1) {
			cout << S << endl;
			continue;
		}
		
		int l = r;
		while (l >= 0 && isdigit(S[l])) l--;
		l++;
		
		string ans = S.substr(0, l);
		
		string num = sum(S.substr(l, r - l + 1), "1");
		
		ans += num;
		ans += S.substr(r + 1, S.size());
		
		cout << ans << endl;
	}
	return 0;
}