Under construction

Still being built. Things may change

LED Scheme

Interview

Time limit3sMemory limit1024 MB

Summary
Given LEDs as directed edges between controller outputs, decide for each LED whether it can be the only one lit, meaning no other path leads from its anode to its cathode.
Level

Medium5 of 10

Topics
Graph, BFS, DFS
Solved
No attempts yet

Problem

A light-emitting diode (LED) is an electronic component with two terminals, called the anode and the cathode. In the figure, A and K on the left are the anode and the cathode. When the anode has a higher voltage than the cathode (figure (a)), the LED lights up. When the cathode has a higher voltage than the anode (figure (b)), the LED stays off but is not damaged. The LED also stays off when the anode and the cathode have equal voltages (figures (c) and (d)).

Juku has a number of LEDs and a controller that drives them. The controller has NN outputs, numbered 1…N1 \ldots N. Each output can be set by a program to a higher or a lower voltage (1 and 0 in the figures), which controls whether the LEDs connected to the controller light up.

Juku wants to connect many LEDs to his controller so that each LED can be turned on separately from all the others, that is, so that a state exists in which only that LED is lit. For example, in the scheme on the left of the figure below, both LEDs can be turned on separately. In the scheme on the right, both LEDs always light up together.

Write a program that takes a description of Juku's scheme and determines which LEDs can be turned on separately from the others with this scheme.

Input

The first line contains the number of controller outputs NN (2≤N≤2502 \le N \le 250) and the number of LEDs MM (1≤M≤25 0001 \le M \le 25\,000). Each of the next MM lines contains two space-separated integers AiA_i and BiB_i (1≤Ai,Bi≤N1 \le A_i, B_i \le N, Ai≠BiA_i \ne B_i), meaning that the anode of the ii-th LED is connected to controller output AiA_i and its cathode to output BiB_i.

Output

For each LED, print one line. If the controller outputs can be set to voltages so that only the ii-th LED lights up, print JAH on the ii-th line. Otherwise print EI.

Examples2

  1. Example 1

    Input
    3 3
    1 2
    2 3
    1 3
    
    Expected output
    JAH
    JAH
    EI
    
  2. Example 2

    Input
    3 4
    1 2
    2 1
    2 3
    3 2
    
    Expected output
    JAH
    JAH
    JAH
    JAH