#include #include #include #include #include #include #include using namespace std; const int maxn=25; int n,a,b[maxn],ans; void gao(int x,int res,int c){ if(c>=ans)return; if(!res){ ans=c; return; } if(x>=n)return; gao(x+1,res,c); gao(x+1,res%b[x],c+1); } void dit(){ scanf("%d%d",&n,&a); for(int i=0;i()); ans=n+1; gao(0,a,0); if(ans>n)ans=-1; printf("%d\n",ans); } int main() { int t;scanf("%d",&t);while(t--)dit(); }