Under construction

Still being built. Things may change

Quality of Life Index

Time limit1sMemory limit1024 MB

Summary
Given countries with three indicators and pairwise ranking requirements, decide whether non-negative weights exist that make every requirement hold strictly.
Level

Medium6 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

Consider the indices used to rank countries, such as the Human Development Index, the Democracy Index, the Freedom Index, and the Happiness Index.

These indices usually work as follows. For each country, kk statistical indicators X1,…,XkX_1, \ldots, X_k are collected, for example life expectancy, average years of schooling, and gross domestic product. Each indicator XiX_i is given a weight λi\lambda_i. The index value of a country is λ1X1+⋯+λkXk\lambda_1 X_1 + \cdots + \lambda_k X_k, and countries are ranked by this value.

Such indices are often criticized for arbitrary weights. The person who builds an index may choose weights that produce the ranking they want.

You are given NN countries, each with three indicators. You are also given MM requirements. Each requirement says that country AA must rank above country BB, meaning the value of country AA must be strictly greater than the value of country BB. Determine whether there exist non-negative real weights λ1,λ2,λ3\lambda_1, \lambda_2, \lambda_3 that satisfy all requirements.

Input

The first line contains the number of tests TT (1≤T≤100 0001 \le T \le 100\,000).

The first line of each test contains the number of countries NN (2≤N≤100 0002 \le N \le 100\,000) and the number of requirements MM (1≤M≤100 0001 \le M \le 100\,000).

Each of the next NN lines contains three integers X1X_1, X2X_2, and X3X_3 (0≤X1≤10 0000 \le X_1 \le 10\,000, 0≤X2≤10 0000 \le X_2 \le 10\,000, 0≤X3≤10 0000 \le X_3 \le 10\,000), the statistics of one country. Countries are numbered 11 to NN in the order they appear in the input.

Each of the next MM lines contains two distinct integers AA and BB (1≤A≤N1 \le A \le N, 1≤B≤N1 \le B \le N, A≠BA \ne B), meaning country AA must rank above country BB.

The sum of NN over all tests is at most 100 000100\,000. The sum of MM over all tests is also at most 100 000100\,000.

Output

For each test, print on its own line JAH if there exist weights that make the ranking satisfy all requirements, or EI if no such weights exist.

Examples1

  1. Example 1

    Input
    3
    4 3
    0 5 1
    0 4 2
    0 2 3
    0 8 1
    2 1
    3 2
    4 2
    3 2
    1 2 5
    5 1 1
    3 1 3
    3 1
    3 2
    4 4
    4 1 9
    7 0 2
    1 4 4
    3 4 8
    1 2
    1 3
    4 1
    2 3
    
    Expected output
    JAH
    EI
    JAH