#include #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--){ ll m; cin >> m; vector d(9); rep(i,9) cin >> d[i]; ll a=0; ll c=16; rep(i,9){ rep(j,d[i]){ a += 1ll*(i+1)*(pow(1ll*10,c)); c--; } } a += m-a%m; cout << a << endl; cout << a%m << endl; } }