#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int T;
cin >> T;
int n;
string x;
int b[101];
int r[101];
for(int i=1;i<=T;i++){
cin >> n;
for(int j=1;j<=n;j++){
cin >> b[j];
}
cin >> x;
for(int j=1;j<=n;j++){
int temp=0;
for(int k=0;k<x.length();k++){
//1.重点:字符串转化为数字 x[k]-'0';
//2.重点: 大数据处理采取字符串,并且采用数论求模方法(A+B)%C=(A%C+B%C)%C;
//3.重点:for循环谨记:i=0,则i<n;i=1,则i<=n;n为长度
temp =(((temp*10)%b[j])+((x[k]-'0')%b[j]))%b[j];
}
r[j] = temp;
}
cout <<"("<<r[1];
for(int j=2;j<=n;j++){
cout <<","<<r[j];
}
cout << ")"<<endl;
}
//system("pause"); // 头文件#include <cstdlib>
return 0;
}