#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
const ull mod=17;
ull A[10009];
/*Euclidean GCD*/
ull gcd(ull a,ull b)
{
while( b != 0)
{
ull t = b;
b= a %t;
a = t;
}
return a;
}
ull lcm(ull a, ull b)
{
return (a/gcd(a,b))%mod*(b%mod);
}
ull lcms(int l ,ull * A)
{
int i;
ull result;
result = 1;
for (i = 0; i < l; i++)
result = lcm(result, A[i])%17;
return result;
}
int main()
{
int T;
cin>>T;
while(T--)/*Number of test cases*/
{
int N;
cin>>N;/*How many Numbers in Array*/
for(int i=0;i<N;++i)
{
cin>>A[i];//Input Array
}
cout<<lcms(N,A)%17<<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIHVuc2lnbmVkIGxvbmcgbG9uZyB1bGw7CmNvbnN0IHVsbCBtb2Q9MTc7CnVsbCBBWzEwMDA5XTsKLypFdWNsaWRlYW4gR0NEKi8KdWxsIGdjZCh1bGwgYSx1bGwgYikKewogICAgd2hpbGUoIGIgIT0gMCkKCXsKCQl1bGwgIHQgPSBiOwoJCWI9IGEgJXQ7CgkJYSA9IHQ7Cgl9CglyZXR1cm4gYTsKfQp1bGwgbGNtKHVsbCBhLCB1bGwgYikgCnsgCglyZXR1cm4gKGEvZ2NkKGEsYikpJW1vZCooYiVtb2QpOyAKfQp1bGwgbGNtcyhpbnQgIGwgLHVsbCAqIEEpCnsKCWludCAgICAgaTsKCXVsbCByZXN1bHQ7CglyZXN1bHQgPSAxOwoJZm9yIChpID0gMDsgaSA8IGw7IGkrKykgCgkJcmVzdWx0ID0gbGNtKHJlc3VsdCwgQVtpXSklMTc7CglyZXR1cm4gcmVzdWx0Owp9CmludCBtYWluKCkKewoJaW50IFQ7CgljaW4+PlQ7Cgl3aGlsZShULS0pLypOdW1iZXIgb2YgdGVzdCBjYXNlcyovCgl7CgkJaW50IE47CgkJY2luPj5OOy8qSG93IG1hbnkgTnVtYmVycyBpbiBBcnJheSovCgkJZm9yKGludCBpPTA7aTxOOysraSkKCQl7CgkJCWNpbj4+QVtpXTsvL0lucHV0IEFycmF5CgkJfQoJCWNvdXQ8PGxjbXMoTixBKSUxNzw8ZW5kbDsKCX0KCXJldHVybiAwOwp9