package main import ( "bufio" "container/heap" "fmt" "os" "strconv" ) type item struct { len int // value n int // weight } type priorityQueue []*item func (pq priorityQueue) Len() int { return len(pq) } func (pq priorityQueue) Less(i, j int) bool { return pq[i].n > pq[j].n } func (pq priorityQueue) Swap(i, j int) { pq[i], pq[j] = pq[j], pq[i] } func (pq *priorityQueue) Push(x interface{}) { item := x.(*item) *pq = append(*pq, item) } func (pq *priorityQueue) Pop() interface{} { old := *pq n := len(old) item := old[n-1] *pq = old[0 : n-1] return item } var sc = bufio.NewScanner(os.Stdin) func next() string { sc.Split(bufio.ScanWords) if !sc.Scan() { panic("could not scan a word from the reader") } return sc.Text() } func nextInt() int { i, e := strconv.Atoi(next()) if e != nil { panic(e) } return i } func nextLong() int64 { i, e := strconv.ParseInt(next(), 10, 64) if e != nil { panic(e) } return i } func nextLine() string { sc.Split(bufio.ScanLines) if !sc.Scan() { panic("could not scan a line from the reader") } return sc.Text() } func solve() { n := nextInt() a := make(map[int]int) for i := 0; i < n; i++ { x := nextInt() a[x]++ } pq := make(priorityQueue, 0, n) for i, v := range a { item := &item{ len: i, n: v, } pq = append(pq, item) } heap.Init(&pq) z := 0 for pq.Len() >= 3 { x := make([]*item, 3) for i := 0; i < 3; i++ { x[i] = heap.Pop(&pq).(*item) x[i].n-- } for i := 0; i < 3; i++ { if x[i].n > 0 { heap.Push(&pq, x[i]) } } z++ } fmt.Println(z) } func main() { t := nextInt() for i := 0; i < t; i++ { solve() } }