Under construction

Still being built. Things may change

Trucks

Interview

Time limit1sMemory limit1024 MB

Summary
Given roads with travel times, answer each query by checking whether a driver can get from city a to city b when every road on the route fits within the rest limit p.
Level

Medium6 of 10

Topics
Minimum spanning tree, Union-find, Tree
Solved
No attempts yet

Statement

A worldwide logistics company is called Loners since all of its drivers ride alone. The managers must quickly and accurately tell their clients whether a driver can deliver goods safely from city aa to city bb.

The job demands responsibility and alertness. Drivers must rest at a hotel no less often than every pp hours. Every city has a hotel. Using the cities and the roads that connect them, write a program that answers the managers' queries.

Input

The first line contains three integers NN, MM, and UU, separated by spaces: the number of cities, the number of roads, and the number of manager queries. The cities are numbered from 11 to NN.

Each of the next MM lines contains three integers xx, yy, and tt. This means it takes tt time to drive from city xx to city yy. Roads are two-way, and the time is the same in both directions. The data always satisfies x<yx < y. Two cities have at most one direct road between them.

Each of the next UU lines contains three integers aa, bb, and pp. Here aa is the starting city, bb is the destination city, and pp is the maximum time the driver can drive without rest. The data always satisfies a<ba < b.

Output

For each query, print TAIP (Lithuanian for "yes") on its own line if the driver can safely deliver the goods from city aa to city bb. Otherwise, print NE (Lithuanian for "no").

Constraints

  • 1≤N,M,U≤2000001 \le N, M, U \le 200000
  • 1≤x,y,a,b≤N1 \le x, y, a, b \le N
  • 1≤t,p≤1091 \le t, p \le 10^9

Examples1

  1. Example 1

    Input
    5 3 3
    1 3 9
    2 4 2
    3 5 8
    1 5 6
    3 4 100
    2 4 3
    
    Expected output
    NE
    NE
    TAIP