Chef owns an icecream shop in Chefland named scoORZ. There are only three types of coins in Chefland: Rs. 5, Rs. 10 and Rs. 15. An icecream costs Rs. 5.
There are $N$ people (numbered $1$ through $N$) standing in a queue to buy icecream from scoORZ. Each person wants to buy exactly one icecream. For each valid $i$, the $i$-th person has one coin with value $a_i$. It is only possible for someone to buy an icecream when Chef can give them back their change exactly ― for example, if someone pays with a Rs. 10 coin, Chef needs to have a Rs. 5 coin that he gives to this person as change.
Initially, Chef has no money. He wants to know if he can sell icecream to everyone in the queue, in the given order. Since he is busy eating his own icecream, can you tell him if he can serve all these people?

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $a_1, a_2, \ldots, a_N$.

-----Output-----
For each test case, print a single line containing the string "YES" if all people can be served or "NO" otherwise (without quotes).

-----Constraints-----
- $1 \le T \le 100$
- $1 \le N \le 10^3$
- $a_i \in \{5, 10, 15\}$ for each valid $i$

-----Subtasks-----
Subtask #1 (40 points): $a_i \in \{5, 10\}$ for each valid $i$
Subtask #2 (60 points): original constraints

-----Example Input-----
3
2
5 10
2
10 5
2
5 15

-----Example Output-----
YES
NO
NO

-----Explanation-----
Example case 1: The first person pays with a Rs. 5 coin. The second person pays with a Rs. 10 coin and Chef gives them back the Rs. 5 coin (which he got from the first person) as change.
Example case 2: The first person already cannot buy an icecream because Chef cannot give them back Rs. 5.
Example case 3: The first person pays with a Rs. 5 coin. The second person cannot buy the icecream because Chef has only one Rs. 5 coin, but he needs to give a total of Rs. 10 back as change.

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
for _ in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    f=0
    t=0
    p=1
    for i in lst:
        if(i==5):
            f+=1
        elif(i==10):
            if(f>0):
                f-=1
                t+=1
            else:
                p=0
                break
        else:
            if(t>0):
                t-=1
            else:
                if(f>1):
                    f-=2
                else:
                    p=0
                    break
    if(p==1):
        print("YES")
    else:
        print("NO")

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    counter = [0, 0, 0]
    flag = False

    for i in arr:
        if i == 5:  counter[0] += 1
        elif i == 10:
            counter[1] += 1
            counter[0] -= 1
        else:
            counter[2] += 1
            if counter[1] > 0:  counter[1] -= 1
            else:
                counter[0] -= 2

        if counter[0] < 0 or counter[1] < 0:    flag = True

    print("NO") if flag else print("YES")

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    total = 0

    for i in arr:
        if i == 5:  total += i
        else:
            if total == 0:
                print("NO")
                break
            else:
                to_return = i - 5
                if total < to_return:
                    print("NO")
                    break

                total += (5 - to_return)
    else:
        print("YES")

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    total = 0

    for i in arr:
        if i == 5:  total += i
        else:
            if total == 0:
                print("NO")
                break
            else:
                to_return = i - 5
                if total < to_return:
                    print("NO")
                    break
                else:
                    total += (5 - to_return)
    else:
        print("YES")

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    total = 0

    for i in arr:
        if i == 5:  total += i
        else:
            if total == 0:
                print("NO")
                break
            else:
                to_return = i - 5
                if total < to_return:
                    print("NO")
                    break
                else:
                    total -= 5
    else:
        print("YES")

for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    sum5=0
    sum10=0
    f=1
    if a[0]!=5:
        f=0
    else:
        for i in range(n):
            if a[i]==5:
                sum5+=1
            elif a[i]==10:
                if sum5<1:
                    f=0
                else:
                    sum5-=1
                    sum10+=1
            elif a[i]==15:
                if sum5<2 and sum10<1:
                    f=0
                else:
                    if sum5<2 and sum10>=1:
                        sum10-=1
                    elif sum5>=2 and sum10<1:
                        sum5-=2
                    else:
                        sum10-=1
    if f==1:
        print("YES")
    else:
        print("NO")

