← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	c := [10][10]int{}
	c[1][2] = 1
	c[1][4] = 3
	c[1][6] = 15
	c[1][8] = 7
	c[2][2] = 0
	c[2][4] = 2
	c[2][6] = 14
	c[2][8] = 6
	c[3][2] = 9
	c[3][4] = 11
	c[3][6] = 3
	c[3][8] = 15
	c[4][2] = 18
	c[4][4] = 0
	c[4][6] = 12
	c[4][8] = 4
	c[6][2] = 6
	c[6][4] = 8
	c[6][6] = 0
	c[6][8] = 12
	c[7][2] = 5
	c[7][4] = 7
	c[7][6] = 19
	c[7][8] = 11
	c[8][2] = 14
	c[8][4] = 16
	c[8][6] = 8
	c[8][8] = 0
	c[9][2] = 3
	c[9][4] = 5
	c[9][6] = 17
	c[9][8] = 9
	dd := []int{2, 4, 6, 8}
	for _t := 0; _t < t; _t++ {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		hasCycling := false
		zeroVals := make(map[int64]bool)
		fiveVals := make(map[int64]bool)
		for i := 0; i < n; i++ {
			l := a[i] % 10
			if l < 0 {
				l += 10
			}
			if l == 0 {
				zeroVals[a[i]] = true
			} else if l == 5 {
				fiveVals[a[i]] = true
			} else {
				hasCycling = true
			}
		}
		ans := "NO"
		if hasCycling {
			if len(zeroVals) > 0 || len(fiveVals) > 0 {
				// NO
			} else {
				for _, d := range dd {
					ok := true
					var first int64 = -1
					for i := 0; i < n; i++ {
						l0 := a[i] % 10
						if l0 < 0 {
							l0 += 10
						}
						tmp := (a[i] + int64(c[int(l0)][d])) % 20
						if tmp < 0 {
							tmp += 20
						}
						if first == -1 {
							first = tmp
						} else if tmp != first {
							ok = false
							break
						}
					}
					if ok {
						ans = "YES"
						break
					}
				}
			}
		} else {
			if len(zeroVals) > 0 {
				if len(zeroVals) > 1 {
					// NO
				} else {
					var b int64
					for k := range zeroVals {
						b = k
					}
					target := b - 5
					if len(fiveVals) == 0 {
						ans = "YES"
					} else {
						if target < 0 {
							// NO
						} else {
							ok := true
							for f := range fiveVals {
								if f != target {
									ok = false
									break
								}
							}
							if ok {
								ans = "YES"
							}
						}
					}
				}
			} else {
				if len(fiveVals) <= 1 {
					ans = "YES"
				}
				// else NO
			}
		}
		fmt.Println(ans)
	}
}
```