Coloring Intervals
InterviewTime limit3sMemory limit512 MB
Given n closed intervals with distinct endpoints, find the minimum number of colors so that overlapping intervals get different colors.
Problem
For real numbers , the closed interval is the set of all real numbers between and , inclusive. For example, .
Bob has closed intervals . For every pair of distinct indices , all of the following hold.
- and are positive integers.
- , so is not empty.
- , and , so two different closed intervals never share an endpoint.
Bob wants to color each interval with a single color so that any two overlapping intervals get different colors. He wants to know how many colors that takes. In other words, find the smallest positive integer such that each interval can be labelled with one of and any two overlapping intervals always carry different labels. Two intervals overlap when their intersection is not empty.
Input
The first line contains the number of test cases. Each of the next lines describes one test case by giving , , , , , , , , in that order. Two consecutive numbers on a line are separated by one or more spaces.
You may assume the following.
- and are positive integers no larger than for every .
Output
For each test case, print the minimum number of colors on its own line. That is, print the smallest positive integer such that each of can be labelled with one of and any two overlapping intervals always carry different labels.