#include using namespace std; /* 型, 定数 */ using ll = long long; using ull = unsigned long long; using i128 = __int128; using ld = long double; // cout << fixed << setprecision(10); const ll INF = 1e18; const ld PI = acos(-1); const ll MOD = 998244353; // const ll MOD = 1000000007; /* 関数 */ #define ctoll(x) static_cast(x - '0') #define lltos(x) to_string(x) #define lltoc(x) static_cast(x + '0') #define all(v) (v).begin(),(v).end() #define len(v) ll(v.size()) template auto min(const vector& a){ return *min_element(all(a)); } template auto min(const set& s){ return *(s.begin()); } template auto min(const map& mp){ return *(mp.begin()); } template auto max(const T& a){ return *max_element(all(a)); } template auto max(const set& s){ return *(--s.end()); } template auto max(const map& mp){ return *(--mp.end()); } templatell count(const T& a, const U& b){ return count(all(a), b); } template long long index(const T& ctr, const T& subctr) { auto itr = search(ctr.begin(), ctr.end(), subctr.begin(), subctr.end()); if(itr == ctr.end()){ return -1; }else{ return distance(ctr.begin(), itr); } } template auto sum(vector& v){ return accumulate(v.begin(), v.end(), 0LL); } template vector cum(vector &v){ vector s = {0}; for(ll i = 0; i < (ll)v.size(); i++) s.push_back(s[i] + v[i]); return s; } ll powll(ll n, ll r){ if (r == 0) return 1; else if (r % 2 == 0) return powll(n * n, (ll)(r / 2)); else return n * powll(n, r - 1); } template unordered_map ucounter(vector &v){ unordered_map mp; for(ll i = 0; i < (ll)v.size(); i++) mp[v[i]]++; return mp; } unordered_map ucounter(string &v){ unordered_map mp; for(ll i = 0; i < (ll)v.size(); i++) mp[v[i]]++; return mp; } template map counter(vector &v){ map mp; for(ll i = 0; i < (ll)v.size(); i++) mp[v[i]]++; return mp; } map counter(string &v){ map mp; for(ll i = 0; i < (ll)v.size(); i++) mp[v[i]]++; return mp; } #define unique(v) sort(all(v)), v.erase(unique(all(v)), v.end()), v.shrink_to_fit() template auto reverse(T& x){ return reverse(x.begin(), x.end()); } template void chmin(T& a, T b) { a = min(a, b); } template void chmax(T& a, T b) { a = max(a, b); } template ll bisect_left(vector &X, ll v){ return lower_bound(X.begin(), X.end(), (ll)v) - X.begin(); } template ll bisect_right(vector &X, ll v){ return upper_bound(X.begin(), X.end(), (ll)v) - X.begin(); } /* ソート */ template auto sort(vector& v){ return stable_sort(v.begin(), v.end()); } template auto sort(vector& v, U idx){ return stable_sort(v.begin(), v.end(), [&](const vector &_a_, const vector &_b_){return _a_[idx] < _b_[idx];}); } template auto rsort(vector& v){ return stable_sort(v.rbegin(), v.rend()); } template auto rsort(vector& v, U idx){ return stable_sort(v.rbegin(), v.rend(), [&](const vector &_a_, const vector &_b_){return _a_[idx] < _b_[idx];}); } /* ループ */ #define OVERLOAD_REP(_1, _2, _3, _4, name, ...) name #define REP1(i, n) for (ll i = (ll)0; i != (ll)n; ++i) #define REP2(i, l, r) for (ll i = (ll)l; i != (ll)r; ++i) #define REP3(i, l, r, s) for (ll i = (ll)l; i < (ll)r; i += (s)) #define rep(...) OVERLOAD_REP(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__) #define OVERLOAD_RREP(_1, _2, _3, _4, name, ...) name #define RREP1(i, n) for (ll i = (ll)n; i != (ll)-1; --i) #define RREP2(i, l, r) for (ll i = (ll)l; i != (ll)r; --i) #define RREP3(i, l, r, s) for (ll i = (ll)l; i > (ll)r; i -= (s)) #define rrep(...) OVERLOAD_RREP(__VA_ARGS__, RREP3, RREP2, RREP1)(__VA_ARGS__) #define OVERLOAD_FORE(_1, _2, _3, name, ...) name #define FORE1(i, a) for(auto &i : a) #define FORE2(i, j, a) for(auto &[i, j] : a) #define fore(...) OVERLOAD_FORE(__VA_ARGS__, FORE2, FORE1)(__VA_ARGS__) /* コンテナ */ #define discard(s, x) {auto itr_ = s.find((x)); if (itr_ != s.end()) s.erase(itr_); } template using pq = priority_queue; // 大きい順に取り出す template using pqg = priority_queue, greater>; // 小さい順に取り出す // unordered_set, unordered_multiset, unordered_map, unordered_multimap で pair, vector, tuple を key に設定させる template size_t HashCombine(const size_t seed,const T &v){ return seed^(std::hash()(v)+0x9e3779b9+(seed<<6)+(seed>>2)); } template struct std::hash>{ size_t operator()(const std::pair &keyval) const noexcept { return HashCombine(std::hash()(keyval.first), keyval.second); } }; template struct std::hash>{ size_t operator()(const std::vector &keyval) const noexcept { size_t s=0; for (auto&& v: keyval) s=HashCombine(s,v); return s; } }; template struct HashTupleCore{ template size_t operator()(const Tuple &keyval) const noexcept{ size_t s=HashTupleCore()(keyval); return HashCombine(s,std::get(keyval)); } }; template <> struct HashTupleCore<0>{ template size_t operator()(const Tuple &keyval) const noexcept{ return 0; } }; template struct std::hash>{ size_t operator()(const tuple &keyval) const noexcept { return HashTupleCore>::value>()(keyval); } }; // modint // https://github.com/drken1215/algorithm/blob/master/MathNumberTheory/modint.cpp template struct Fp { // inner value long long val; // constructor constexpr Fp() : val(0) { } constexpr Fp(long long v) : val(v % MOD) { if (val < 0) val += MOD; } // getter constexpr long long get() const { return val; } constexpr int get_mod() const { return MOD; } // comparison operators constexpr bool operator == (const Fp &r) const { return this->val == r.val; } constexpr bool operator != (const Fp &r) const { return this->val != r.val; } // arithmetic operators constexpr Fp& operator += (const Fp &r) { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp &r) { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp &r) { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp &r) { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b, swap(a, b); u -= t * v, swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr Fp operator + () const { return Fp(*this); } constexpr Fp operator - () const { return Fp(0) - Fp(*this); } constexpr Fp operator + (const Fp &r) const { return Fp(*this) += r; } constexpr Fp operator - (const Fp &r) const { return Fp(*this) -= r; } constexpr Fp operator * (const Fp &r) const { return Fp(*this) *= r; } constexpr Fp operator / (const Fp &r) const { return Fp(*this) /= r; } // other operators constexpr Fp& operator ++ () { ++val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -- () { if (val == 0) val += MOD; --val; return *this; } constexpr Fp operator ++ (int) { Fp res = *this; ++*this; return res; } constexpr Fp operator -- (int) { Fp res = *this; --*this; return res; } friend constexpr istream& operator >> (istream &is, Fp &x) { is >> x.val; x.val %= MOD; if (x.val < 0) x.val += MOD; return is; } friend constexpr ostream& operator << (ostream &os, const Fp &x) { return os << x.val; } // other functions constexpr Fp pow(long long n) const { Fp res(1), mul(*this); while (n > 0) { if (n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } constexpr Fp inv() const { Fp res(1), div(*this); return res / div; } friend constexpr Fp pow(const Fp &r, long long n) { return r.pow(n); } friend constexpr Fp inv(const Fp &r) { return r.inv(); } }; // Binomial coefficient template struct BiCoef { vector fact_, inv_, finv_; constexpr BiCoef() {} constexpr BiCoef(int n) : fact_(n, 1), inv_(n, 1), finv_(n, 1) { init(n); } constexpr void init(int n) { fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1); int MOD = fact_[0].get_mod(); for(int i = 2; i < n; i++){ fact_[i] = fact_[i-1] * i; inv_[i] = -inv_[MOD%i] * (MOD/i); finv_[i] = finv_[i-1] * inv_[i]; } } constexpr mint com(int n, int k) const { if (n < k || n < 0 || k < 0) return 0; return fact_[n] * finv_[k] * finv_[n-k]; } constexpr mint fact(int n) const { if (n < 0) return 0; return fact_[n]; } constexpr mint inv(int n) const { if (n < 0) return 0; return inv_[n]; } constexpr mint finv(int n) const { if (n < 0) return 0; return finv_[n]; } }; using mint = Fp; /* input */ inline void scan(){} template inline void scan(Head&head,Tail&... tail){std::cin >> head; scan(tail...);} #define LL(...) long long __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) long double __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHAR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define VEC(type, name, size) \ vector name(size); \ for(auto &x: name) cin >> x #define VEC2(type1, name1, type2, name2, size) \ vector name1(size); \ vector name2(size); \ rep(i, size) cin >> name1[i] >> name2[i]; #define VEC3(type1, name1, type2, name2, type3, name3, size) \ vector name1(size); \ vector name2(size); \ vector name3(size); \ rep(i, size) cin >> name1[i] >> name2[i] >> name3[i]; #define VVEC(type, name, h, w) \ vector> name(h, vector(w)); \ for(auto &row: name){ \ for(auto &in: row){ \ cin >> in; \ } \ } /* print */ // __init128 std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } __int128 parse(string &s) { __int128 ret = 0; for (ll i = 0; i < (ll)s.size(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } void print() { cout << endl; } template void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward(tail)...); } template void print(vector &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; } template void print(vector> &df) { for (auto& vec : df) { print(vec); } } /* lambda */ template struct lambda { private: F func; public: template constexpr lambda(G&& func) noexcept: func(std::forward(func)) {} template constexpr decltype(auto) operator ()(Args&&... args) const noexcept(std::is_nothrow_invocable_v) { return func(*this, forward(args)...); } }; template lambda(G&&) -> lambda>; /* debug */ #ifdef LOCAL # include # define debug(...) cerr << "\033[33m"; debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__); cerr << "\033[m"; #else # define debug(...) ; #endif // max 987654321 int main(){ LL(T); rep(_, T){ LL(M); string s = ""; rep(i, 9){ LL(c); rep(j, c){ s += lltoc(i + 1); } } debug(s) ll num = stoll(s) * 1e9; ll m = num % M; print(num + m); } }