QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 128 MB Total points: 100

#12294. Byteland Worldbeat Publishers

統計

Byteasar is a manager in Byteland Worldbeat Publishers (BWP). There are $n$ composers and $m$ lyricists employed there. The artists work in pairs consisting of one composer and one lyricist.

Byteasar knows the skills of BWP employees. Thus he can assess how effective a composer-lyricist pair is going to be. The efficiency of each potential pair is measured as the number of songs written per week.

Byteasar wants to arrange the employees in $\min(n, m)$ disjoint pairs such that the number of songs produced is as high as possible. Unpaired artists will not work.

After the analysis of the whole data Byteasar suspects that the total number of songs produced in BWP during a week is independent of the paring. Byteasar is surprised, therefore he asks you to write a program to verify this observation.

Input Format

The first line of input contains one integer $t$ ($1 ≤ t ≤ 10$), i.e., the number of test cases that follow.

Each test case starts with a line with three integers $n$, $m$ and $k$ ($1 ≤ n, m ≤ 100\,000$, $1 ≤ k ≤ 300\,000$) that are the number of composers, the number of lyricists and the number of lines describing the efficiency of pairs. Composers are numbered from 1 to n, while lyricists are numbered from $1$ to $m$.

Each of the next $k$ subsequent lines contains four integers $a_{i}$, $b_{i}$, $c_{i}$ and $p_{i}$ ($1 ≤ a_{i} ≤ n$, $1 ≤ b_{i} ≤ c_{i} ≤ m$, $1 ≤ p_{i} ≤ 10^{9}$) with the meaning that a pair of composer $a_{i}$ and any lyricist from the range $b_{i}$ to $c_{i}$ (inclusive) will produce $p_{i}$ songs per week.

Each composer-lyricist pair will be described at most once. If a pair is not mentioned in the input, its members will be assumed to be skilled in incompatible music genres, thus the efficiency of their work will be 0 songs a week. Nevertheless such a pair can be formed in BWP.

Output Format

Your program should output t lines with answers for subsequent test cases. For each test case the answer is TAK (i.e., yes in Polish) if for each arrangement of $\min(n, m)$ pairs, the total efficiency is the same. Otherwise, the answer is NIE (no in Polish).

Example

Input

2
2 3 3
1 1 3 3
2 1 1 3
2 2 3 3
3 3 7
1 1 1 5
1 2 2 6
2 1 1 5
2 2 2 6
3 1 1 8
3 2 2 9
3 3 3 10

Output

TAK
NIE
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.