Untitled

mail@pastecode.io avatar
unknown
python
3 years ago
1.3 kB
1
Indexable
Never
#!/bin/python3

import math
import os
import random
import re
import sys



from itertools import permutations as pr
#
# Complete the 'checkDivisibility' function below.
#
# The function is expected to return a STRING_ARRAY.
# The function accepts STRING_ARRAY arr as parameter.
#
def solve(n):
    p = list(pr(n, 3))
    for i in p:
        if (int(''.join(i)) % 8 == 0):
            return 1
    return 0

def checkDivisibility(arr):
    
    arr2 = []
    
    for n in arr : 
        if len(n) <= 2:
            n = list(n)
            if len(n) == 1 and int(''.join(n)) % 8 == 0:
                arr2.append("YES")
            elif len(n) == 2 and (int(''.join(n)) % 8 == 0 or int(''.join(reversed(n))) % 8 == 0):
                arr2.append("YES")
            else:
                arr2.append("NO")
            continue
            
        if solve(n):
            arr2.append("YES")
        else:
            arr2.append("NO")
    
    return arr2
    
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    arr_count = int(input().strip())

    arr = []

    for _ in range(arr_count):
        arr_item = input()
        arr.append(arr_item)

    result = checkDivisibility(arr)

    fptr.write('\n'.join(result))
    fptr.write('\n')

    fptr.close()