#include #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int T; cin >> T; while(T--) { int M; cin >> M; vector c(10); long long X = 0; for(int i = 1; i < 10; i++) { cin >> c[i]; for(int j = 0; j < c[i]; j++) { X += i; X *= 10; } } X *= 100000000; X += M - X % M; cout << X << '\n'; } return 0; }