read t while read n m; do ((m/=2)) if ((n/4 <= m)); then echo $((n/4*3)) else r=$((n-m*4)) echo $((m*3+r/10*6+(r%10>=6 ? 3 : 0))) fi done