#include<bits/stdc++.h> usingnamespace std; using ll = longlong; constint N = 1e6 + 10, mod = 1e9 + 7;
ll T, m, a[10];
ll qpow(ll x, ll y){ ll ans = 1; while (y) { if (y & 1) { ans = (ans * x) % mod; } y = y >> 1; x = (x * x) % mod; } return ans; }
intmain(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> T; while (T--) { cin >> m; ll ans = 0; for (int i = 0; i <= 9; ++i) { cin >> a[i]; } if (m == 1and a[0] >= 1) { cout << 0 << '\n'; continue; } m--; for (int i = 1; i <= 9; ++i) { if (a[i] > 0) { a[i]--; ans += i * qpow(10, m) % mod; break; } } for (int i = 0; i <= 9; ++i) { if (a[i] > 0and m > 0) { ll cnt = min(m, a[i]); ans += (qpow(10, cnt) - 1) * qpow(9, mod - 2) * i % mod * qpow(10, m - cnt); ans %= mod; m -= cnt; } } cout << ans << '\n'; } return0; }