#include #include #include #include #include #include #include #include #include using namespace std; int T; int n,a; const int maxn = (1 << 20) - 1; int arr[25]; int cmp(int x,int y) { return y < x; } int getOnes(int x) { int nums = 0; while(x > 0) { if(x & 1) nums ++; x >>= 1; } return nums; } int fun(int x) { int tmp = a; int pos = 0; int ans = 0; while(x > 0 && pos < n) { if(x & 1) { tmp %= arr[pos]; ans ++; } x >>= 1; pos ++; } if(tmp == 0) return ans; else return -1; } int main() { //freopen("in.txt","r",stdin); scanf("%d",&T); while(T --) { scanf("%d%d",&n,&a); for(int i=0;i= mins) continue; int res = fun(i); if(res > 0 && res < mins ) { mins = res; } } if(mins != 0x3f3f3f3f) { printf("%d\n",mins); } else{ printf("-1\n"); } } //while(1); return 0; }