problems / 242

Alice's Lucky Die

easy brute-force arrays 1000 ms · 256 MB

Alice's Lucky Die

Alice and Bob carved their own dice. Alice's die has a faces and Bob's has b faces, and every face carries an integer. Faces may repeat numbers, so a die may well show 5 on three of its faces. They each roll their own die once, and whoever shows the higher number wins the round. Equal numbers are a tie.

Every face of a die is equally likely, so all a·b pairs (Alice's face, Bob's face) are equally likely. Count how many of these pairs give Alice a win, how many give Bob a win, and how many are ties. Then say who is favoured: ALICE if Alice wins in more pairs than Bob, BOB if Bob wins in more pairs than Alice, and FAIR if they win in the same number of pairs.

Two faces showing the same number are still different faces: each counts as its own pair.

Input

The first line contains t (1 ≤ t ≤ 100), the number of test cases.

Each test case consists of three lines:

  • a and b (1 ≤ a, b ≤ 100), the number of faces on Alice's and Bob's dice;
  • a integers x_1, …, x_a (1 ≤ x_i ≤ 10^9), the numbers on Alice's faces;
  • b integers y_1, …, y_b (1 ≤ y_j ≤ 10^9), the numbers on Bob's faces.

Output

For each test case print one line with three integers and a word: the number of pairs where Alice wins, the number where Bob wins, the number of ties, and then ALICE, BOB or FAIR.

Notes

In the first test case of the first example, Alice's die is 1 4 4 and Bob's is 3 3 5. Alice's face 1 loses to all three of Bob's faces. Each of her two 4 faces beats both 3 faces and loses to 5. So Alice wins 2·2 = 4 pairs, Bob wins 3 + 2 = 5 pairs, and there are no ties: Bob is favoured.

Comparing the totals or averages of the faces does not decide the game. In the second test case of the first example, Alice's faces add up to 1 + 1 + 1 + 10 = 13, more than Bob's 2 + 2 + 2 + 2 = 8, yet Bob wins 12 of the 16 pairs.

In the third test case, Alice's 6 beats Bob's 2 and 4 and ties with his 6, while her 2 ties with his 2 and loses to 6 and 4: two wins each and two ties, so the dice are FAIR.

Example 1

Input

3
3 3
1 4 4
3 3 5
4 4
1 1 1 10
2 2 2 2
2 3
6 2
2 6 4

Output

4 5 0 BOB
4 12 0 BOB
2 2 2 FAIR

Example 2

Input

2
1 1
7
7
1 3
5
1 2 9

Output

0 0 1 FAIR
2 1 0 ALICE

Hints · reveal one at a time if you're stuck

Hint 1

Look at the constraints. At most how many (Alice's face, Bob's face) pairs can one test case have?

Hint 2

At most 10 000 pairs is few enough to look at every one of them and see who wins it. Repeated numbers are still separate faces, so don't remove duplicates.

report an issue Prefer your own editor? sooks prep 242 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.