F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 119    Accepted Submission(s): 4


Problem Description
After played many kinds of nim games, Xay and Amr decided to play something different. As the judge, I wrote several valid pairs of numbers on the blackboard. For every pair (x, y), it is valid only if -y ¡Ü x ¡Ü y and the greatest common divisor of x and y is 1. The typical legal move is to alter just one of these pairs. If we change (x, y) to (a, b):
1. (a, b) should be a valid pair.
2. 1 ¡Ü b < y if y != 1
3. 1 ¡Ü b ¡Ü y, -b < a < b if y = 1.

Furthermore, such a replacement will be legal for Xay only if a*y - b*x < 0, legal for Amr only if a*y - b*x > 0.For example, Xay can change (2, 5) to (1,3), (1,4), (-1,2), (0,1), (-1,1), etc. And Amr can similarly change (2, 5) to (1, 2), (2, 3), (3, 4), (1, 1), etc.

They will play on these pairs alternately. The last one who be able to move is the winner .We have already knew that both Amr and Xay are very clever and they will play this game perfectly. Now, my dear programmers, can you predict that who will be the winner?
 

Input
The first line contains a single positive integer T. which is the number of test cases. Each test case starts with a line with a single positive integer n(1 ¡Ü n ¡Ü 100) and a string ¡°Xay¡± or ¡°Amr¡± means who moves first. Then n lines follows, each line contains a pair of integers x and y. (1 ¡Ü y ¡Ü 15 and ¨Cy ¡Ü x ¡Ü y)
 

Output
One line per test case, ¡°Xay¡± means Xay will win, ¡°Amr¡± otherwise.
 

Sample Input
3 1 Xay 0 1 2 Amr 1 1 -1 1 2 Xay 1 4 -1 2
 

Sample Output
Amr Xay Amr Hint If Xay choose the pair (x, y), he will change it to (a, b) which make a/b as large as possible.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-23 04:58:43, Gzip enabled