for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    sum5=0
    sum10=0
    f=1
    if a[0]!=5:
        f=0
    else:
        for i in range(n):
            if a[i]==5:
                sum5+=1
            elif a[i]==10:
                if sum5<1:
                    f=0
                else:
                    sum5-=1
                    sum10+=1
            elif a[i]==15:
                if sum5<2 and sum10<1:
                    f=0
                else:
                    if sum5<2 and sum10>=1:
                        sum10-=1
                    elif sum5>=2 and sum10<1:
                        sum5-=2
                    else:
                        sum10-=1
    if f==1:
        print("YES")
    else:
        print("NO")

for _ in range(int(input())):
    n = int(input())
    nums = [int(j) for j in input().split()]
    yes, five, ten = 1, 0, 0
    for j in range(n):
        if nums[j] == 15:
            if ten > 0 and five > 0:
                ten -= 1
                five -= 1
            elif five > 1:
                five -= 2
            else:
                yes = 0
        elif nums[j] == 10:
            ten += 1
            if five > 0:
                five -= 1
            else:
                yes = 0
        else:
            five += 1
    if yes == 1:
        print("YES")
    else:
        print("NO")


for _ in range(int(input())):
    has=1
    get=[]
    tens=0
    flag=1
    N=int(input())
    a=list(map(int, input().split()))
    for i in range(N):
        get.append(a[i]-5)
        
    if a[0]!=5 or a[1]==15:
        flag=0
       

    else:
        for i in range(1,N):
            if get[i]==0:
                has=has+1
                
            elif get[i]==5:
                    
                   # if tens!=0:
#                        has=has-10
#                        tens=tens-1
                if has>=1:
                    has=has-1
                else:
                    flag=0
                    break
                tens=tens+1
            else:
                if tens!=0:
                    tens=tens-1
                elif has>=2:
                    has=has-2
                        
                else:
                    flag=0
                    break

    if flag==0:
        print("NO")
        
    else:
        print("YES")
    

                        
   
        
        
        
    

# cook your dish here
for _ in range(int(input().strip())):
    N = int(input().strip())
    A = list(map(int, input().strip().split(" ")))
    coins = [0, 0]
    f = 1
    for i in A:
        if i == 5:
            coins[0] += 1
        elif i == 10 and coins[0] > 0:
            coins[0] -= 1
            coins[1] += 1
        elif i == 15:
            if coins[1] > 0:
                coins[1] -= 1
            elif coins[0] > 1:
                coins[0] -= 2
            else:
                f = 0
                print("NO")
                break
        else:
            f = 0
            print("NO")
            break
    if f:
        print("YES")

for _ in range(int(input().strip())):
    N = int(input().strip())
    A = list(map(int, input().strip().split(" ")))
    coins = [0, 0]
    f = 1
    for i in A:
        if i == 5:
            coins[0] += 1
        elif i == 10 and coins[0] > 0:
            coins[0] -= 1
            coins[1] += 1
        elif i == 15:
            if coins[1] > 0:
                coins[1] -= 1
            elif coins[0] > 1:
                coins[0] -= 2
            else:
                f = 0
                print("NO")
                break
        else:
            f = 0
            print("NO")
            break
    if f:
        print("YES")

for _ in range(int(input().strip())):
    N = int(input().strip())
    A = list(map(int, input().strip().split(" ")))
    coins = [0, 0, 0]
    f = 1
    for i in A:
        if i == 5:
            coins[0] += 1
        elif i == 10 and coins[0] > 0:
            coins[0] -= 1
        elif i == 15:
            if coins[1] > 0:
                coins[1] -= 1
            elif coins[0] > 1:
                coins[0] -= 2
            else:
                f = 0
                print("NO")
                break
        else:
            f = 0
            print("NO")
            break
    if f:
        print("YES")

