#include<stdio.h>
#include<stdlib.h>
int main(){
int t,q;
scanf("%d" , &t);
long long int n;
for(q=0;q<t;q++){
scanf("%lld" , &n);
int i;
for(i=0;i<7;i++){
n-=4*i;
if(n%7==0)
break;
}
if(n<0)printf("-1\n");
else
printf("%lld\n" , n);
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CmludCBtYWluKCl7CiAgICBpbnQgdCxxOwoJc2NhbmYoIiVkIiAsICZ0KTsKCWxvbmcgbG9uZyBpbnQgbjsKCWZvcihxPTA7cTx0O3ErKyl7CgkJc2NhbmYoIiVsbGQiICwgJm4pOwoJCWludCBpOwoJCWZvcihpPTA7aTw3O2krKyl7CgkJCW4tPTQqaTsKCQkJaWYobiU3PT0wKQoJCQkJYnJlYWs7CgkJfQoJCWlmKG48MClwcmludGYoIi0xXG4iKTsKCQllbHNlCgkJCXByaW50ZigiJWxsZFxuIiAsIG4pOwoJfQoJcmV0dXJuIDA7Cn0=