Bag of Bags

가방을 순서대로 처리하면서 i와 j가 같고 j와 k가 같은데 i와 k는 다른 세 가방이 생기는 경우에만 새 가방을 버린다.

어려움8정렬구간유니온 파인드아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

A mathematician goes to the shop every day and brings a bag from it. The bags are nice and practical, so mathematician wants to keep them for future usage. He also wants to keep his bags in order: big bags with big bags and small bags with small bags.

The bag brought on the ii-th day (we'll just call it bag ii) occupies volume a_ia\_i in folded state and volume b_ib\_i in unfolded state (naturally, a_i<b_ia\_i < b\_i). The bag ii fits into the bag jj if a_i<b_ja\_i < b\_j. Mathematician thinks that bags ii and jj are equal (and should be kept together) if the bag ii fits into the bag jj and vice versa.

Unfortunately, sometimes it happens that there are three bags i,j,ki, j, k such that bags ii and jj are equal, and bags jj and kk are equal, but bags ii and kk are not! It scares mathematician very much because it contradicts with what he knows about the equality relation. If adding a new bag to his collection gives rise to a contradictory triple as described above, he throws the new bag out instead, otherwise he keeps it (and never throws it away afterwards).

Your task is to determine for each bag whether it was kept or thrown away.

입력

The first line contains an integer nn --- the number of bags (1n31051 \le n \le 3 \cdot 10^5). 

The next nn lines describe the bags. The ii-th of these lines contains two integers a_ia\_i and b_ib\_i --- sizes of the bag ii in folded and unfolded states respectively (1a_i<b_i1091 \le a\_i < b\_i \le 10^9).

출력

Print nn lines. The ii-th line should contain the word "KEPT" if the mathematician keeps the bag ii, and "THROWN AWAY" otherwise.