for _ in range(int(input().strip())):
    N = int(input().strip())
    A = list(map(int, input().strip().split(" ")))
    coins = [0, 0, 0]
    f = 1
    for i in A:
        #print(i, coins)
        if i == 5:
            coins[0] += 1
        elif i == 10 and coins[0] > 0:
            coins[0] -= 1
        elif i == 15:
            if coins[1] > 1:
                coins[1] -= 1
            elif coins[0] > 1:
                coins[0] -= 2
            else:
                f = 0
                print("NO")
                break
        else:
            f = 0
            print("NO")
            break
    if f:
        print("YES")

for _ in range(int(input().strip())):
    N = int(input().strip())
    A = list(map(int, input().strip().split(" ")))
    coins = [0, 0, 0]
    f = 1
    for i in A:
        #print(i, coins)
        if i == 5:
            coins[0] += 1
        elif i == 10 and coins[0] > 0:
            coins[0] -= 1
        elif i == 15:
            if coins[1] > 1:
                coins[1] -= 1
            elif coins[1] > 1:
                coins[1] -= 2
            else:
                f = 0
                print("NO")
                break
        else:
            f = 0
            print("NO")
            break
    if f:
        print("YES")

# cook your dish here
for _ in range(int(input())):
    N=int(input())
    inp_arr=tuple(int(i) for i in input().strip().split())
    chefCoins={
        5: 0,
        10: 0
    }
    printStr='YES'
    for i in inp_arr:
        if(i==5):
            chefCoins[5]+=1
        elif(i==10):
            chefCoins[10]+=1
            if(chefCoins[5]>0):
                chefCoins[5]-=1
            else:
                printStr='NO'
                break
        elif(i==15):
            if(chefCoins[10]>0):
                chefCoins[10]-=1
            elif(chefCoins[5]>1):
                chefCoins[5]-=2
            else:
                printStr='NO'
                break
            
    print(printStr)
            

T=int(input()) 
for _ in range(T):
    N=int(input())   
    A=list(map(int, input().split()))
    Fives=0
    Flag=True
    Tens=0
    for i in A:
        if i==5:
            Fives=Fives+1
        elif i==10:
            if Fives>0:
                Tens=Tens+1
                Fives=Fives-1
            else:
                Flag=False
        else:
            if Tens>0:
                Tens=Tens-1
            elif Fives>1:
                Fives=Fives-2
            else:
                Flag=False
                break
    if Flag==True:
        print('YES')
    else:
        print("NO")

# cook your dish here
# 3
# 2
# 5 10
# 2
# 10 5
# 2
# 5 15

for _ in range(int(input())):
    n = int(input())
    coins = list(map(int, input().split()))
    res = True
    fives = 0
    tens = 0
    for i in coins:
        if i == 5:
            fives += 1
        elif i == 10:
            if fives > 0:
                fives -= 1
                tens += 1
            else:
                res = False
                break
        else:
            if tens > 0:
                tens -= 1
            elif fives > 1:
                fives -= 2
            else:
                res = False
                break
    if res == True:
        print("YES")
    else:
        print("NO")



