#include using namespace std; using ll = long long; bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; } bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; } #include using mint = atcoder::modint998244353; ll digit_sum(ll x) { ll ret = 0; while(x) { ret += x % 10; x /= 10; } return ret; } bool is_monotonic(ll x) { int p = 10, q; while(x) { q = x % 10; if(p < q) return false; x /= 10; swap(p, q); } return true; } bool is_forever_monotonic(ll x) { while(x >= 10) { if(!is_monotonic(x)) return false; x = digit_sum(x); } return true; } vector A; void precalc() { vector v; for(int i = 0; i < 15; i++) v.push_back(0); for(int i = 0; i < 9; i++) v.push_back(1); do { ll x = 0, s = 0; for(int f : v) { if(f) s += 1; else x = 10 * x + s; } if(is_forever_monotonic(x)) A.push_back(x); }while(next_permutation(v.begin(), v.end())); } mint repunit(ll len) { if(len == 0) { return 0; }else if(len % 2 == 1) { return 1 + 10 * repunit(len - 1); }else { mint r = repunit(len / 2); return r + mint(10).pow(len / 2) * r; } } void sol(ll N) { ll L = *lower_bound(A.begin(), A.end(), N + 1) - (N + 1); ll m = L / 8, r = L % 8; mint ans; // cout << repunit(1).val() << endl; // cout << L << " " << m << " " << r << endl; ans += repunit(N + 1); ans += 8 * repunit(m); ans += r * mint(10).pow(m); cout << ans.val() << endl; } void solve() { ll N; cin >> N; ll n = N; for(;; n++) { ll L = *lower_bound(A.begin(), A.end(), n + 1) - (n + 1); if(8 * (n + 1) >= L) { sol(n); break; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); precalc(); // cout << A.size() << endl; // sort(A.begin(), A.end()); // for(ll a : A) cout << a << "\n"; int T; cin >> T; while(T--) solve(); }