| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 
 | #include <bits/stdc++.h>using i64 = long long;
 #define int i64
 #define pb push_back
 #define ep emplace
 #define eb emplace_back
 using std::max, std::min, std::swap;
 using std::cin, std::cout, std::string, std::vector;
 int read(int x = 0, int f = 0, char ch = getchar()) {
 while (ch < 48 or 57 < ch) f = ch == 45, ch = getchar();
 while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar();
 return f ? -x : x;
 }
 
 template <class T>
 constexpr T power(T a, i64 b) { T res {1}; for (; b; b /= 2, a *= a) if (b % 2) res *= a; return res; }
 constexpr i64 mul(i64 a, i64 b, i64 p) { i64 res = a * b - (i64)(1.L * a * b / p) * p; res %= p; if (res < 0) res += p; return res; }
 template <i64 P>
 struct MInt {
 i64 x;
 constexpr MInt() : x {0} {}
 constexpr MInt(i64 x) : x {norm(x % getMod())} {}
 static i64 Mod;
 constexpr static i64 getMod() { return P > 0 ? P : Mod; }
 constexpr static void setMod(i64 Mod_) { Mod = Mod_; }
 constexpr i64 norm(i64 x) const { if (x < 0) x += getMod(); if (x >= getMod()) x -= getMod(); return x; }
 constexpr i64 val() const { return x; }
 constexpr MInt operator-() const { MInt res; res.x = norm(getMod() - x); return res; }
 constexpr MInt inv() const { return power(*this, getMod() - 2); }
 constexpr MInt &operator*=(MInt rhs) & { if (getMod() < (1ULL << 31)) x = x * rhs.x % int(getMod()); else x = mul(x, rhs.x, getMod()); return *this; }
 constexpr MInt &operator+=(MInt rhs) & { x = norm(x + rhs.x); return *this; }
 constexpr MInt &operator-=(MInt rhs) & { x = norm(x - rhs.x); return *this; }
 constexpr MInt &operator/=(MInt rhs) & { return *this *= rhs.inv(); }
 friend constexpr MInt operator*(MInt lhs, MInt rhs) { MInt res = lhs; res *= rhs; return res; }
 friend constexpr MInt operator+(MInt lhs, MInt rhs) { MInt res = lhs; res += rhs; return res; }
 friend constexpr MInt operator-(MInt lhs, MInt rhs) { MInt res = lhs; res -= rhs; return res; }
 friend constexpr MInt operator/(MInt lhs, MInt rhs) { MInt res = lhs; res /= rhs; return res; }
 friend constexpr std::istream &operator>>(std::istream &is, MInt &a) { i64 v; is >> v; a = MInt(v); return is; }
 friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) { return os << a.val(); }
 friend constexpr bool operator==(MInt lhs, MInt rhs) { return lhs.val() == rhs.val(); }
 friend constexpr bool operator!=(MInt lhs, MInt rhs) { return lhs.val() != rhs.val(); }
 friend constexpr bool operator<(MInt lhs, MInt rhs) { return lhs.val() < rhs.val(); }
 };
 template <>
 i64 MInt<0>::Mod = 1e9 + 7;
 constexpr int P = 1e9 + 7;
 using Z = MInt<P>;
 
 const Z inv9 = Z(9).inv();
 
 void solve() {
 int m = read();
 int a[10];
 for (int i = 0; i < 10; i++) a[i] = read();
 
 if (m == 1 and a[0] > 0) { puts("0"); return; }
 
 Z ans = 0;
 for (int i = 1; i < 10; i++) {
 if (a[i] > 0) {
 ans += Z(i) * power(Z(10), m - 1);
 a[i]--, m--;
 break;
 }
 }
 
 for (int i = 0; i < 10; i++) {
 int t = min(a[i], m);
 ans += Z(i) * power(Z(10), m - t) * (power(Z(10), t) - 1) * inv9;
 
 m -= t;
 }
 
 cout << ans << '\n';
 }
 
 
 signed main() {
 for (int T = read(); T--; solve());
 
 return 0;
 }
 
 |