for _ in range(int(input())):
    n = int(input())
    coins = list(map(int, input().split()))
    
    rem = [0, 0, 0]
    flag = True
    for c in coins:
        change = c - 5
        tens = change//10
        change = change % 10
        fives = change//5
        
        if (rem[0] >= fives and rem[1] >= tens):
            rem[0] -= fives
            rem[1] -= tens
        elif (rem[0] >= (tens*2) + fives):
            rem[0] -= 2
        else:
            flag = False
            break
        rem[c//5-1] += 1 
    
    print("YES" if flag else "NO")

for _ in range(int(input())):
    n = int(input())
    coins = list(map(int, input().split()))
    
    rem = [0, 0, 0]
    flag = True
    for c in coins:
        change = c - 5
        tens = change//10
        change = change % 10
        fives = change//5
        
        if (rem[0] >= fives and rem[1] >= tens):
            rem[0] -= fives
            rem[1] -= tens
        elif (rem[0] >= (tens*2) + fives):
            rem[1] -= 2
        else:
            flag = False
            break
        rem[c//5-1] += 1 
    
    print("YES" if flag else "NO")

for _ in range(int(input())):
    n = int(input())
    coins = list(map(int, input().split()))
    
    rem = [0, 0, 0]
    flag = True
    for c in coins:
        change = c - 5
        tens = change//10
        change = change % 10
        fives = change//5
        
        if (rem[0] >= fives and rem[1] >= tens):
            rem[0] -= fives
            rem[1] -= tens
        elif (rem[0] >= (tens*2) + fives):
            rem[1] -= tens*2
        else:
            flag = False
            break
        rem[c//5 -1] += 1
    
    print("YES" if flag else "NO")

# MOD = 1000000007
for _ in range(int(input())):
    # n,k = map(int,input().split())
    n = int(input())
    coins = list(map(int,input().split()))
    cashier = {5:0, 10:0}
    boo = False
    for coin in coins :
        if coin == 5 :
            cashier[5] += 1
        elif coin == 10 :
            if cashier[5] > 0 :
                cashier[5] -= 1
                cashier[10] += 1
            else :
                boo = True
                break
        else :
            if cashier[10] > 0 :
                cashier[10] -= 1
            elif cashier[5] >= 2 :
                cashier[5] -= 2
            else :
                boo = True
                break
    if boo :
        print('NO')
    else :
        print('YES')


# n = int(input())

# while n > 0:

#     t = int(input())

#     total = 0

#     arr = list(map(int, input().split()))

#     for i in arr:

#         if i == 5:
#             total += 5
#         else:
#             total -= (i-5)
            
#             if total != 0:
#                 print("NO")
#                 break
#     else:
#         print("YES")
#     n-=1

n = int(input())

while n > 0:

    t = int(input())
    d = {5: 0, 10:0, 15:0}

    arr = list(map(int, input().split()))

    for temp in arr:

        if d[5] < 0:
            print("NO")
            break

        if temp == 5:
            d[temp] += 1

        elif temp == 10:
            if d[5] >= 1:
                d[10] += 1
                d[5] -= 1
            else:
                print("NO")
                break

        elif temp == 15:
            if d[10] >= 1:
                #d[15] += 1
                d[10] -= 1
            else:
                # print("NO")
                # break
                if d[5] >= 2:
                    d[5]-=2
                    d[15] += 1
                else:
                    print('NO')
                    break
        else:
            print("NO")
            break
    else:
        print("YES")
    n-=1

n = int(input())

while n > 0:

    t = int(input())

    total = 0

    arr = list(map(int, input().split()))

    for i in arr:

        if i == 5:
            total += 5
        else:
            total -= (i-5)
            
            if total < 0:
                print("NO")
                break
    else:
        print("YES")
    n-=1

n = int(input())

while n > 0:

    t = int(input())
    d = {5: 0, 10:0}

    arr = list(map(int, input().split()))

    for temp in arr:

        if d[5] < 0:
            print("NO")
            break

        if temp == 5:
            d[temp] += 1

        elif temp == 10:
            if d[5] >= 1:
                d[10] += 1
                d[5] -= 1
            else:
                print("NO")
                break

        elif temp == 15:
            if d[10] >= 1:
                #d[15] += 1
                d[10] -= 1
            else:
                print("NO")
                break
        else:
            print("NO")
            break
    else:
        print("YES")
    n-=1

import sys
def hasKey(dic,key):
    return key in dic.keys()

cases = int(sys.stdin.readline().rstrip())
for case in range(cases):
    
    N = int(sys.stdin.readline().rstrip())
    p = list(map(int,sys.stdin.readline().rstrip().split(" ")))
    change = 0
    error = False
    for pi in p:
        
        
        if(pi - 5 <=change):
            change = change - (pi - 5)
            change +=5
        else :
            error = True
            break
        
    if(error):
        print("NO")
    else :
        print("YES")