#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; ++i) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> t; while(t--){ ll x = 0, m; cin >> m; for(int i=1;i<=9;i++){ int d; cin >> d; while(d--) x = x*10 + i; } x *= 1000000000; x = (x+m-1)/m*m; cout << x << '\n'; } return 0; }