Bzoj 1022: [shoi2008] John anti_nim game

Source: Internet
Author: User

1022: [shoi2008] John's game Time Limit: 1 secMemory limit: 162 MB
Submit: 1189Solved: 734
[Submit] [Status] Description

John often plays a very interesting game with his brother: There are n piles of stones on the table. John and his brother take turns to take stones, you can select a pile of stones at will, and take away any number of stones in the pile, but not one stone or not. We stipulate that the person who gets the last one will lose. John is very stubborn. He insisted that the first person has a great advantage, so he always takes the first stone, and his brother is more intelligent, he has never made any mistakes in the game. John asked you to be his adviser before getting angry. Naturally, you should first write a program to predict who will win the game.

Input

The input in this question is composed of multiple groups of data. The first row contains an integer T, indicating that the input has a total of T groups of data (T ≤ 500 ). The first row of each group of data contains an integer n (n ≤ 50), indicating a total of N stones. Next there are n integers not greater than 5000, the number of stones in each heap.

Output

The output of each group of data occupies one row, and each row outputs one word. If John can win the game, "John" is output; otherwise, "brother" is output. Note the case sensitivity of words. 2 3 3 5 1 1 1

Sample Input John
Brother


[Data scale]
For 40% of data, T ≤ 250.
For 100% of data, T ≤ 500.
Sample output hintsource

 

Anti_nim games: the first player wins only when

1) All sg XOR! = 0 and a SG> 1
2) All sg XOR = 0 and No SG> 1

Do not understand the proof. Make up later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.